Board index » delphi » QUESTION: List of classes in TList

QUESTION: List of classes in TList

  I am a raw beginner to Pascal and am struggling with OOP.
Recently I was writing a programme to simulate a few circles
moving in  a window and bouncing off the "window walls" ( I know,
not very inspiring stuff but its a start).I defined a class to
hold the co-ordinates,speed and direction of my balls and then
stored these in a TList.Here is where my problems began..
   What is actually held in the TList object? Does it contain
the instances of the classes or just the pointers to them.
If it only holds pointers, then do I need to typecast to refer to
the object?
 Question 2: what is the best way to simulate movement.with
Delphi?
                   Please don't laugh at me
                                Thanking you in advance
                                       Peter.
 

Re:QUESTION: List of classes in TList


On 28 Sep 1995 15:47:06 GMT, Peter Kohout <z...@ozemail.com.au.>
wrote:

Quote
>  I am a raw beginner to Pascal and am struggling with OOP.
>Recently I was writing a programme to simulate a few circles
>moving in  a window and bouncing off the "window walls" ( I know,
>not very inspiring stuff but its a start).I defined a class to
>hold the co-ordinates,speed and direction of my balls and then
>stored these in a TList.Here is where my problems began..
>   What is actually held in the TList object? Does it contain
>the instances of the classes or just the pointers to them.
>If it only holds pointers, then do I need to typecast to refer to
>the object?
> Question 2: what is the best way to simulate movement.with
>Delphi?
>                   Please don't laugh at me
>                                Thanking you in advance
>                                       Peter.

According to Delphi's online help: Yes, The List property of TList is
a list of pointers.  This is the gist of some of their sample code to
use the TList object.

var
   oObjList : TList

{assume that TCircles have been added to this list}

procedure ShowAll;
var
   oCurrCircle : TCircle;
   iCounter : Integer;
begin
   for iCounter := 0 to oObjList.Count-1 do begin
      oCurrCircle := oObjList.List[iCounter];
      oCurrCircle.Show;
   end;
end;

Simulate movement?   Hope this helps...

-Matt

Re:QUESTION: List of classes in TList


TLists are *magical* objects. Get to know them well!
TLists are your friends!

Seriously, TLists do store nothing but pointers. You
need to typecast once you get the pointer out.

Simulate movement by changing the Top and Left parameters
of a component. it'll scoot right along... (call invalidate
aferwards if it doesn't; sometimes that's needed...)

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/  Green Meddler  kilga...@tde.com   Nathan F. Wallace _/
_/     http://www.webcom.com/~kilgalen/welcome.html     _/
_/     http://www.webcom.com/~kilgalen/nerelon.html     _/
_/    C.I.U.P.K.C. Software -- Unleashing the Power!    _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Other Threads