Link to home
Start Free TrialLog in
Avatar of lpd
lpd

asked on

Show a label on a form created at runtime

At runtime a have created a form. How can I create a label on this form at runtime so a can display a message.

ASKER CERTIFIED SOLUTION
Avatar of Pegasus100397
Pegasus100397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rickpet
rickpet

Okay...you can also create your label at runtime...



type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Label1 : TLabel;
    procedure MyClick(Sender: TObject);
  end;

var
  Form1: TForm1;


implementation

{$R *.DFM}

procedure TForm1.MyClick(Sender: TObject);
begin
  ShowMessage('Hello');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Label1 := TLabel.create(self);
with Label1 do
begin
  parent := self;  //or the form/panel...
  top := 10;
  left := 20;
  caption := 'My Message';
  onclick := myClick;
  show;
end;
end;

end.

Rick