Constructors
One simple rule about constructors in Delphi for .NET is different from Delphi Win32. You cannot access class members from inherited classes prior to calling the inherited constructor. This will result in a compile-time error. You can access members of the class itself. So, for the given classes, the comments annotate the valid and invalid statements within the constructor.
TMyBase = class(TObject) FBaseField: integer; end; TMyObject = class(TMyBase) FMyObjectField: integer; constructor Create; end;
The implementation of the preceding constructor above would be
constructor TMyObject.Create; begin FBaseField := 3; // error FMyObjectField := 3; // valid inherited; FBaseField := 3; // valid FMyObjectField := 3; // valid end;
Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.