title: What is the sequence for Form and other object creation in Lazarus
body: <p>I have a simple program with two forms, a main form and a settings form. Obviously the settings form allows the user to change settings. I have a settings unit whose initialization section reads settings from a file.</p>
  
  <p>When the program is first installed and started up for the first time, the settings will be empty and if so I want to show the settings form. The question is where to put the check and invoking code.</p>
  
  <p>My Application.lpr contains</p>
  
  <pre><code>begin
    RequireDerivedFormResource := True;
    Application.Initialize;
    Application.CreateForm(TMainForm, MainForm);
    Application.CreateForm(TSettingsForm, SettingsForm);
    Application.Run;
  end.                       
  </code></pre>
  
  <p>My Settings unit is roughly like this</p>
  
  <pre><code>uses
    Classes, SysUtils, INIFiles;
  
  type
    TSettings = class
      public
        procedure LoadFromFile();
        procedure SaveToFile();
      ...
      end;
  
  var
    Settings: TSettings;
  
  implementation
  
  { TSettings }
  
  ...
  
  initialization
    Settings := TSettings.Create;
    Settings.LoadFromFile();
  
  finalization
    Settings.SaveToFile();
    FreeAndNil(Settings);
  
  end.       
  </code></pre>
  
  <p>If I do this check for empty settings in MainForm.FormCreate, I can't show the Settings Form because it hasn't been created yet.</p>
  
  <p>I don't see how I could do it in Application.lpr as there isn't an obvious variable there to refer to the SettingsForm instance. Anyway it doesn't feel right to put it there.</p>
  
  <ul>
  <li><p>Can I do this check in SettingsForm.FormCreate assuming that this is only called <em>after</em> SettingsForm is fully initialized and ready to be shown? Can you call <code>Show()</code> in <code>FormCreate()</code>?</p></li>
  <li><p>I'm not sure when exactly my Settings type gets instantiated.</p></li>
  <li><p>Are there any ideas, guidelines design-patterns or other material I could use to determine where to put my check for empty settings?</p></li>
  </ul>