unit fmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    CheckBox1: TCheckBox;
    RadioButton1: TRadioButton;
    Memo1: TMemo;
    Button2: TButton;
    mmResult: TMemo;
    Button5: TButton;
    Button6: TButton;
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TBase = class(TObject)
  private
    iID : Integer;
    dValue : Double;
    sName : String;
  public
    procedure SetName(const sName : String );
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button5Click(Sender: TObject);
var
  aObj : TComponent;
  aButton : TButton;
  alb : TListBox;
  aForm : TForm1;
begin
  aObj := TComponent(TButton.NewInstance);
  aObj.Create(Self);
  aButton := TButton(aObj);
  aButton.Caption := 'I am a Button';

  if (aObj is TListBox) then
  begin
    alb := TListBox(aObj);
    alb.Items.Add('Test');
  end;

  if (aObj is TForm1) then
  begin
    aForm := TForm1(aObj);
    aForm.Caption := 'I am a Form';
    aForm.WindowState := wsNormal;
    aForm.ShowModal;
  end;
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  aBObj : TBase;
  aObj : TObject;
begin
  aObj := TObject(TBase.NewInstance.Create);
  ShowMessage(aObj.ClassName);
  aBObj := TBase(aObj);
  ShowMessage(aBObj.ClassName);
end;

{ TBase }

procedure TBase.SetName(const sName: String);
begin
  Self.sName := sName;
end;

end.
