> I understand that TList is a list of pointers. What I cannot understand is
> why I can't do something like\
>
> for i := 0 to AList.Count do
> begin
>          if AList.Items[i]^ is TMyObject then
>          with AList.Items[i]^ as TMyObject do
>
> etc etc etc.

You can.  You just need to tell the compiler that it is a TObject first. 
This then allows the compiler to know that you are dealing with an object.
not just a pointer to a block of memory.  It needs to know it's an object
so it knows that there is RTTI attached to this block of memory.

  for i := 0 to AList.Count - 1 do
  begin
    if TObject(AList.Items[i]) is TMyObject then
      with TMyObject(AList.Items[i]) do

Or even simpler, if you are only adding the same type of object to the
list, then you do not have to check the type.  Just typecast.

  for i := 0 to AList.Count - 1 do
  begin
    with TMyObject(AList.Items[i]) do

> In other words, I suppose my question is "If TList is a list of TPointer,
> the how do I dereference the pointer to access the object? Is accessing
> the
> Items property the only way to do it?"

You do not dereference the pointer because variables that reference
objects are really pointers anyway.

Sly





This message and its attachments may contain legally privileged or confidential 
information. This message is intended for the use of
the individual or entity to which it is addressed. If you are not the addressee 
indicated in this message, or the employee or
agent responsible for delivering the message to the intended recipient, you may 
not copy or deliver this message or its attachments
to anyone. Rather, you should permanently delete this message and its 
attachments and kindly notify the sender by reply e-mail. Any
content of this message and its attachments, which does not relate to the 
official business of the sending company must be taken not
to have been sent or endorsed by the sending company or any of its related 
entities. No warranty is made that the e-mail or attachment(s)
are free from computer virus or other defect.
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to