Hello everybody,
I want the window of a tool of mine be set according to my screen-size divided by a factor. This factor should be get from a .ini-file and be changed during run-time with a ComboBox which also writes the value of it to a ini-file. If you select custom a little popup-window should appear where you set the factor manually which will set the screen-size and save it in the ini.
I implemented a ComboBox which I want to use to set the size of my window. The size is definied in the FormCreate-Procedure as this:
Faktor:=1.6;
Width := round(Screen.Width/Faktor);
Height := round(Screen.Height/Faktor);
The ComboBox's Caption, if need to answer my question, is in the FormCreate-procedure as well (The descriptions will be updated later, they just placeholders at the moment:
ComboBox1.Caption:='Set Size';
ComboBox1.Items.Clear;
ComboBox1.Items.Add('Fullscreen');
ComboBox1.Items.Add('3840x2160p');
ComboBox1.Items.Add('2560x1440p');
ComboBox1.Items.Add('1920x1080p');
ComboBox1.Items.Add('Custom');
The Combobox has 5 different states which should each set a different value for "factor". Here is the code for my ComboBox):
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case ComboBox1.ItemIndex of
0: factor:=1;
1: factor:=1.6;
2: factor:=2.4;
3: factor:=4;
4: Custom //I'll come to that later.
end;
end;
I defiend factor as extended (a Double, since its a Floating point number) in the private-section of my source-code head. This brings me to my first question, how can I change the value of factor during run-time with my ComboBox? At the moment, when I set a Combo column - nothing happens.
Also, I have another procedure (confCheck) which checks a .ini-file for a String in Line 1 and either enables or disables a button. Now I want to expand this procedure in order for it to read the size too. The size is defined in line 6 and contains on of the following strings - XL, L, M, S or custom. Each size represents a different factor (as you can see in my if-else-condition below). My goal is to read the .ini during start-up of the tool, set the ComboBox Case as well as the factor and change the string in the ini when the size get's changed by the ComboBox. My code of the confCheck so far:
procedure TForm1.confCheck();
var
MyFile:Text;
Line1,Line6:String;
begin
AssignFile(MyFile,cMyFileName);
Reset(MyFile);
ReadLn(MyFile,Line1);
ReadLn(MyFile,Line6);
sScreenSize:=Line6;
CloseFile(MyFile);
if Line1='init=1' then
Button1.Enabled:=false
else
Button1.Enabled:=true;
if sScreenSize='size=XL' then
Faktor:=1
ComboBox1.ItemIndex:=0 //I thought this was the right but it's wrong.
else if sScreenSize='size=L' then
Faktor:=1.6
ComboBox1.ItemIndex := 1
else if sScreenSize='size=M' then
Faktor:=2.4
ComboBox1.ItemIndex:=2
else if sScreenSize='size=S' then
Faktor:=3.6;
ComboBox1.ItemIndex:=3
I'm struggeling with how to set the default value for the ComboBox and the factor itself. I tried to set the ItemIndex witho no succes. Maybe the answer to this is included in the first question? But I also don't know how to change the String in the .ini-file after I changed the Factor during runtime.
Last but not least, as commented in the ComboBox Code snippet, I want to be able to open a little popup-window when I set the ComboBox-value "custom" where I can manually set a factor which will be written to the .ini, read after a re-start of the tool and used to set the window-size. My code-idea so far:
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case ComboBox1.ItemIndex of
0: factor:=1;
1: factor:=1.6;
2: factor:=2.4;
3: factor:=4;
4: Custom:=PopupMenu1.PopUp;
But beyond that I have no clue how to do so.