Solved

Need TList Example

Posted on 1998-12-28
10
366 Views
Last Modified: 2011-09-20
Hi,

I'm trying to create an object derived from TList that will act as a container for other objects.
For example the object TEmails would be derived from TList. The objects in TEmails would be TMessage objects, derived from TObject.

How do I create TMessage objects by using Add from TEmails (TList) at runtime and how could I access their properties and methods?

Can you help me with an example?

Thanks.
0
Comment
Question by:michaelsanders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 1353451
Here is this source for TObjectList I wrote recently. Either rename TObject to TEmail, or derive from it and override the get/put/last methods and items property I have done.

Then just add objects to it like this

TEmailList.Add(TEmail.Create);
TEmail.Last.MyProp := 'Fred';
or

MyEmail := TEmail.Create;
TEmailList.Add(MyEmail );
MyEmail.MyProp := 'Fred';

If you have any more Q's just yell!

Cheers,

Raymond.



type
  TObjectList = class(TList)
    private
      FOwnObjects : Boolean;

    protected
      function Get(Index : Integer) : TObject;
      procedure Put(Index : Integer;
                    AObject : TObject);
    public
      property Items[Index : integer] : TObject read get write put; default;
      property OwnObjects : Boolean read FOwnObjects write FOwnObjects;

      constructor Create;
      destructor Destroy; Override;

      Function First : TObject;
      Function Last : TObject;
      Procedure Clear;
  end;

implementation


{ TObjectList }

Constructor TObjectList.Create;

begin
  Inherited;

  FOwnObjects := True;
end;

destructor TObjectList.Destroy;
var
  I : Integer;
begin
  if FOwnObjects then // better clobber them
    for I := 0 to Count - 1 do
      Items[i].Free;

  Inherited;
end;

function TObjectList.Get(Index : Integer) : TObject;

begin
  Result := TObject(Inherited Get(Index));
end;

procedure TObjectList.Put(Index : Integer;
                                    AObject : TObject);
begin
  Inherited Put(Index, AObject);
end;

Function TObjectList.Last : TObject;

begin
  Result := TObject(Inherited Last);
end;

Function TObjectList.First : TObject;

begin
  Result := TObject(Inherited First);
end;

Procedure TObjectList.Clear;
var
  I : Integer;
begin
  if FOwnObjects then // better clobber them
    for I := 0 to Count - 1 do
      Items[i].Free;

  Inherited;
end;
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1353452
Oops,

Better I menat TMessage when I said TEmail and EmailList when I said TEmailList. EmailList would of course be an instance of TEmailList... (which would be a TObject list modified in the ways I mentioned in my answer)

You can treat it just as a normal TList:

MyEmailList[i].MyProp := 'Fred'; // etc

Cheers,

Raymond.

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353453
Hi Raymond, you're too fast...
Are you just sitting at home and do nothing but wait for new questions?   :-)))

Regards, Madshi.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:rwilson032697
ID: 1353454
No Madshi, just the luck of the draw!

Anyway, after cleaning off Dwwang's tire marks I thought it was time I chalked up a few more ;-)

Cheers,

Raymond.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353455
:-)

If I look at the currently locked questions, you'll have success with that...

Regards, Madshi.
0
 
LVL 1

Expert Comment

by:Oli2
ID: 1353456
That's something I've been wondering for a long time...
how do you guys find so much time to answer all these questions?
I mean, you've got to be online 24 h/day and reloading http://.../.../comp/lang/delphi/ 
every 30 sec. ?
;-))

Greetings, Oli
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1353457
Hi, I heard someone talking about me, right? :-)

Anyway, I will leave this site soon, that's why I utilize these ten days to get higher and higher on the ranking list - to let my freinds see me for longer time.

Raymond, I think you could easily get in front of me within few days in the year 1999. By the way, my English is yet not so good, so would you tell me what means "cleaning off Dwwang's tire marks"? :-)

Cheers,
Season's greeting from China!

Wang
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353458
Hi Wang,

what do you mean with you will leave this site soon? Do you mean you don't like us anymore or what?

Regards, Madshi.

P.S: I had to start my translator program to understand what Raymond meant...   :-)))
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1353459
No, I like all of you very much, also this site very much. However, I need to go now, to leave Internet, computer, and all of you. Tommorow you will see my message saying farewell to all.

Regards, Wang

P.S. I think raymond could even get in front of me within the year 1998. :-)))
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1353460
We will be sad to see you leave Wang - you contribute a high level of expertise to the answers provided here.

Cheers,

Raymond.

PS: 'tire marks' is a way of saying you caught up with me and went past so fast you ran over me! :-) :-)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question