Jump to content
fiblearn

Form Button.OnClick execute procedure 'nameprocedure'

Recommended Posts

Hello, i need some help for Button1 (event-button-onclick-execute a specificate procedure)

 

type
 TForm1 = record
   Form1: TForm;
   Button1: TButton;
 end;

var
 Form1: TForm1;

procedure TestButon;
begin
  WriteLn('Butonul functioneaza');
end;
procedure Form1_Init;
begin
 with Form1 do
 begin
   Form1 := CreateForm;
   Button1 := TButton.Create(Form1);
   with Form1 do
   begin
     Left := 333;
     Top := 302;
     Caption := 'Form1';
     ClientHeight := 202;
     ClientWidth := 304;
     Color := clWindow;
     Font.Charset := DEFAULT_CHARSET;
     Font.Color := clWindowText;
     Font.Height := -11;
     Font.Name := 'Tahoma';
     Font.Style := [];
     OldCreateOrder := False;
     PixelsPerInch := 96;
   end;
   with Button1 do
   begin
     Parent := Form1;
     Left := 0;
     Top := 182;
     Width := 304;
     Height := 20;
     Align := alBottom;
     Caption := 'Run!';
     TabOrder := 0;

   end;
 end;
end;

procedure Form1_SafeInit;
var
 v: TVariantArray;
begin
 SetLength(v, 0);
 ThreadSafeCall('Form1_Init', v);
end;

function Form1_ShowModal: Boolean;
begin
 Result := Form1.Form1.ShowModal = mrOk;
end;

function Form1_SafeShowModal: Boolean;
var
 v: TVariantArray;
begin
 SetLength(v, 0);
 Result := ThreadSafeCall('Form1_ShowModal', v);
end;

 

 

I do not want to bother anyone with my questions, I searched for doc. some time and still have not found. I apologize if the post is stupid

Link to comment
Share on other sites

Do you need...

 

type
 TForm1 = record
   Form1: TForm;
   Button1: TButton;
 end;

var
 Form1: TForm1;

procedure TestButon;
begin
  WriteLn('Butonul functioneaza');
end;

procedure ButtonClick(sender: TObject);
begin
 case sender of
   Form1.Button1: TestButon; 
 end;
end;

procedure Form1_Init;
begin
 with Form1 do
 begin
   Form1 := CreateForm;
   Button1 := TButton.Create(Form1);
   with Form1 do
   begin
     Left := 333;
     Top := 302;
     Caption := 'Form1';
     ClientHeight := 202;
     ClientWidth := 304;
     Color := clWindow;
     Font.Charset := DEFAULT_CHARSET;
     Font.Color := clWindowText;
     Font.Height := -11;
     Font.Name := 'Tahoma';
     Font.Style := [];
     OldCreateOrder := False;
     PixelsPerInch := 96;
   end;
   with Button1 do
   begin
     Parent := Form1;
     Left := 0;
     Top := 182;
     Width := 304;
     Height := 20;
     Align := alBottom;
     Caption := 'Run!';
     TabOrder := 0;
     OnClick := @ButtonClick;
   end;
 end;
end;

procedure Form1_SafeInit;
var
 v: TVariantArray;
begin
 SetLength(v, 0);
 ThreadSafeCall('Form1_Init', v);
end;

function Form1_ShowModal: Boolean;
begin
 Result := Form1.Form1.ShowModal = mrOk;
end;

function Form1_SafeShowModal: Boolean;
var
 v: TVariantArray;
begin
 SetLength(v, 0);
 Result := ThreadSafeCall('Form1_ShowModal', v);
end;

begin
 Form1_SafeInit;
 Form1_SafeShowModal;     
 FreeForm(Form1.Form1);
end.

 

Something like that? :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...