### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Change Size with ComboBox [SOLVED]  (Read 551 times)

#### AlphaInc.

• Jr. Member
• Posts: 93
##### Change Size with ComboBox [SOLVED]
« on: April 21, 2021, 08:35:53 am »
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:
Code: Pascal  [Select][+][-]
1. Faktor:=1.6;
2. Width := round(Screen.Width/Faktor);
3. 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:
Code: Pascal  [Select][+][-]
1. ComboBox1.Caption:='Set Size';
2. ComboBox1.Items.Clear;

The Combobox has 5 different states which should each set a different value for "factor". Here is the code for my ComboBox):
Code: Pascal  [Select][+][-]
1. procedure TForm1.ComboBox1Change(Sender: TObject);
2. begin
3.   case ComboBox1.ItemIndex of
4.     0: factor:=1;
5.     1: factor:=1.6;
6.     2: factor:=2.4;
7.     3: factor:=4;
8.     4: Custom //I'll come to that later.
9.   end;
10. 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:
Code: Pascal  [Select][+][-]
1. procedure TForm1.confCheck();
2. var
3.    MyFile:Text;
4.    Line1,Line6:String;
5. begin
6.    AssignFile(MyFile,cMyFileName);
7.    Reset(MyFile);
10.
11.    sScreenSize:=Line6;
12.
13.    CloseFile(MyFile);
14.
15.    if Line1='init=1' then
16.       Button1.Enabled:=false
17.    else
18.       Button1.Enabled:=true;
19.
20.    if sScreenSize='size=XL' then
21.        Faktor:=1
22.        ComboBox1.ItemIndex:=0 //I thought this was the right but it's wrong.
23.    else if sScreenSize='size=L' then
24.       Faktor:=1.6
25.       ComboBox1.ItemIndex := 1
26.    else if sScreenSize='size=M' then
27.       Faktor:=2.4
28.       ComboBox1.ItemIndex:=2
29.    else if sScreenSize='size=S' then
30.       Faktor:=3.6;
31.       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:
Code: Pascal  [Select][+][-]
1. procedure TForm1.ComboBox1Change(Sender: TObject);
2. begin
3.   case ComboBox1.ItemIndex of
4.     0: factor:=1;
5.     1: factor:=1.6;
6.     2: factor:=2.4;
7.     3: factor:=4;
But beyond that I have no clue how to do so.
« Last Edit: April 24, 2021, 11:50:06 pm by AlphaInc. »

#### jamie

• Hero Member
• Posts: 4587
##### Re: Change Size with ComboBox
« Reply #1 on: April 21, 2021, 11:27:13 pm »
Doing more than a single statement following a statement of True or false  you need to enclose multiple statements to be executed only for that condition before a Begin ..... END  block

The only true wisdom is knowing you know nothing

#### AlphaInc.

• Jr. Member
• Posts: 93
##### Re: Change Size with ComboBox
« Reply #2 on: April 22, 2021, 09:31:09 am »
Doing more than a single statement following a statement of True or false  you need to enclose multiple statements to be executed only for that condition before a Begin ..... END  block

Sorry I don't understand. Could make an example?

#### jamie

• Hero Member
• Posts: 4587
##### Re: Change Size with ComboBox
« Reply #3 on: April 22, 2021, 11:25:54 pm »
Code: Pascal  [Select][+][-]
1. if Something = SomethingElse Then
2.   Begin
3.     // do something;
4.    //  and do some more now that only happens inside these block
5.    // continue doing more other stuff if this IF statement is true;
6.   End
7. else
8.  If Something = AManFromSpace Then
9.   …..
10.

in your code where you have problems you are trying to do more than a single statement following a IF operation. The Point I was making is if you have a desired to execute multiple instructions following the TRUE condition of a IF operation,  you need to place all the instructions inside a pair of BEGIN …. END etc..
The only true wisdom is knowing you know nothing