How to add items to TListBox or TComboBox
Posted: 16 Sep 2016 17:29
I created a combobox as shown (I tried with a listbox too):
Trying to add an item to the combobox using:
This gives me a "List index out of bounds (0)" error which leads me to believe that I have to declare the capacity of the list array somewhere but I can't figure out where. Does it have something to do with TStringList?
A working example would be much appreciated!
Code: Select all
TForm myForm = new TForm(nil);
myForm.Caption = "Form name";
myForm.BorderStyle = bsDialog;
myForm.Position = poScreenCenter;
TComboBox myComboBox = TComboBox.Create(myForm);
myComboBox.Parent = myForm;
myForm.ShowModal;
myForm.Free;
Code: Select all
myComboBox.Items[0] = "Hello world!";
A working example would be much appreciated!