whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

46 Visitors Online


 
...create a Component at Runtime?
Autor: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
[ Print tip ]  

Tip Rating (5):  
     


{
  Dieser Code erzeugt zur Laufzeit einen Button namens "MyButton".
  Beim Klicken auf diesen Button wird die Procedure 'ButtonClickHandler' ausgeführt.

  This code create a button called "MyButton" at runtime.
  Its onClick event is the procedure 'ButtonClickHandler'.
}

type
  
TForm1 = class(TForm)
    {...}
    
private
      
MyButton: TButton;
      // OnClick handler
      
procedure ButtonClickHandler(Sender: TObject);
  end;

var
  
Form1: TForm1;

implementation

{$R *.DFM}

// OnClick handler
procedure TForm1.ButtonClickHandler(Sender: TObject);
begin
  
ShowMessage(TButton(Sender).Name);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
MyButton := TButton.Create(Self);
  MyButton.Parent := Self;   // Set its parent (Form1)
  
MyButton.Name := 'Button1';
  MyButton.Caption := 'My Button';
  MyButton.SetBounds(20, 20, 80, 40);
  MyButton.OnClick := ButtonClickHandler; // assign onclick handler
end;

end.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners