To initialize Delphi entries, I always added a method (class or object) that would initialize the known good defaults. Delphi also allows you to define constructor entries with parameters, but you cannot define your own constructor without parameters.
TSomeRecord = record Value1: double; Value2: double; procedure Init; end; procedure TSomeRecord.Init; begin Value1 := MaxDouble; Value2 := Pi; end;
Given the above record, there is no warning that the record was not initialized. Developers can ignore the Init call in the record. Is there a way to automatically initialize default entries, potentially more than just FillChar ;
for example
var LSomeRecord: TSomeRecord begin // someone forgot to call LSomeRecord.Init here FunctionThatTakesDefaultSomeRecord(LSomeRecord); end;
How to automatically record to my default settings?
[Note] I do not want to change the problem after the answer. Any readers should read comments on best practices for using class methods to initialize instead of mutating object methods.
delphi
Jasper schellingerhout
source share