Steve Williams wrote:
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.

The easiest way of doing that -- and arguably the best way -- is to use a TObjectList instead of a plain TList. Find that in the Contnrs unit in Delphi 5 and later.


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

That code does not use RTTI. The "is" and "as" operators don't require RTTI -- at least not the RTTI that the $M compiler directive controls.


--
Rob

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to