43 פיט - יפלד
ישאר דומע | םיפיטה דומע רנק ודיע תאמ

?(םתוא םיררחשמ ךיאו) הציר ןמזב םידקפ םירצוי ךיא

unit Unit1;

interface

uses windows .......... ....;

..
type
  TForm1 = class(TForm)
             
             private
                     
             public
             MyButton : Tbutton;
             procedure MyButtonClick(Sender : TObject);
           end;

var
 Form1 : TForm1;

implementation
...


procedure TForm1.FormCreate(Sender : TObject);
....

begin
 Button1.Caption:='Click me to Create new Button';
 Button1.tag:=1; //I want to know if the button created
                 //the new button or it need to free it.

 ....
end;

procedure TForm1.Button1Click(Sender : TObject);
begin
 if Button1.tag=1 then
  begin
    MyButton:=TButton.Create;
    MyButton.left:=Button1.Width + 10;
    MyButton.Top := Buton1.Top;
    MyButton.caption:='Click me to say hallo';
    MyButton.OnClick:=MyButtonClick

    Button1.Tag:=0;
    button1.caption:='Click me to free the created button';
  end
 else begin
         MyButton.free;
         Button1.Tag:=1;
         Button1.Caption:='Click me to Create new Button';
        end;
end;

Procedure TForm1.MyButtonClick(Sender : TObject);
begin
 ShowMessage('hallo');
end;

...
end.