Sign in Join
Wiki copytemporary

TTIComboBox: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11RTTI controls link to other components' published property, and changes in the either control are reflected to the other without any coding. TTIComboBox allows users to select any predefined item.
22
33As a simple example, let's create new form, and drop one TEdit (name=Edit1) and one TTIComboBox (name=TICombobox1) on the form. And then open TIComboBox1's Link property. Select Edit1 in the TIObject drop-down list, and Text in tht TIProperty dropdown list.
44
55As with TCombobox, TTIComboBox needs items to drop down. This is not provided in the object inspector. Users have to hard code them. It is necessary to define it before running. We'll put it in the OnCreate event of the form.
66
7-`procedure TForm1.FormCreate(Sender: TObject);`\
8-`begin`\
9-`   with TIComboBox1.Items do begin`\
10-`      Add('Sunday');`\
11-`      Add('Monday');`\
12-`      Add('Tuesday');`\
13-`      Add('Wednesday');`\
14-`      Add('Thursday');`\
15-`      Add('Friday');`\
16-`      Add('Saturday');`\
17-`   end;`\
18-`end;`
7+``` pascal
8+procedure TForm1.FormCreate(Sender: TObject);
9+begin
10+ with TIComboBox1.Items do begin
11+ Add('Sunday');
12+ Add('Monday');
13+ Add('Tuesday');
14+ Add('Wednesday');
15+ Add('Thursday');
16+ Add('Friday');
17+ Add('Saturday');
18+ end;
19+end;
20+```
1921
2022Now run the program, and change selection in the TIComboBox1. You will see that the text in the Edit1 changes as well. And if you type in any text in the Edit1, the text will be displayed in the TIComboBox1 as well.
2123
2224TTIComboBox can provide other value (alias values) that is different from displayed its text box. Now add to FromCreate event handler as follows.
2325
24-`procedure TForm1.FormCreate(Sender: TObject);`\
25-`begin`\
26-`   with TIComboBox1.Items do begin`\
27-`      Add('Sunday');`\
28-`      Add('Monday');`\
29-`      Add('Tuesday');`\
30-`      Add('Wednesday');`\
31-`      Add('Thursday');`\
32-`      Add('Friday');`\
33-`      Add('Saturday');`\
34-`   end;`\
35-`   with TIComboBox1.Link.AliasValues do begin`\
36-`      Add('0=Sunday');`\
37-`      Add('1=Monday');`\
38-`      Add('2=Tuesday');`\
39-`      Add('3=Wednesday');`\
40-`      Add('4=Thursday');`\
41-`      Add('5=Friday');`\
42-`      Add('6=Saturday');`\
43-`   end;`\
44-`end;`
26+``` pascal
27+procedure TForm1.FormCreate(Sender: TObject);
28+begin
29+ with TIComboBox1.Items do begin
30+ Add('Sunday');
31+ Add('Monday');
32+ Add('Tuesday');
33+ Add('Wednesday');
34+ Add('Thursday');
35+ Add('Friday');
36+ Add('Saturday');
37+ end;
38+ with TIComboBox1.Link.AliasValues do begin
39+ Add('0=Sunday');
40+ Add('1=Monday');
41+ Add('2=Tuesday');
42+ Add('3=Wednesday');
43+ Add('4=Thursday');
44+ Add('5=Friday');
45+ Add('6=Saturday');
46+ end;
47+end;
48+```
4549
4650And then run the program again. Now, you'll see Sunday, Monday, Tuesday, etc. in the TIComboBox1. But if Mondayh is selected, then Edit1 will show 1, instead of "Monday". The alias value of Monday, which is 1, is displayed. If you type in 3 in the Edit1, then TIComboBox1 will show Wednesday.
4751
4852---
4953*From the Free Pascal wiki, page "TTIComboBox", as it stood on 2022-09-01 after a change by Egsuh, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history