Board index » delphi » TButton.Create(self) --> each button another action???
Dirk
![]() Delphi Developer |
TButton.Create(self) --> each button another action???2003-08-16 06:24:53 AM delphi160 Hi, I am just curious if this is possible: My app makes his own buttons with "TButton.Create(self)" Each button has his own name and position. Now i want each button to have his own "OnClick" action. Example-->button1 says: "i'm button 1" so this would be the action --> ShowMessage('i''m button 1'); button2 says: "i'm button 2" button3 says: "i'm button 3" ....... Any help is much appreciated! This is my code so far: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i: Integer; knop: TButton; begin for i:= 1 to StrToInt(Edit1.Text) do //Edit1.Text is a text box where you can type a integer Begin knop := TButton.Create(self); with knop do begin Name := 'knop'+IntToStr(i); Parent := Self; Left := 20; Top := 20 + i * 30; Width := 100; Height := 25; Caption := 'Knoppeke nr.'+IntToStr(i); end; end; end; end. |