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,513 other followers

Class methods in Record vs Class in Delphi 2010 – Stack Overflow

Posted by jpluimers on 2020/10/20

A still relevant part for [WayBack] Class methods in Record vs Class in Delphi 2010+ – Stack Overflow is the distinction between class methods on both:

  • on classes they can be either regular (no extra keyword), static or virtual.
  • on records they can only be static, as there is no inheritance on records
    • this also holds for any helpers that are not class helpers (and presumably if they are ever created: interface helpers)

While class methods inside classes can be used in the same way, they can in addition have another goal: they can be virtual. Called from a class variable this can lead to different implementations depending on the current content of that variable. This is not possible for records. As a consequence class methods in records are always static.

Thanks Uwe Raabe for this insight!

One odd thing on class methods in classes, is that when they need to be static when they are the read or write backing of a class property.

When a class method is static, any calls from it to virtual (or dynamic) methods will not be handled as such: there is no class VMT for it (as because they are static, they do not have a self parameter).


PS: I realised later that part of the above was already in E2398 Class methods in record types must be static (Delphi) – RAD Studio

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 )

Google photo

You are commenting using your Google 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: