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),staticorvirtual. - on
records they can only bestatic, as there is no inheritance on records- this also holds for any helpers that are not
classhelpers (and presumably if they are ever created:interfacehelpers)
- 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 aclassvariable 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






Leave a comment