title: Delphi - Create instance of subclass
body: <p>I have a class defined as:</p>
  
  <pre><code>TfraFrame = class(TFrame);
  </code></pre>
  
  <p>then I have several subclasses all inherting from this, such as:</p>
  
  <pre><code>TfraUsers = class(TfraFrame);
  TfraGroups = class(TfraFrame);
  TfraMenus = class(TfraFrame);
  </code></pre>
  
  <p>In my main form i have declared variables as:</p>
  
  <pre><code>var
    fraUsers: TfraUsers;
    fraGroups: TfraGroups;
    fraMenus: TfraMenus;
  </code></pre>
  
  <p>Now my question is, I would like to have one single function to control the generation of the instances of each class. There should only be once instance of each class, but i only want to create the instances if the user requires them.</p>
  
  <p>I would like to pass the variable like this:</p>
  
  <pre><code>procedure ShowFrame(Frame: TfraFrame)
  begin
    if Frame = nil then
    begin
      Frame := TfraFrame.Create(self);
      Frame.Init(Panel1);
    end;
  
    Frame.Show;
  end;
  </code></pre>
  
  <p>and call it like this;</p>
  
  <pre><code>ShowFrame(fraUsers);
  </code></pre>
  
  <p>I was expecting it to create a instance of <code>TfraUsers</code> (because that is what <code>fraUsers</code> is declared as), however, i suspect it may be creating an instance of <code>fraFrame</code>.</p>
  
  <p>Is there a way to create an instance of the type that the variable was declared as?</p>