unit fmMain;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function CreateControl(classref : TControlClass; const cName : String;
                           const X, Y, W, H : Integer) : TControl;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.CreateControl(classref: TControlClass;
  const cName: String; const X, Y, W, H: Integer): TControl;
begin
  Result := classref.Create(Self);
  Result.Name := cName;
  Result.Parent := Self;
  Result.Left := X;
  Result.Top := Y;
  Result.Width := W;
  Result.Height := H;
  Result.Visible := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CreateControl(TEdit, 'TEdit1', 10, 10, 100, 30);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  CreateControl(TButton, 'TButton1', 150, 10, 100, 30);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  CreateControl(TListBox, 'TListBox1', 50, 80, 200, 200);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  CreateControl(TMemo, 'TMemo1', 350, 80, 200, 200);
end;

end.
