0

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

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by toxygen
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.