title: delphi class determined at runtime
body: <p>Is there a way in Delphi XE+ to create a function whose result is determined at runtime? </p>
  
  <p>For example:</p>
  
  <pre><code>function ARuntimeClass(achoice: integer): ClassType;
  begin
     case achoice of
       0: Result := TEdit;
       1: Result := TMemo;
       2: Result := TCheckbox;
       3: Result := TComboBox;
     end;
  end;
  </code></pre>
  
  <p>Then, at runtime:</p>
  
  <pre><code>var
    aComponent: TComponent;       
  begin
    aComponent := FindComponent('SomeComponent234');
    //then process
    ARuntimeClass(2).Checked := True;
    aComponent := FindComponent('SomeComponent123');
    //then process
    ARuntimeClass(0).Text := 'Chosen';    
  end;
  </code></pre>
  
  <p>I am trying to typecast at runtime.</p>