The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,947 other followers

Pointers to value and to reference types (was: delphi – Why does TValue.Make require a pointer to an object reference? – Stack Overflow)

Posted by jpluimers on 2012/05/30

Delphi seemingly makes the distinction between reference and value types disappear, especially because it hides the ^derefererncing operator for most usages:

  • there is no ^ dereferencing operator when following “class” type object instances, “interface” references and “object” type object instances, strings, open arrays and dynamic arrays: the dereferencing is implicit
  • usually you do not need the ^ dereferencing operator when

Rudy Velthuis wrote a great article on pointers in general. Though it was in the Delphi 2009 timeframe, almost everything is very valid. A few things are missing, some additions are below.

I’m not going into deep detail here right now, just a few notes to get people interested going.

Hopefully I will some time in the future to either go into more detail, or point to articles that do.

  1. “object” style object instances.
    Those have been deprecated since Delphi 1 (which introduced “class” style objects), but there are still libraries that use them, and (almost unbeleivable): they are supported in Delphi x64
  2. anonymous method references
  3. Events (method references) aka the “procedure … of object”/”function … of object”
    are implemented using the underlying TMethod type from the System unit
    always use the “Assigned” method to check if both the Data and Method field are non-nil

Even with those additions to Rudy’s list, I’m not 100% sure everything is complete now (:


via: delphi – Why does TValue.Make require a pointer to an object reference? – Stack Overflow.

4 Responses to “Pointers to value and to reference types (was: delphi – Why does TValue.Make require a pointer to an object reference? – Stack Overflow)”

  1. rvelthuis said

    Interesting additions. If I have time, I might add them to the article. Thanks.

    • jpluimers said

      You are most welcome. I’ve been extremely busy with projects lately, so I didn’t have much time to add more details myself. Will let you know of details when I get some more time (:

  2. WarrenP said

    I think that the “implicit reference semantics” of TObject was the most genius-level change in the language, that came in at the same time as the class keyword, and the parent class TObject, which is Delphi 1.0. Prior to Delphi 1.0, we had the “object” keyword. We still have the old objects and there are a few people out there who insist on using them, but mostly the “object” style of objects have gone away. In the turbo Pascal era, we used ^ and @ (dereference, and take address of) operators a lot, and combined with some quirks like “untyped parameters” it made for some pretty unreadable code. The new system avoids untyped parameters, and explicit by-reference semantics are done with the var keyword, and so even then, you rarely use pointers explicitly. And that, in a strongly-typed language, is the point. Amateurs (and even experts) making gratuitous use of Pointers is asking for trouble.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: