I dont have Delphi in front of me but here goes:


Type //where the objects etc are declared in your unit
        tRossesObject = Class(TObject)
                FieldOne : Integer;
                FieldTwo : String
                ...
        end;

So you now have the template for an object.

Now, in the loop you populate your Listbox, or each time you add an item you
want to:

Var 
myObject : TRossObject;

Begin
myObject := TRossesObject.Create;
myObject.FieldOne := 1;
myObject.FieldTwo := 'Two';
        
With ListBox1 do 
        AddObject('Somestring to display', myObject);
        myObject.Free; //the list owns a reference to it now

end;

The flip side is retrieving the object which can be accessed (wish I had the
IDE now) through the ListBoxes Objects collection (ie something like):

myObject := Listbox1.Objects[ListBox1.Listindex];
TextBox1.text = InttoStr(myObject.field1);

Please excuse the liberal and no doubt offensive to some VB 'ness of some of
the above. Hopefully enough to get you going though.

Call me in the weekend if you want a hand.
-----Original Message-----
From: Ross Levis [mailto:[EMAIL PROTECTED]]
Sent: 6 July 2001 16:30
To: Multiple recipients of list delphi
Subject: Re: Listbox items (Was: Re: [DUG]: array of TStringList)


The Delphi book I have doesn't explain this item object linking very well at
all.  I
presume I create an object as needed when a new item is added to the list.
How do I
do that considering I have to give each object a name?  A small example
would be
appreciated.

Thanks,
Ross.

NIRAV KAKU wrote:

> Objects property would be a good choice.
>
> regards,
> NIRAV KAKU
>
> On 6 Jul 01, at 12:22, Ross Levis wrote:
>
> > I have another newbie question.  What is the standard way of internally
storing
> > data attached to a listbox item.
> > ie. I have a listbox which has user defined items that can be added &
deleted.
> > For each of the items I need to display/store particular information.
> > eg. On the left I have a Listbox containing account numbers and on the
right I
> > have edit boxes containing Name, Address etc.
> >
> > Can I use the Items.Objects property to link each item to another object
in
> > this case?  Or do I simply store the Name/Address data in a string array
> > indexed on the ItemIndex.  That creates a problem when the user deletes
an item
> > >from the list -- I would have to move the data around in the array
which I
> > would rather not do.  Maybe I should use the item Tag property to store
the
> > index of the related array data.
> >
> > (BTW: The data will eventually be saved to a text file)
> >
> > Thanks,
> > Ross.
>
> - From the Shreemat Bhägwat Gïta -
> 'Sarcasm is the lowest form of wit.'
>
---------------------------------------------------------------------------
>     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"
---------------------------------------------------------------------------
    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