title: How can Delphi records be initialized automatically?
body: <p>To initialize Delphi records I've always added a method (class or object) that would initialize to known good defaults. Delphi also allows for defining record "constructors" with parameters, but you cannot define your own parameter-less "constructor".</p>
  
  <pre><code>TSomeRecord = record
   Value1: double;
   Value2: double;
  
   procedure Init;
  end;
  
  procedure TSomeRecord.Init;
  begin
    Value1 := MaxDouble;
    Value2 := Pi;
  end; 
  </code></pre>
  
  <p>Given the record above there is no warning that a record has not been initialized. Developers may neglect to call <code>Init</code> on the record. Is there a way to <strong>automatically</strong> initialize records to my default, potentially more than just a simple <code>FillChar</code>;</p>
  
  <p>For instance</p>
  
  <pre><code>var 
    LSomeRecord: TSomeRecord
  begin
    // someone forgot to call LSomeRecord.Init here
    FunctionThatTakesDefaultSomeRecord(LSomeRecord);
  end; 
  </code></pre>
  
  <p>How can a record be initialized to my defaults automatically?</p>
  
  <p>[Note]
  I don't want to modify the problem after it has been answered. Any readers are directed to read the comments on best practices on using class methods for initialization instead of a mutating object method. </p>