Forum

× General discussions, feature requests for CodeTyphon Project and discussions that don't fit in any of the other specific CodeTyphon forum categories.

Question Something went wrong.....

  • Tigr
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
2 months 6 days ago #12035 by Tigr
Something went wrong..... was created by Tigr
The simplest example of creating an event for a dynamically created button component does not work ((( What's wrong?


unit Unit1;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

{ TForm1 }

TForm1 = class(TForm)
Button1: TButton;

procedure Button1Click(Sender: TObject);


private

public

procedure Clicks(Sender: TObject);
end;

var
Form1: TForm1;


implementation
var
btn:TButton;


{$R *.frm}

{ TForm1 }
procedure Tform1.Clicks(Sender: TObject); // unit1.pas(39,18) Error: Found declaration: Clicks(TObject);
begin
ShowMessage('123');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
btn:=Tbutton.Create(form1);
btn.Parent:=form1;
btn.Left:=80;
btn.Top:=80;
btn.Caption:='Button';
btn.Height:=30;

btn.OnClick:=Clicks; // unit1.pas(54,16) Error: Wrong number of parameters specified for call to "Clicks"
end;

end.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
2 months 6 days ago - 2 months 6 days ago #12036 by Sternas Stefanos
Replied by Sternas Stefanos on topic Something went wrong.....
Thanks Sir
because is {$mode objfpc}, try this

btn.OnClick:=@Clicks;

if was {$mode delphi} then
use can use

btn.OnClick:=Clicks;

CodeTyphon Architect and Programmer
Last edit: 2 months 6 days ago by Sternas Stefanos.
The following user(s) said Thank You: Tigr

Please Log in or Create an account to join the conversation.

  • Tigr
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
2 months 6 days ago - 2 months 6 days ago #12037 by Tigr
Replied by Tigr on topic Something went wrong.....
Thank You!
Last edit: 2 months 6 days ago by Tigr.

Please Log in or Create an account to join the conversation.