Recent

Author Topic: ComboBox Size Changing Problem [SOLVED]  (Read 1980 times)

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
ComboBox Size Changing Problem [SOLVED]
« on: April 26, 2021, 02:55:40 pm »
Hello everybody,

I recently implemented a TiniFile to read specific entries of a config file used by the programm. Now I wanted to change the Size of my tool during runtime. The Sizing itself does work but there is one issue I can't get resolved - It should place the tool-window in the middle of my screen. I've set the code-line for that but when changing the size that doesn't work. After every start of the tool it is in the middle but not when you change it during runtime.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ComboBox1Change(Sender: TObject);
  2. begin
  3.   case ComboBox1.ItemIndex of
  4.     0: begin
  5.           Config := TIniFile.Create(IniFile);
  6.           try
  7.              Config.WriteString('Size', 'Size', 'XL');
  8.           finally
  9.             Config.free;
  10.           end;
  11.     end;
  12.     1: begin
  13.           Config := TIniFile.Create(IniFile);
  14.           try
  15.              Config.WriteString('Size', 'Size', 'L');
  16.           finally
  17.             Config.free;
  18.           end;
  19.     end;
  20.     2: begin
  21.           Config := TIniFile.Create(IniFile);
  22.           try
  23.              Config.WriteString('Size', 'Size', 'M');
  24.           finally
  25.             Config.free;
  26.           end;
  27.     end;
  28.     3: begin
  29.           Config := TIniFile.Create(IniFile);
  30.           try
  31.              Config.WriteString('Size', 'Size', 'S');
  32.           finally
  33.             Config.free;
  34.           end;
  35.     end;
  36.   end;
  37.   confCheck;
  38. end;
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.    //Resize-Component
  43.    Sizer := TFormResizer.Create(self);
  44.    Sizer.EnforceMinSize := false;
  45.    Sizer.ResizeFonts := true;
  46.    Font.Size:=20;
  47.    Sizer.InitializeForm;
  48.  
  49.    Config := TIniFile.Create(IniFile);
  50.    try
  51.       Language     :=Config.ReadString('Language', 'Language', '');
  52.          if Language = 'English' then
  53.             begin
  54.                ComboBox1.Caption:='Choose Size';
  55.                ComboBox1.Items.Clear;
  56.                ComboBox1.Items.Add('Fullscreen');
  57.                ComboBox1.Items.Add('Size L');
  58.                ComboBox1.Items.Add('Size M');
  59.                ComboBox1.Items.Add('Size S');
  60.             end
  61.          else if Language = 'German' then
  62.             begin
  63.                ComboBox1.Caption:='Größe wählen';
  64.                ComboBox1.Items.Clear;
  65.                ComboBox1.Items.Add('Vollbildschirm');
  66.                ComboBox1.Items.Add('Größe L');
  67.                ComboBox1.Items.Add('Größe M');
  68.                ComboBox1.Items.Add('Größe S');
  69.             end;
  70.       finally
  71.          Config.free;
  72.    end;
  73. end;  
  74.  
  75. procedure TForm1.confCheck();
  76. begin
  77.    Config := TIniFile.Create(IniFile);
  78.    try
  79.       Enhancements :=Config.ReadString('Enhancements', 'Enhancements', '');
  80.       Language     :=Config.ReadString('Language', 'Language', '');
  81.       Version      :=Config.ReadString('Version', 'Version', '');
  82.       Custom       :=Config.ReadString('Size', 'Custom', '');
  83.       Init         :=Config.ReadString('Init', 'Init', '');
  84.       Mods         :=Config.ReadString('Mods', 'Mods', '');
  85.       Size         :=Config.ReadString('Size', 'Size', '');
  86.  
  87.       //Setting of Initialization
  88.       if Init='true' then
  89.          Button3.Enabled:=false
  90.       else
  91.          Button3.Enabled:=true;
  92.  
  93.       //Setting of Tool-Size
  94.       if Size='XL' then
  95.          begin
  96.             Faktor:=1;
  97.          end
  98.       else if Size='L' then
  99.          Faktor:=1.6
  100.       else if Size='M' then
  101.          Faktor:=2.4
  102.       else if Size='S' then
  103.          Faktor:=3.6;
  104.  
  105.       //Dynamic Tool-Size
  106.       Width:=round(Screen.Width/Faktor);
  107.       Height:=round(Screen.Height/Faktor);
  108.  
  109.       //Positioning of Tool-Size
  110.       Form1.position := poScreenCenter;
  111.       Form1.BorderStyle := bsNone;
  112.  
  113.       //Setting of Button-Captions
  114.       if Language ='German' then
  115.          begin
  116.             Button1.Caption:='Starten';
  117.             Button2.Caption:='Eintellungen';
  118.             Button3.Caption:='Initialisieren';
  119.             Button4.Caption:='Beenden';
  120.             Button5.Caption:='Sprache ändern';
  121.             Button9.Caption:='Zurück';
  122.                if Version='Remastered' then
  123.                   begin
  124.                      Button6.Caption:='Original laden';
  125.                   end
  126.                else if Version='Original' then
  127.                   begin
  128.                      Button6.Caption:='Remastered laden';
  129.                   end;
  130.                if Enhancements='false' then
  131.                   begin
  132.                      Button7.Caption:='Enhancements aktivieren';
  133.                   end
  134.                else if Enhancements='true' then
  135.                   begin
  136.                      Button7.Caption:='Enhancements deaktivieren';
  137.                   end;
  138.                if Mods='false' then
  139.                   begin
  140.                      Button8.Caption:='Mods aktivieren';
  141.                   end
  142.                else if Mods='true' then
  143.                   begin
  144.                      Button8.Caption:='Mods deaktivieren';
  145.                   end;
  146.          end
  147.       else if Language='English' then
  148.          begin
  149.             Button1.Caption:='Start';
  150.             Button2.Caption:='Settings';
  151.             Button3.Caption:='Initialize';
  152.             Button4.Caption:='Close';
  153.             Button5.Caption:='Change Language';
  154.             Button9.Caption:='Back';
  155.                if Version='Remastered' then
  156.                   begin
  157.                      Button6.Caption:='Load Original';
  158.                   end
  159.                else if Version='Original' then
  160.                   begin
  161.                      Button6.Caption:='Load Remastered';
  162.                   end;
  163.                if Enhancements='false' then
  164.                   begin
  165.                      Button7.Caption:='Activate Enhancements';
  166.                   end
  167.                else if Enhancements='true' then
  168.                   begin
  169.                      Button7.Caption:='Deactivate Enhancements';
  170.                   end;
  171.                if Mods='false' then
  172.                   begin
  173.                      Button8.Caption:='Activate Mods';
  174.                   end
  175.                else if Mods='true' then
  176.                   begin
  177.                      Button8.Caption:='Deactivate Mods';
  178.                   end;
  179.          end;
  180.    finally
  181.       Config.free;
  182.    end;
  183. end;

Also, There is another thing which is defenetly not properly set but I can't see it - After I choose a size with my ComboBox I want the Caption to stay the same ('Größe wählen' or 'Choose Size', depending on the language). After every start of the tool the Description is set correctly but after choosing a Case the Description changes to the value i selecet and not the Description.
« Last Edit: April 27, 2021, 08:28:35 pm by AlphaInc. »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: ComboBox Size Changing Problem
« Reply #1 on: April 26, 2021, 03:19:26 pm »
I don't know about the first issue but for the second:

Also, There is another thing which is defenetly not properly set but I can't see it - After I choose a size with my ComboBox I want the Caption to stay the same ('Größe wählen' or 'Choose Size', depending on the language). After every start of the tool the Description is set correctly but after choosing a Case the Description changes to the value i selecet and not the Description.

That's as it should be; after all, the user would want to see what he has selected, wouldn't she? But if you want it otherwise you can set the box's Text property to whatever you want after doing whatever you need to do with the selected item, because (IIRC) changing Text will probably deselect it.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: ComboBox Size Changing Problem
« Reply #2 on: April 26, 2021, 03:32:45 pm »
I don't know about the first issue but for the second:

Also, There is another thing which is defenetly not properly set but I can't see it - After I choose a size with my ComboBox I want the Caption to stay the same ('Größe wählen' or 'Choose Size', depending on the language). After every start of the tool the Description is set correctly but after choosing a Case the Description changes to the value i selecet and not the Description.

That's as it should be; after all, the user would want to see what he has selected, wouldn't she? But if you want it otherwise you can set the box's Text property to whatever you want after doing whatever you need to do with the selected item, because (IIRC) changing Text will probably deselect it.

Okay, but when I change the ComboBox to this it doens't work:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ComboBox1Change(Sender: TObject);
  2. begin
  3.   case ComboBox1.ItemIndex of
  4.     0: begin
  5.           Config := TIniFile.Create(IniFile);
  6.           try
  7.              Config.WriteString('Size', 'Size', 'XL');
  8.           finally
  9.             Config.free;
  10.           end;
  11.     end;
  12.     1: begin
  13.           Config := TIniFile.Create(IniFile);
  14.           try
  15.              Config.WriteString('Size', 'Size', 'L');
  16.           finally
  17.             Config.free;
  18.           end;
  19.     end;
  20.     2: begin
  21.           Config := TIniFile.Create(IniFile);
  22.           try
  23.              Config.WriteString('Size', 'Size', 'M');
  24.           finally
  25.             Config.free;
  26.           end;
  27.     end;
  28.     3: begin
  29.           Config := TIniFile.Create(IniFile);
  30.           try
  31.              Config.WriteString('Size', 'Size', 'S');
  32.           finally
  33.             Config.free;
  34.           end;
  35.     end;
  36.   end;
  37.   confCheck;
  38.   ComboBox1.Caption:='Choose Size';
  39. end;

The Re-Sizing was done at this point but the ComboBox' Caption just goes blank.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: ComboBox Size Changing Problem
« Reply #3 on: April 26, 2021, 03:54:10 pm »
Try with:
Code: Pascal  [Select][+][-]
  1.   ComboBox1.Text := 'Choose Size';

Note that the result might depend on the Style of the box, whether auto-completion is on, etc.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: ComboBox Size Changing Problem
« Reply #4 on: April 26, 2021, 04:11:21 pm »
Try with:
Code: Pascal  [Select][+][-]
  1.   ComboBox1.Text := 'Choose Size';

Note that the result might depend on the Style of the box, whether auto-completion is on, etc.

Alright I did that in the confCheck-procedure but again it goes blank.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: ComboBox Size Changing Problem
« Reply #5 on: April 27, 2021, 09:56:53 am »
I am having a hard time determining what the real issue Is here ?

If you are trying to change the caption of the ComboBox then set the ItemIndex := -1 and then Get the caption to something you wish...
ComboxBox.Caption := 'xxxxxx';

and also, the OnSelectItem should be used when USER makes the changes and the OnChange gets fired always..

you may also want to do this
Combobox.Repaint;
after you changes are made.

Sorry, the issue I have is that after Setting a ComboBox-Case I want the Caption to appear instead of the selected case/ComboBox.Item... The Caption just goes blank.

I tried to use both ItemIndex:=-1 and ComboBox.Repaint with no success. I also made a new smaller and better structured tool to get rid of that issue with no success (the problem is still the same than in the first post of my topic):

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   Buttons, FileUtil, IniFiles;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     ComboBox1: TComboBox;
  18.  
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure ComboBox1Change(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure confCheck();
  23.  
  24.   private
  25.  
  26.   public
  27.   img : array [1..2] of TImage;
  28.  
  29.   end;
  30.  
  31. var
  32.   Init, Language, Version, Enhancements, Mods, Size, Custom: String;
  33.   BackgroundList: TStrings;
  34.   MusicList: TStrings;
  35.   LogoList: TStrings;
  36.   Form1: TForm1;
  37.   Faktor: extended;
  38.   Config: TIniFile;
  39.  
  40. implementation
  41.  
  42. {$R *.lfm}
  43.  
  44. { TForm1 }
  45.  
  46. const
  47.    IniFile = '..\Binaries\conf.ini';
  48.  
  49. procedure TForm1.FormCreate(Sender: TObject);
  50. begin
  51.  
  52. end;
  53.  
  54. procedure TForm1.ComboBox1Change(Sender: TObject);
  55. begin
  56.   case ComboBox1.ItemIndex of
  57.     0: begin
  58.           Config := TIniFile.Create(IniFile);
  59.           try
  60.              Config.WriteString('Size', 'Size', 'XL');
  61.           finally
  62.             Config.free;
  63.           end;
  64.     end;
  65.     1: begin
  66.           Config := TIniFile.Create(IniFile);
  67.           try
  68.              Config.WriteString('Size', 'Size', 'L');
  69.           finally
  70.             Config.free;
  71.           end;
  72.     end;
  73.     2: begin
  74.           Config := TIniFile.Create(IniFile);
  75.           try
  76.              Config.WriteString('Size', 'Size', 'M');
  77.           finally
  78.             Config.free;
  79.           end;
  80.     end;
  81.     3: begin
  82.           Config := TIniFile.Create(IniFile);
  83.           try
  84.              Config.WriteString('Size', 'Size', 'S');
  85.           finally
  86.             Config.free;
  87.           end;
  88.     end;
  89.   end;
  90.   confCheck;
  91. end;
  92.  
  93. procedure TForm1.Button1Click(Sender: TObject);
  94. begin
  95.   Close();
  96. end;
  97.  
  98. procedure TForm1.confCheck();
  99. begin
  100.    Config := TIniFile.Create(IniFile);
  101.    try
  102.       Enhancements :=Config.ReadString('Enhancements', 'Enhancements', '');
  103.       Language     :=Config.ReadString('Language', 'Language', '');
  104.       Version      :=Config.ReadString('Version', 'Version', '');
  105.       Custom       :=Config.ReadString('Size', 'Custom', '');
  106.       Init         :=Config.ReadString('Init', 'Init', '');
  107.       Mods         :=Config.ReadString('Mods', 'Mods', '');
  108.       Size         :=Config.ReadString('Size', 'Size', '');
  109.  
  110.       //Setting of Tool-Size
  111.       if Size='XL' then
  112.          begin
  113.             Faktor:=1;
  114.          end
  115.       else if Size='L' then
  116.          Faktor:=1.6
  117.       else if Size='M' then
  118.          Faktor:=2.4
  119.       else if Size='S' then
  120.          Faktor:=3.6;
  121.  
  122.       //Dynamic Tool-Size
  123.       Width:=round(Screen.Width/Faktor);
  124.       Height:=round(Screen.Height/Faktor);
  125.  
  126.       //Positioning of Tool-Size
  127.       Form1.position := poScreenCenter;
  128.       Form1.BorderStyle := bsNone;
  129.  
  130.       //Setting of Captions
  131.       if Language='German' then
  132.          begin
  133.             ComboBox1.Caption:='Größe wählen';
  134.             ComboBox1.Items.Clear;
  135.             ComboBox1.Items.Add('Vollbildschirm');
  136.             ComboBox1.Items.Add('Größe L');
  137.             ComboBox1.Items.Add('Größe M');
  138.             ComboBox1.Items.Add('Größe S');
  139.          end
  140.       else if Language='English' then
  141.          begin
  142.             ComboBox1.Caption:='Choose Size';
  143.             ComboBox1.Items.Clear;
  144.             ComboBox1.Items.Add('Fullscreen');
  145.             ComboBox1.Items.Add('Size L');
  146.             ComboBox1.Items.Add('Size M');
  147.             ComboBox1.Items.Add('Size S');
  148.          end;
  149.       ComboBox1.ItemIndex:=-1;
  150.    finally
  151.       Config.free;
  152.    end;
  153. end;
  154.  
  155. end.
« Last Edit: April 27, 2021, 09:59:22 am by AlphaInc. »

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: ComboBox Size Changing Problem
« Reply #6 on: April 27, 2021, 11:49:38 am »
Can you provide the whole source code in zip format, also conf.ini file an all the necessary files?

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: ComboBox Size Changing Problem
« Reply #7 on: April 27, 2021, 12:45:32 pm »
Can you provide the whole source code in zip format, also conf.ini file an all the necessary files?

Sure.

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: ComboBox Size Changing Problem
« Reply #8 on: April 27, 2021, 03:40:34 pm »
I have solved the center positioning issue. Not sure about the caption, it always show 'Größe wählen' on my test. I tested on Linux GTK2 without multiple monitors support.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   Buttons, FileUtil, IniFiles;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     ComboBox1: TComboBox;
  18.  
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure ComboBox1Change(Sender: TObject);
  21.     procedure confCheck();
  22.     procedure FormCreate(Sender: TObject);
  23.   private
  24.     procedure MakeFormCentre;
  25.   end;
  26.  
  27. var
  28.   Init, Language, Version, Enhancements, Mods, Size, Custom: String;
  29.   BackgroundList: TStrings;
  30.   MusicList: TStrings;
  31.   LogoList: TStrings;
  32.   Form1: TForm1;
  33.   Faktor: extended;
  34.   Config: TIniFile;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. const
  43.    IniFile = 'conf.ini';
  44.  
  45. procedure TForm1.ComboBox1Change(Sender: TObject);
  46. begin
  47.   case ComboBox1.ItemIndex of
  48.     0: begin
  49.           Config := TIniFile.Create(IniFile);
  50.           try
  51.              Config.WriteString('Size', 'Size', 'XL');
  52.              ComboBox1.ItemIndex:=-1;
  53.           finally
  54.             Config.free;
  55.           end;
  56.     end;
  57.     1: begin
  58.           Config := TIniFile.Create(IniFile);
  59.           try
  60.              Config.WriteString('Size', 'Size', 'L');
  61.           finally
  62.             Config.free;
  63.           end;
  64.     end;
  65.     2: begin
  66.           Config := TIniFile.Create(IniFile);
  67.           try
  68.              Config.WriteString('Size', 'Size', 'M');
  69.           finally
  70.             Config.free;
  71.           end;
  72.     end;
  73.     3: begin
  74.           Config := TIniFile.Create(IniFile);
  75.           try
  76.              Config.WriteString('Size', 'Size', 'S');
  77.           finally
  78.             Config.free;
  79.           end;
  80.       end;
  81.    end;
  82. confCheck();
  83. end;
  84.  
  85. procedure TForm1.Button1Click(Sender: TObject);
  86. begin
  87.   Close();
  88. end;
  89.  
  90. procedure TForm1.confCheck();
  91. begin
  92.    Config := TIniFile.Create(IniFile);
  93.    try
  94.       Enhancements :=Config.ReadString('Enhancements', 'Enhancements', '');
  95.       Language     :=Config.ReadString('Language', 'Language', '');
  96.       Version      :=Config.ReadString('Version', 'Version', '');
  97.       Custom       :=Config.ReadString('Size', 'Custom', '');
  98.       Init         :=Config.ReadString('Init', 'Init', '');
  99.       Mods         :=Config.ReadString('Mods', 'Mods', '');
  100.       Size         :=Config.ReadString('Size', 'Size', '');
  101.  
  102.       //Setting of Tool-Size
  103.       if Size='XL' then
  104.          begin
  105.             Faktor:=1;
  106.          end
  107.       else if Size='L' then
  108.          Faktor:=1.6
  109.       else if Size='M' then
  110.          Faktor:=2.4
  111.       else if Size='S' then
  112.          Faktor:=3.6;
  113.  
  114.       //Dynamic Tool-Size
  115.       Width:=round(Screen.Width/Faktor);
  116.       Height:=round(Screen.Height/Faktor);
  117.  
  118.       //Positioning of Tool-Size
  119. //      Form1.position := poScreenCenter;             // Removed by Handoko
  120. //      Form1.BorderStyle := bsNone;                  // Removed by Handoko
  121.       if not(Size = 'XL') then
  122.         MakeFormCentre;
  123.  
  124.       //Setting of Captions
  125.       if Language='German' then
  126.          begin
  127.             ComboBox1.Text:='Größe wählen';
  128.             ComboBox1.Items.Clear;
  129.             ComboBox1.Items.Add('Vollbildschirm');
  130.             ComboBox1.Items.Add('Größe L');
  131.             ComboBox1.Items.Add('Größe M');
  132.             ComboBox1.Items.Add('Größe S');
  133.             ComboBox1.ItemIndex:=-1;
  134.          end
  135.       else if Language='English' then
  136.          begin
  137.             ComboBox1.Text:='Choose Size';
  138.             ComboBox1.Items.Clear;
  139.             ComboBox1.Items.Add('Fullscreen');
  140.             ComboBox1.Items.Add('Size L');
  141.             ComboBox1.Items.Add('Size M');
  142.             ComboBox1.Items.Add('Size S');
  143.             ComboBox1.ItemIndex:=-1;
  144.          end;
  145.    finally
  146.       Config.free;
  147.    end;
  148. end;
  149.  
  150. procedure TForm1.FormCreate(Sender: TObject);
  151. begin
  152.   BorderStyle := bsNone;                  // Added by Handoko
  153. end;
  154.  
  155. procedure TForm1.MakeFormCentre;
  156. begin
  157.   Left := (Screen.Width - Width) div 2;
  158.   Top  := (Screen.Height - Height) div 2;
  159. end;
  160.  
  161. end.

I added a new function MakeFormCentre.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: ComboBox Size Changing Problem
« Reply #9 on: April 27, 2021, 08:28:26 pm »
I have solved the center positioning issue. Not sure about the caption, it always show 'Größe wählen' on my test. I tested on Linux GTK2 without multiple monitors support.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   Buttons, FileUtil, IniFiles;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     ComboBox1: TComboBox;
  18.  
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure ComboBox1Change(Sender: TObject);
  21.     procedure confCheck();
  22.     procedure FormCreate(Sender: TObject);
  23.   private
  24.     procedure MakeFormCentre;
  25.   end;
  26.  
  27. var
  28.   Init, Language, Version, Enhancements, Mods, Size, Custom: String;
  29.   BackgroundList: TStrings;
  30.   MusicList: TStrings;
  31.   LogoList: TStrings;
  32.   Form1: TForm1;
  33.   Faktor: extended;
  34.   Config: TIniFile;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. const
  43.    IniFile = 'conf.ini';
  44.  
  45. procedure TForm1.ComboBox1Change(Sender: TObject);
  46. begin
  47.   case ComboBox1.ItemIndex of
  48.     0: begin
  49.           Config := TIniFile.Create(IniFile);
  50.           try
  51.              Config.WriteString('Size', 'Size', 'XL');
  52.              ComboBox1.ItemIndex:=-1;
  53.           finally
  54.             Config.free;
  55.           end;
  56.     end;
  57.     1: begin
  58.           Config := TIniFile.Create(IniFile);
  59.           try
  60.              Config.WriteString('Size', 'Size', 'L');
  61.           finally
  62.             Config.free;
  63.           end;
  64.     end;
  65.     2: begin
  66.           Config := TIniFile.Create(IniFile);
  67.           try
  68.              Config.WriteString('Size', 'Size', 'M');
  69.           finally
  70.             Config.free;
  71.           end;
  72.     end;
  73.     3: begin
  74.           Config := TIniFile.Create(IniFile);
  75.           try
  76.              Config.WriteString('Size', 'Size', 'S');
  77.           finally
  78.             Config.free;
  79.           end;
  80.       end;
  81.    end;
  82. confCheck();
  83. end;
  84.  
  85. procedure TForm1.Button1Click(Sender: TObject);
  86. begin
  87.   Close();
  88. end;
  89.  
  90. procedure TForm1.confCheck();
  91. begin
  92.    Config := TIniFile.Create(IniFile);
  93.    try
  94.       Enhancements :=Config.ReadString('Enhancements', 'Enhancements', '');
  95.       Language     :=Config.ReadString('Language', 'Language', '');
  96.       Version      :=Config.ReadString('Version', 'Version', '');
  97.       Custom       :=Config.ReadString('Size', 'Custom', '');
  98.       Init         :=Config.ReadString('Init', 'Init', '');
  99.       Mods         :=Config.ReadString('Mods', 'Mods', '');
  100.       Size         :=Config.ReadString('Size', 'Size', '');
  101.  
  102.       //Setting of Tool-Size
  103.       if Size='XL' then
  104.          begin
  105.             Faktor:=1;
  106.          end
  107.       else if Size='L' then
  108.          Faktor:=1.6
  109.       else if Size='M' then
  110.          Faktor:=2.4
  111.       else if Size='S' then
  112.          Faktor:=3.6;
  113.  
  114.       //Dynamic Tool-Size
  115.       Width:=round(Screen.Width/Faktor);
  116.       Height:=round(Screen.Height/Faktor);
  117.  
  118.       //Positioning of Tool-Size
  119. //      Form1.position := poScreenCenter;             // Removed by Handoko
  120. //      Form1.BorderStyle := bsNone;                  // Removed by Handoko
  121.       if not(Size = 'XL') then
  122.         MakeFormCentre;
  123.  
  124.       //Setting of Captions
  125.       if Language='German' then
  126.          begin
  127.             ComboBox1.Text:='Größe wählen';
  128.             ComboBox1.Items.Clear;
  129.             ComboBox1.Items.Add('Vollbildschirm');
  130.             ComboBox1.Items.Add('Größe L');
  131.             ComboBox1.Items.Add('Größe M');
  132.             ComboBox1.Items.Add('Größe S');
  133.             ComboBox1.ItemIndex:=-1;
  134.          end
  135.       else if Language='English' then
  136.          begin
  137.             ComboBox1.Text:='Choose Size';
  138.             ComboBox1.Items.Clear;
  139.             ComboBox1.Items.Add('Fullscreen');
  140.             ComboBox1.Items.Add('Size L');
  141.             ComboBox1.Items.Add('Size M');
  142.             ComboBox1.Items.Add('Size S');
  143.             ComboBox1.ItemIndex:=-1;
  144.          end;
  145.    finally
  146.       Config.free;
  147.    end;
  148. end;
  149.  
  150. procedure TForm1.FormCreate(Sender: TObject);
  151. begin
  152.   BorderStyle := bsNone;                  // Added by Handoko
  153. end;
  154.  
  155. procedure TForm1.MakeFormCentre;
  156. begin
  157.   Left := (Screen.Width - Width) div 2;
  158.   Top  := (Screen.Height - Height) div 2;
  159. end;
  160.  
  161. end.

I added a new function MakeFormCentre.

That worked Thank you Handoko. I can't tell how many times you've helped me already  :D

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: ComboBox Size Changing Problem
« Reply #10 on: April 28, 2021, 01:53:47 am »
OnSelectItem should be used when USER makes the changes and the OnChange gets fired always..

I assume you mean OnSelect, but in any case these events are unclear to me. OnChange help says:

"This event covers only changes made by user. Not by code."

As far as I can tell, this is not true. It is fired when changed in code (as you say), resulting in an annoying call to the event when I set it in code. This follows a discussion in the Cocoa forum. If the OnSelect event only fires when the USER changes it, that is great and I can change all my OnChange to OnSelect.

I could use some official clarity...

“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: ComboBox Size Changing Problem [SOLVED]
« Reply #11 on: April 28, 2021, 04:44:15 am »
Thanks Jamie. I will have to get back to skalogryz. This sounds like a bug in Cocoa, I reported this as a bug, but was assured that OnChange was always fired when changing a ComboBox selection in code.

Made no sense to me.

No offense to skalogryz, a master coder who I support on Patreon.
« Last Edit: April 28, 2021, 05:30:37 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

 

TinyPortal © 2005-2018