I would like to ask whether pointer dereference by typecast is same in both cases:

TComponent(my_tfplist[1]).mymethod

and

TComponent(my_tfplist[1]^).mymethod

both things are doing the same thing (at least it behaves so), but compiler generates different code, so i'm curious what is the difference between those two.

to clarify:
my_tfplist is an object instance of class tfplist (or tlist, doesn't matter really).

thanks

In Delphi (as in C++, etc.), a reference is really a veiled pointer. Hence, when you declare a variable of type var TMyObject: MyObject; space is not reserved for the entire object; rather, MyObject is a pointer to a TMyObject.

The compiler is smart enough to know the difference, but allows for the possibility that the programmer knows something it doesn't when you use the second syntax you illustrated. However, unless you really do know something funny about your variable, you should stick to the first syntax.

Hope this helps.

However, unless you really do know something funny about your variable, you should stick to the first syntax.

Hope this helps.

thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.