Welcome, Guest
Username: Password: Remember me
General discussions, feature requests for CodeTyphon Project and discussions that don't fit in any of the other specific CodeTyphon forum categories.
  • Page:
  • 1

TOPIC:

Something went wrong..... 6 years 3 months ago #12035

  • Tigr
  • Tigr's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 54
  • Thank you received: 1
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.

Something went wrong..... 6 years 3 months ago #12036

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4540
  • Thank you received: 1117
Thanks Sir
because is {$mode objfpc}, try this

btn.OnClick:=@Clicks;

if was {$mode delphi} then
use can use

btn.OnClick:=Clicks;
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Tigr

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

Last edit: by Sternas Stefanos.

Something went wrong..... 6 years 3 months ago #12037

  • Tigr
  • Tigr's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 54
  • Thank you received: 1
Thank You!

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

Last edit: by Tigr.
  • Page:
  • 1