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 add a string and an integer value to the items property of a TListBox 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 All Versions
Views
79
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to add a string and an integer value to the items property of a TListBox

Answer:

This requires some type conversions. The TString component has an Objects array 
along with the string array that can be utilized for the purpose of storing integer 
data: The data type that the Objects array holds is TObject. In essence it holds a 
4 byte pointer value. So to put an integer value in it you would need to type cast 
that value. For example, the following is adding a string and an integer value of 
100 to an items property (TString object) of a Listbox:


Listbox1.Items.AddObject('Text string', TObject(100));


To get the value out do the following:

1   
2   Result := LongInt(Listbox1.Items.Objects[0]);




This assumes that Result is of type Longint and that the value that were after is 
at index position 0. Note: Though this works it is never wise to rely on the 
internal workings of an object. This is trick code and should be well commented.

If you want to keep track of more than one value then a new class can be derived 
from the TObject base class to hold these values.

3   type
4     ManyValues = class(TObject)
5       Value1: Integer;
6       Value2: Integer;
7     end;
8     { ... }


			
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