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
classe
s they can be either regular (no extra keyword),static
orvirtual
. - on
record
s they can only bestatic
, 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)
- this also holds for any helpers that are not
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 aclass
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 alwaysstatic
.
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).
–jeroen
PS: I realised later that part of the above was already in E2398 Class methods in record types must be static (Delphi) – RAD Studio