User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Mar 2008
Posts: 2
Reputation: toxygen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toxygen toxygen is offline Offline
Newbie Poster

using method or dereferenced object pointer

  #1  
May 12th, 2008
I would like to ask whether pointer dereference by typecast is same in both cases:
  1. TComponent(my_tfplist[1]).mymethod
and
  1. 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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,736
Reputation: Duoas is a name known to all Duoas is a name known to all Duoas is a name known to all Duoas is a name known to all Duoas is a name known to all Duoas is a name known to all 
Rep Power: 9
Solved Threads: 172
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: using method or dereferenced object pointer

  #2  
May 12th, 2008
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.
Reply With Quote  
Join Date: Mar 2008
Posts: 2
Reputation: toxygen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toxygen toxygen is offline Offline
Newbie Poster

Re: using method or dereferenced object pointer

  #3  
May 12th, 2008
Originally Posted by Duoas View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Pascal and Delphi Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 10:56 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC