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
Object List(String) Using TList 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
18-Sep-03
Category
VCL-General
Language
Delphi 3.x
Views
73
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Object List(String) Using TList

Answer:

Couldn't find too many examples on the net of how to do this so here it is.

Here some code for all you newbies(like myself kinda). That will let you create 
your own objectlist.
I used code from a program that manages email accounts for this example..

add items via  accountlist.add(TAccount.Create(Server, User, Password);

1   uses classes;
2   
3   type
4   
5     //Define the type of data for it to hold
6     TAccount = class
7     private
8       fServer: string;
9       fUser: string;
10      fPassword: string;
11    public
12      constructor create(Server, User, Password: string);
13      property Server: string read fServer write FServer;
14      property User: string read fUser write FUser;
15      property Password: string read fpassword write fpassword;
16    end;
17    // define the list
18    TAccountList = class(TList)
19    private
20      function GetItem(AIndex: Integer): TAccount;
21    public
22      constructor create;
23      destructor Destroy; override;
24      function add(Account: TAccount): integer;
25      property Items[AIndex: Integer]: TAccount read getitem;
26    end;
27  implementation
28  
29  constructor TAccount.create(Server, User, Password: string);
30  begin
31    fserver := Server;
32    fUser := User;
33    fPassword := Password;
34  end;
35  
36  constructor TAccountlist.create;
37  begin
38    inherited Create;
39  end;
40  
41  destructor TAccountList.Destroy;
42  begin
43    try
44      Clear;
45    finally
46      inherited Destroy;
47    end;
48  end;
49  
50  function TAccountlist.add(Account: TAccount): integer;
51  begin
52    result := inherited Add(Account);
53  end;
54  
55  function TAccountList.GetItem(AIndex: integer): TAccount;
56  begin
57    result := TAccount(inherited Items[AIndex]);
58  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