>There was a thread on this a few weeks ago and I thought I'd give it a try in my
>spare (?) time.
> type
> TFooObject = class(TObject)
> id : integer;
> desc : string;
> role :string;
> end;
This definition is fine...
Procedure to add a new Object to the list
procedure TMyForm.AddFooClick(Sender :TObject);
var
FO :TFooObject;
begin
FO := TFooObject.create;
with FO do begin
Id := StrToIntDef(EdID.text,0);
Desc := EdDesc.text;
Role := EdRole.text;
end;
LBFoo.Items.AddObject(EdTitle.text,FO);
end;
> When the user clicks in the list box, I want to use the object details.
procedure TMyForm.LBFooClick(Sender: TObject);
var
FO :TFooObject;
begin
FO := TFooObject(LBFoo.Items.Objects[LBFoo.ItemIndex]);
LBLRole.Caption := FO.Role;
end;
1. You Don't 'Create' when retrieving an object reference from a list.
2. There is no 'typ' field in the TFooObject definition for TFooObject(XO).typ.Role to
work...
3. remember to free the objects when clearing the list or removing items from the list
NB: All untested code...
--
Aaron@home
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"