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
Create a sorted TList that holds integers 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
26-Mar-03
Category
VCL-General
Language
Delphi 3.x
Views
70
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How can I create a TStringlist cousin which holds integers rather than strings. I 
need the ability to keep a list of objects sorted by an integer with full binary 
IndexOf.

Answer:

Use a TList, and do casts where appropriate:

To write:

1   MyList.Add(Pointer(17));
2   MyList.Add(Pointer(39));
3   
4   //To read:
5   
6   MyInt := Integer(MyList[0]);
7   
8   //To sort:
9   
10  procedure CompareInts(Item1, Item2: Pointer): Integer;
11  begin
12    if Integer(Item1) > Integer(Item2) then
13      Result := 1
14    else if if Integer(Item1) < Integer(Item2) then
15      Result := -1
16    else
17      Result := 0;
18  end;
19  { ... }
20  MyList.Sort(CompareInts);


			
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