[SOLVED] Set/Get ItemData() Equivalent in Delphi
-
hello guys.. I am new to Delphi. Some of you might have worked in C++. Is there anyway we could use these methods for associating 32-bit values, in Delphi. I also watched functions of TCustomCombo but could not find these methods. Thanks for any pointers.
This world is going to explode due to international politics, SOON.
-
hello guys.. I am new to Delphi. Some of you might have worked in C++. Is there anyway we could use these methods for associating 32-bit values, in Delphi. I also watched functions of TCustomCombo but could not find these methods. Thanks for any pointers.
This world is going to explode due to international politics, SOON.
Basically, you need to set/get Object into/from Items property of TComboBox instance. An example could be found at TComboBox.Items Property[^] To set:
// Add View styles and constants to the Combo Box
ComboBox1.Items.AddObject('vsIcon', TObject(vsIcon));
ComboBox1.Items.AddObject('vsList', TObject(vsList));
ComboBox1.Items.AddObject('vsReport', TObject(vsReport));
ComboBox1.Items.AddObject('vsSmallIcon', TObject(vsSmallIcon));
// Display first item in the Combo Box
ComboBox1.ItemIndex := 0;To get:
ListView1.ViewStyle := TViewStyle(Items.Objects[ItemIndex]);
TComboBox uses an instance of TCustomComboBoxStrings to maintain captions and their associated data, which has a function called PutObject.
function PutObject(Index: Integer; AObject: TObject); override;
This is the function that sends CB_SETITEMDATA message internally and where you could be able to set 32-bit value along with a given item index. On the other hand, GetObject
function GetObject(Index: Integer): TObject;
will retrieve the 32-bit value for you. Notice, in the world of Delphi, all these 32-bit values here are actually a TObject value.