Board index » delphi » D2 ListBox 'ItemData' Property (like VB)

D2 ListBox 'ItemData' Property (like VB)

There doesn't seem to be an 'ItemData' property for Delphi's ListBox
component (like VB's, which exposes the 32bit value available via the
LB_SETITEMDATA and LB_GETITEMDATA messages).

There is, however, an array of TObjects associated with the ListBox, one
per item (which can only store objects, not simple integer values)

Does anyone know if the TObjects array uses the same 32bit storage area as
that area available via the LB_SET/GET messages? IOW, is it safe for me to
use the LB_SET/GET messages to store my own 32bit values related to each
listbox item without Delphi thinking that they are TObject pointers or
something?

Finally, is there a better way to duplicate VB's 'ItemData'  functionality
in D2?

Thanks In Advance,
Mike Cookson

 

Re:D2 ListBox 'ItemData' Property (like VB)


Quote
In article <01bbbbd2$63f5ccc0$572537a6@beta> "Mike Cookson" <mcook...@internetMCI.com> writes:
>From: "Mike Cookson" <mcook...@internetMCI.com>
>Subject: D2 ListBox 'ItemData' Property (like VB)
>Date: 17 Oct 1996 02:24:48 GMT
>There doesn't seem to be an 'ItemData' property for Delphi's ListBox
>component (like VB's, which exposes the 32bit value available via the
>LB_SETITEMDATA and LB_GETITEMDATA messages).
>There is, however, an array of TObjects associated with the ListBox, one
>per item (which can only store objects, not simple integer values)

it actually stores a 4 byte pointer, so you can typecast things into the
objects eg

var
  anothernumber, anumber : longint;
  alistbox :tlistbox;

begin {create the listbox elsewhere}
  alistbox.items.addobject('A longint', tobject(anumber));
{should work}

   anothernumber := longint(alistbox.items.objects[X});

Quote
>Does anyone know if the TObjects array uses the same 32bit storage area as
>that area available via the LB_SET/GET messages? IOW, is it safe for me to
>use the LB_SET/GET messages to store my own 32bit values related to each
>listbox item without Delphi thinking that they are TObject pointers or
>something?

dunno & don't recommend mixing your metaphors - imho Delphi has a fine
interface for these objects, so why bother with messages ?

Quote
>Finally, is there a better way to duplicate VB's 'ItemData'  functionality
>in D2?

if you were feeling v energetic, you could derive a new listbox class, and
give this a published property, of whatever name you wanted. Some coding
needed, but not that much

HTH

Boris Ingram, Cyborg Software
boris...@iafrica.com
100076.3...@compuserve.com
http://www.pcb.co.za/users/borising/cyborg.htm

Re:D2 ListBox 'ItemData' Property (like VB)


On Thu, 17 Oct 1996 10:06:21, boris...@iafrica.com (Boris Ingram)
wrote:

Quote
>In article <01bbbbd2$63f5ccc0$572537a6@beta> "Mike Cookson" <mcook...@internetMCI.com> writes:
>>From: "Mike Cookson" <mcook...@internetMCI.com>
>>Subject: D2 ListBox 'ItemData' Property (like VB)
>>Date: 17 Oct 1996 02:24:48 GMT

>>There doesn't seem to be an 'ItemData' property for Delphi's ListBox
>>component (like VB's, which exposes the 32bit value available via the
>>LB_SETITEMDATA and LB_GETITEMDATA messages).

>>There is, however, an array of TObjects associated with the ListBox, one
>>per item (which can only store objects, not simple integer values)

>it actually stores a 4 byte pointer, so you can typecast things into the
>objects eg

>var
>  anothernumber, anumber : longint;
>  alistbox :tlistbox;

>begin {create the listbox elsewhere}
>  alistbox.items.addobject('A longint', tobject(anumber));
>{should work}

>   anothernumber := longint(alistbox.items.objects[X});

>>Does anyone know if the TObjects array uses the same 32bit storage area as
>>that area available via the LB_SET/GET messages? IOW, is it safe for me to
>>use the LB_SET/GET messages to store my own 32bit values related to each
>>listbox item without Delphi thinking that they are TObject pointers or
>>something?

>dunno & don't recommend mixing your metaphors - imho Delphi has a fine
>interface for these objects, so why bother with messages ?

Yes, the Objects[] do map to the ItemData. And I have to agree with
Boris that it is not advisable to use messages as your code will loose
it's transparency..., i.e. it becomes harder to read.

Quote
>>Finally, is there a better way to duplicate VB's 'ItemData'  functionality
>>in D2?

No. If you just need a 4 byte storage area typecast to TObject and
store it there (and typecast the returned value to anything you want
to).

Quote
>if you were feeling v energetic, you could derive a new listbox class, and
>give this a published property, of whatever name you wanted. Some coding
>needed, but not that much

--
Stefan Hoffmeister                       Stefan.Hoffmeis...@Uni-Passau.de
University of Passau, Bavaria, Germany

Other Threads