Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Rooster

Show Message on Button Click

Recommended Posts

Hi everyone,

 

I'm slowly getting the hang of scripting so Please keep your as simplified as possible.

 

After making some besic scripts I want to combine them under 1 single program...

So I'm trying to make a form with basic buttons to assign my scripts to, but I can't even make a button click to show a message.

 

I succeeded in getting a message box with a basic script using the ShowMessage function, but as soon as i try it in a form, it won't work.

 

Here's the code:

 

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

var
 Form1: TForm1;

procedure TestButton;
 begin
   ShowMessage('ok') 
 end;                           

procedure Button1Click(sender: TObject);
 begin
   case sender of 
     Form1.Button1: TestButton;
   end;
 end;  

procedure Form1_Init;
begin
 with Form1 do
 begin
   Form1 := CreateForm;
   Button1 := TButton.Create(Form1);
   with Form1 do
   begin
     Left := 228;
     Top := 129;
     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 := 4;
     Top := 4;
     Width := 296;
     Height := 40;
     Caption := 'Button1';
     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;

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

 

 

So if anyone sees what I'm doing and wants to tell me,

Thanks in advance

Share this post


Link to post
Share on other sites

You forgot to set your event handler!

 

Put this in your with Button1 do block

OnClick := @Button1Click;

 

Scar Divi has a nice form editor under Tools if you want one.

Share this post


Link to post
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...