Recent

Author Topic: Compile error: Wrong number of param!!  (Read 4047 times)

VictorZhang

  • New Member
  • *
  • Posts: 11
Compile error: Wrong number of param!!
« on: February 09, 2007, 02:09:30 pm »
The code can run on delphi/kylix,but a error occurs while  compiling with Lazarus

Code: [Select]

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Menus;

type

  { TForm1 }

  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure test(Sender:   TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
item:tmenuitem;
begin
  item:=tmenuitem.create(self);
  item.onclick:=test;
  MenuItem1.add(item);
end;
procedure   TForm1.test(Sender:   TObject);
begin
  showmessage(tmenuitem(sender).caption);
end;

initialization
  {$I unit1.lrs}

end.      



Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.0.4 [2006/08/20] for i386
Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for i386
Compiling /tmp/project1.lpr
Compiling unit1.pas
 unit1.pas(39,22) Error: Wrong number of parameters specified
item.onclick:=test;
unit1.pas(18,15) Hint: Found declaration: TForm1.test(TObject)
unit1.pas(53) Fatal: There were 1 errors compiling module, stopping



Any clues?Thanks
J.S.Bach is an evidence of God's existence.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: Compile error: Wrong number of param!!
« Reply #1 on: February 09, 2007, 03:42:11 pm »
You are using mode objfpc, which is the free pascal, pascal dialect. If you wish to use delphi dialect, change the beginning of your unit to:

unit Unit1;

{$mode delphi}{$H+}

-------------

on mode objfpc when you do this:

item.onclick:=test;

the compiler things you are calling function test, when in fact you want to pass it´s address, so that´s why the number of parameters is incorrect. For this code to work on mode objfpc you should write:

item.onclick:=@test;

VictorZhang

  • New Member
  • *
  • Posts: 11
J.S.Bach is an evidence of God's existence.

 

TinyPortal © 2005-2018