Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to store additional data in a TListBox along with each item it contains Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
63
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

In my application I have a TListBox control and I need to store additional data 
along with each item it contains. The additional data will be an integer variable 
and a status variable. What is the best way of doing this? Is there some other 
control I can use?

Answer:

TListBox objects are pointers, but you can cast a 32-bit integer to a pointer and 
store its value directly. Therefore, if your "integer variable" and "status 
variable" can be crammed into 32 bits, you can do this:
1   
2   procedure TForm1.Button1Click(Sender: TObject);
3   var
4     MyInt, MyStatus: smallint;
5     Combine: integer;
6   begin
7     MyInt := 1234;
8     MyStatus := 5678;
9     Combine := MyInt or (MyStatus shl 16);
10    with ListBox1.Items do
11    begin
12      { store the string and data }
13      AddObject('Foobar', pointer(Combine));
14      { retrieve the data }
15      MyInt := integer(Objects[0]) and $FFFF;
16      MyStatus := integer(Objects[0]) shr 16;
17    end;
18  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC