选择后设置组合框标题

时间:2021-04-28 08:23:55

标签: combobox freepascal lazarus

我有一个在 FreePascal (Lazarus IDE) 中编写的小工具,并且有一个 ComboBox 可以根据 Ini-Entry 更改我的工具的大小。调整大小有效,但在用户选择 Combobox-Case 后,我在重置标题时遇到问题。我试图让 ComboBox 的标题始终设置,即使用户选择了一个案例。目前,在选择 ComboBox-Case 后,Box 只是空白(没有标题但您仍然可以选择一个案例)。我将 ItemIndex 设置为 -1,但没有成功。也许我正在监督某事。这是我的代码:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  Buttons, FileUtil, IniFiles;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    ComboBox1: TComboBox;

    procedure Button1Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure confCheck();

  private

  public

  end;

var
  Init, Language, Version, Enhancements, Mods, Size, Custom: String;
  BackgroundList: TStrings;
  MusicList: TStrings;
  LogoList: TStrings;
  Form1: TForm1;
  Faktor: extended;
  Config: TIniFile;

implementation

{$R *.lfm}

{ TForm1 }

const
   IniFile = 'conf.ini';

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  case ComboBox1.ItemIndex of
    0: begin
          Config := TIniFile.Create(IniFile);
          try
             Config.WriteString('Size', 'Size', 'XL');
          finally
            Config.free;
          end;
    end;
    1: begin
          Config := TIniFile.Create(IniFile);
          try
             Config.WriteString('Size', 'Size', 'L');
          finally
            Config.free;
          end;
    end;
    2: begin
          Config := TIniFile.Create(IniFile);
          try
             Config.WriteString('Size', 'Size', 'M');
          finally
            Config.free;
          end;
    end;
    3: begin
          Config := TIniFile.Create(IniFile);
          try
             Config.WriteString('Size', 'Size', 'S');
          finally
            Config.free;
          end;
      end;
   end;
   confCheck;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Close();
end;

procedure TForm1.confCheck();
begin
   Config := TIniFile.Create(IniFile);
   try
      Language     :=Config.ReadString('Language', 'Language', '');
      Size         :=Config.ReadString('Size', 'Size', '');

      //Setting of Tool-Size
      if Size='XL' then
         begin
            Faktor:=1;
         end
      else if Size='L' then
         Faktor:=1.6
      else if Size='M' then
         Faktor:=2.4
      else if Size='S' then
         Faktor:=3.6;

      //Dynamic Tool-Size
      Width:=round(Screen.Width/Faktor);
      Height:=round(Screen.Height/Faktor);

      //Positioning of Tool-Size
      Form1.position := poScreenCenter;
      Form1.BorderStyle := bsNone;

      //Setting of Captions
      if Language='German' then
         begin
            ComboBox1.Text:='Größe wählen';
            ComboBox1.Items.Clear;
            ComboBox1.Items.Add('Vollbildschirm');
            ComboBox1.Items.Add('Größe L');
            ComboBox1.Items.Add('Größe M');
            ComboBox1.Items.Add('Größe S');
         end
      else if Language='English' then
         begin
            ComboBox1.Text:='Choose Size';
            ComboBox1.Items.Clear;
            ComboBox1.Items.Add('Fullscreen');
            ComboBox1.Items.Add('Size L');
            ComboBox1.Items.Add('Size M');
            ComboBox1.Items.Add('Size S');
         end;
      ComboBox1.ItemIndex:=-1;
   finally
      Config.free;
   end;
end;

end.

0 个答案:

没有答案
相关问题