> How do I use an Object property (declared as TObject) to do this? Do I
> create my own class and put an integer field in it? Or use something like
> this example in Delphi help, which casts things to TObjects and then later
> casts them back to the appropriate type
>
> // 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));
> with ComboBox1 do
> ListView1.ViewStyle := TViewStyle(Items.Objects[ItemIndex]);
The idea here is using the same storage space as different symbol
table-types.
By casting all you're doing is informing the compiler that you know you're
not using
the right type by that you'd like it to treat the data stored as if it were
the right type.
the compiler will warn if data-types are the wrong size to be cast and
cannot be
converted to the right size automatically...
The above code assumes that pointer and integer are the same size... This is
currently
true but may not remain so... It's still the best option available... for
instance we regularly
do
with TQuery.Create(nil) do try
DatabaseName := AppDatabases[dbMain,true].DatabaseName;
SQL.Text := 'Select Name,ID from TheTable';
Open;
while not EOF do begin
SL.AddObject(Fields[0].AsString,TObject(Fields[1].AsInteger));
next;
end;
finally
Free;
end;
Setting the combo to the last Item selected is as simple as
Combo.ItemIndex := Combo.Items.IndexOfObject(Tobject(LastID));
--
Aaron@home
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz