title: How objects are initialized in delphi XE vs XE4
body: <p>I have a class </p>
  
  <pre><code>type
    TLoadOption = class
    private
      FAutoSearch: Boolean;
    public
      property AutoSearch: Boolean read FAutoSearch write FAutoSearch;
    end;
  </code></pre>
  
  <p>In one of the functions i am creating the object of the class in stack</p>
  
  <pre><code>procedure MyView.InitializeForm(const aMsg: MyMsg);
  //---------------------------------------------------------------------------
  var
    Options: TLoadOption;
  begin
  
    if aMsg.OptionalObject &lt;&gt; nil then
     Options := aMsg.OptionalObject as TLoadOption;
  
    if Assigned(Options) and Options.AutoSearch then
      DoRefresh;
  end;
  </code></pre>
  
  <p>I am not passing anything in aMsg so ideally Options is not set.</p>
  
  <p>In Delphi XE by default Options is set as nil and so this DoRefresh is not called but when i execute the same code in Delpi XE4 the options is initialized with some random value and AutoSearch becomes true always and it results in calling this DoRefresh function which is undesired. </p>
  
  <p>I am wondering if there are any compiler options that set default values to uninitialized variable.  My only solution as of now is like this</p>
  
  <pre><code> procedure MyView.InitializeForm(const aMsg: MyMsg);
      //---------------------------------------------------------------------------
      var
        Options: TLoadOption;
      begin
        Options := nil;
  
        if aMsg.OptionalObject &lt;&gt; nil then
         Options := aMsg.OptionalObject as TLoadOption;
  
        if Assigned(Options) and Options.AutoSearch then
          DoRefresh;
      end;
  </code></pre>
  
  <p>is this a correct way?</p>