•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 374,011 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,728 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
Views: 378 | Replies: 2
![]() |
•
•
Join Date: Mar 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I would like to ask whether pointer dereference by typecast is same in both cases:
and
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
delphi Syntax (Toggle Plain Text)
TComponent(my_tfplist[1]).mymethod
delphi Syntax (Toggle Plain Text)
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
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,736
Reputation:
Rep Power: 9
Solved Threads: 172
In Delphi (as in C++, etc.), a reference is really a veiled pointer. Hence, when you declare a variable of type
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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Pascal Question
- Next Thread: OnCalcField modifying its own DataSet - Error



Linear Mode