Thanks Aaron & Paul

I followed your code and it's working great.

Had a small hiccup on the way - was iterating through my query to build the
list and had all the code in the same loop. Basic effect was I'd added the
same object to all list items!! Separated the add as a procedure - all OK.

A whole new world of lists is now available!

Merry Xmas
Mike

----- Original Message -----
From: "Aaron Scott-Boddendijk" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Sunday, December 24, 2000 5:02 PM
Subject: Re: [DUG]: AddObject


> >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"
>

---------------------------------------------------------------------------
    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"

Reply via email to