From Clomosy Docs
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection. Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.<br> | Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection. Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.<br> | ||
AddNewComboBox(TComponent,xName) : TClComboBox | AddNewComboBox(TComponent,xName) : TClComboBox | ||
| Line 7: | Line 8: | ||
<span style="color:blue"> xName</span> : The name of the defined combobox should be written. | <span style="color:blue"> xName</span> : The name of the defined combobox should be written. | ||
{| class="wikitable" style="border: 2px solid #c3d7e0" | |||
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"|Definition | |||
[ | |- | ||
|TClComboBox || testCombo : TClComboBox; || A variable belonging to the TClComboBox class is created. | |||
|- | |||
|AddNewComboBox ||testCombo := MyForm.AddNewComboBox(MyForm,'testCombo'); || A new ComboBox is added to the form. | |||
|- | |||
|AddItem || testCombo.AddItem('key1','value1'); ||In order to add data to the list in the Combobox, we need to use "AddItem". You must write the key value in the first parameter in the "AddItem" definition. This is the area you want to appear on the screen. You should write the value it will hold in the second parameter. | |||
|- | |||
|tbeOnChange || MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected'); || tbeOnChange is used as the event for clicking on the combobox. | |||
|- | |||
|ItemIndex || testCombo.ItemIndex || Specifies the index of the selected item. That is, it determines which element is selected. | |||
|- | |||
|GetValueIndex ||testCombo.GetValueIndex(testCombo.ItemIndex);||Returns the value of the selected string. In other words, it returns the value1 of the field defined by saying testCombo.AddItem('key1','value1'). | |||
|- | |||
|GetItemIndex ||testCombo.GetItemIndex(testCombo.ItemIndex) ||Returns the key of the selected string. In other words, it returns the key1 value of the field defined by saying testCombo.AddItem('key1','value1'). | |||
|- | |||
|Items ||testCombo.Items[testCombo.ItemIndex]; || This does the same thing as the GetItemIndex definition above. | |||
|- | |||
|Width ||testCombo.Width := 150; ||Allows the width of columns to be adjusted. | |||
|- | |||
|Height ||testCombo.Height := 50; ||llows the height of columns to be adjusted. | |||
|- | |||
|Align ||testCombo.Align := alTop; ||With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the page to learn about these features. | |||
|- | |||
|Margins || testCombo.Margins.Left:= 50; // Right, Top, Bottom || With the Margins parameter, you can give margins at any scale from the right, left, bottom, top. | |||
|} | |||
'''Example:'''<br> | '''Example:'''<br> | ||
Now let's make an example where we can show the value of the selected one in the message box when we select and select one of the days.<br> | Now let's make an example where we can show the value of the selected one in the message box when we select and select one of the days.<br> | ||
'' | |||
:''Basic Syntax''<br> | |||
'''var''' | '''var''' | ||
MyForm:TclForm; | MyForm:TclForm; | ||
| Line 66: | Line 48: | ||
'''procedure''' ComboSelected; | '''procedure''' ComboSelected; | ||
'''var''' | '''var''' | ||
strValue,strKey,strKey2 : String; | |||
'''begin''' | '''begin''' | ||
strValue := testCombo.GetValueIndex(testCombo.ItemIndex); | |||
ShowMessage( | strKey := testCombo.GetItemIndex(testCombo.ItemIndex); | ||
strKey2 := testCombo.Items[testCombo.ItemIndex]; | |||
ShowMessage('strValue : '+strValue); //value1 | |||
ShowMessage('strKey : '+strKey); //key | |||
ShowMessage('strKey2 : '+strKey2); //key | |||
ShowMessage('testCombo.ItemIndex : '+IntToStr(testCombo.ItemIndex)); //index | |||
'''end;'''<br> | '''end;'''<br> | ||
'''begin''' | '''begin''' | ||
| Line 89: | Line 77: | ||
testCombo.Margins.Left :=50; | testCombo.Margins.Left :=50; | ||
testCombo.Margins.Right :=50;<br> | testCombo.Margins.Right :=50;<br> | ||
testCombo.AddItem('Monday',' | testCombo.AddItem('Monday','01'); | ||
testCombo.AddItem('Tuesday',' | testCombo.AddItem('Tuesday','02'); | ||
testCombo.AddItem('Wednesday',' | testCombo.AddItem('Wednesday','03'); | ||
testCombo.AddItem('Thursday',' | testCombo.AddItem('Thursday','04'); | ||
testCombo.AddItem('Friday',' | testCombo.AddItem('Friday','05'); | ||
testCombo.AddItem('Saturday',' | testCombo.AddItem('Saturday','06'); | ||
testCombo.AddItem('Sunday',' | testCombo.AddItem('Sunday','07');<br> | ||
MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected'); | MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected'); | ||
MyForm.Run; | MyForm.Run; | ||
'''end;''' | '''end;''' | ||
:''TRObject Syntax'' | |||
var | |||
MyForm:TclForm; | |||
testCombo : TClComboBox; | |||
testLabel :TClLabel; | |||
void ComboSelected; | |||
var | |||
strValue,strKey,strKey2 : String; | |||
{ | |||
strValue = testCombo.GetValueIndex(testCombo.ItemIndex); | |||
strKey = testCombo.GetItemIndex(testCombo.ItemIndex); | |||
strKey2 = testCombo.Items[testCombo.ItemIndex]; | |||
ShowMessage('strValue : '+strValue); //value1 | |||
ShowMessage('strKey : '+strKey); //key | |||
ShowMessage('strKey2 : '+strKey2); //key | |||
ShowMessage('testCombo.ItemIndex : '+IntToStr(testCombo.ItemIndex)); //index | |||
} | |||
{ | |||
MyForm = TclForm.Create(Self); | |||
testLabel= MyForm.AddNewLabel(MyForm,'testLabel','Select the day'); | |||
testLabel.Align=alMostTop; | |||
testLabel.StyledSettings = ssFamily; | |||
testLabel.TextSettings.FontColor = clAlphaColor.clHexToColor('#820000'); | |||
testLabel.TextSettings.Font.Size=20; | |||
testLabel.Width = 150; | |||
testLabel.Height = 25; | |||
testLabel.Margins.Top=50; | |||
testLabel.Margins.Left =50; | |||
testLabel.Margins.Right =50; | |||
testCombo = MyForm.AddNewComboBox(MyForm,'testCombo'); | |||
testCombo.Align = alTop; | |||
testCombo.Width = 150; | |||
testCombo.Margins.Top=10; | |||
testCombo.Margins.Left =50; | |||
testCombo.Margins.Right =50; | |||
testCombo.AddItem('Monday','01'); | |||
testCombo.AddItem('Tuesday','02'); | |||
testCombo.AddItem('Wednesday','03'); | |||
testCombo.AddItem('Thursday','04'); | |||
testCombo.AddItem('Friday','05'); | |||
testCombo.AddItem('Saturday','06'); | |||
testCombo.AddItem('Sunday','07'); | |||
MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected'); | |||
MyForm.Run; | |||
} | |||
'''Output:'''<br> | '''Output:'''<br> | ||
Revision as of 13:43, 30 November 2023
Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection. Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.
AddNewComboBox(TComponent,xName) : TClComboBox
TComponent : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.
xName : The name of the defined combobox should be written.
| Feature | Use of | Definition |
|---|---|---|
| TClComboBox | testCombo : TClComboBox; | A variable belonging to the TClComboBox class is created. |
| AddNewComboBox | testCombo := MyForm.AddNewComboBox(MyForm,'testCombo'); | A new ComboBox is added to the form. |
| AddItem | testCombo.AddItem('key1','value1'); | In order to add data to the list in the Combobox, we need to use "AddItem". You must write the key value in the first parameter in the "AddItem" definition. This is the area you want to appear on the screen. You should write the value it will hold in the second parameter. |
| tbeOnChange | MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected'); | tbeOnChange is used as the event for clicking on the combobox. |
| ItemIndex | testCombo.ItemIndex | Specifies the index of the selected item. That is, it determines which element is selected. |
| GetValueIndex | testCombo.GetValueIndex(testCombo.ItemIndex); | Returns the value of the selected string. In other words, it returns the value1 of the field defined by saying testCombo.AddItem('key1','value1'). |
| GetItemIndex | testCombo.GetItemIndex(testCombo.ItemIndex) | Returns the key of the selected string. In other words, it returns the key1 value of the field defined by saying testCombo.AddItem('key1','value1'). |
| Items | testCombo.Items[testCombo.ItemIndex]; | This does the same thing as the GetItemIndex definition above. |
| Width | testCombo.Width := 150; | Allows the width of columns to be adjusted. |
| Height | testCombo.Height := 50; | llows the height of columns to be adjusted. |
| Align | testCombo.Align := alTop; | With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the page to learn about these features. |
| Margins | testCombo.Margins.Left:= 50; // Right, Top, Bottom | With the Margins parameter, you can give margins at any scale from the right, left, bottom, top. |
Example:
Now let's make an example where we can show the value of the selected one in the message box when we select and select one of the days.
- Basic Syntax
var MyForm:TclForm; testCombo : TClComboBox; testLabel :TClLabel;
procedure ComboSelected; var strValue,strKey,strKey2 : String; begin strValue := testCombo.GetValueIndex(testCombo.ItemIndex); strKey := testCombo.GetItemIndex(testCombo.ItemIndex); strKey2 := testCombo.Items[testCombo.ItemIndex]; ShowMessage('strValue : '+strValue); //value1 ShowMessage('strKey : '+strKey); //key ShowMessage('strKey2 : '+strKey2); //key ShowMessage('testCombo.ItemIndex : '+IntToStr(testCombo.ItemIndex)); //index end;
begin MyForm := TclForm.Create(Self);
testLabel:= MyForm.AddNewLabel(MyForm,'testLabel','Select the day'); testLabel.Align:=alMostTop; testLabel.StyledSettings := ssFamily; testLabel.TextSettings.FontColor := clAlphaColor.clHexToColor('#820000'); testLabel.TextSettings.Font.Size:=20; testLabel.Width := 150; testLabel.Height := 25; testLabel.Margins.Top:=50; testLabel.Margins.Left :=50; testLabel.Margins.Right :=50;
testCombo := MyForm.AddNewComboBox(MyForm,'testCombo'); testCombo.Align := alTop; testCombo.Width := 150; testCombo.Margins.Top:=10; testCombo.Margins.Left :=50; testCombo.Margins.Right :=50;
testCombo.AddItem('Monday','01'); testCombo.AddItem('Tuesday','02'); testCombo.AddItem('Wednesday','03'); testCombo.AddItem('Thursday','04'); testCombo.AddItem('Friday','05'); testCombo.AddItem('Saturday','06'); testCombo.AddItem('Sunday','07');
MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected'); MyForm.Run; end;
- TRObject Syntax
var
MyForm:TclForm;
testCombo : TClComboBox;
testLabel :TClLabel;
void ComboSelected;
var
strValue,strKey,strKey2 : String;
{
strValue = testCombo.GetValueIndex(testCombo.ItemIndex);
strKey = testCombo.GetItemIndex(testCombo.ItemIndex);
strKey2 = testCombo.Items[testCombo.ItemIndex];
ShowMessage('strValue : '+strValue); //value1
ShowMessage('strKey : '+strKey); //key
ShowMessage('strKey2 : '+strKey2); //key
ShowMessage('testCombo.ItemIndex : '+IntToStr(testCombo.ItemIndex)); //index
}
{
MyForm = TclForm.Create(Self);
testLabel= MyForm.AddNewLabel(MyForm,'testLabel','Select the day');
testLabel.Align=alMostTop;
testLabel.StyledSettings = ssFamily;
testLabel.TextSettings.FontColor = clAlphaColor.clHexToColor('#820000');
testLabel.TextSettings.Font.Size=20;
testLabel.Width = 150;
testLabel.Height = 25;
testLabel.Margins.Top=50;
testLabel.Margins.Left =50;
testLabel.Margins.Right =50;
testCombo = MyForm.AddNewComboBox(MyForm,'testCombo');
testCombo.Align = alTop;
testCombo.Width = 150;
testCombo.Margins.Top=10;
testCombo.Margins.Left =50;
testCombo.Margins.Right =50;
testCombo.AddItem('Monday','01');
testCombo.AddItem('Tuesday','02');
testCombo.AddItem('Wednesday','03');
testCombo.AddItem('Thursday','04');
testCombo.AddItem('Friday','05');
testCombo.AddItem('Saturday','06');
testCombo.AddItem('Sunday','07');
MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected');
MyForm.Run;
}