Make controls at runtime  

Send By: Q3 Team
Web : www.q3.nu
Email: dlib@q3.nu
Date: 19/01/00

Tip accessed 455 times

 


By example, we make a button in the OnCreate event handler of your form:


  procedure TForm1.FormCreate(Sender: TObject);
    var
      i: Integer;
      Boton: TButton;
    begin
      Boton := TButton.Create(Self);
      Boton.Parent := Self;
      Boton.Left := 100;
      Boton.Top := 100;
      Boton.Caption:='Pulsame';
      Boton.Name := 'Boton';
    end;



and now, you will want to make something with the button when press it, no? then we make their event handler procedure:


   procedure TForm1.ClickBoton(Sender: TObject);
    begin
      Boton.Caption := 'Pulsado'; {Pressed}
    end;



and we assign it to the Button with this:


 	Boton.OnClick:=ClickBoton;



NOTE: This method is valid for any component created in runtime.