Difference between revisions of "FPC message: Wrong number of parameters specified"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; deleted category included in page template)
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
You confused the function and forgot a parameter or added a parameter too much.
 
You confused the function and forgot a parameter or added a parameter too much.
  
== Missing @ ==
+
== Missing <code>@</code> ==
  
 
For example:
 
For example:
<syntaxhighlight>Button1.Click := Button1Click;</syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>Button1.Click := Button1Click;</syntaxhighlight>
 
    
 
    
In mode [[ObjFPC]] you must add the @ to tell the compiler, that you want the pointer to the function, not the result of the function:
+
In [[Mode ObjFPC|<code>{$mode objfpc}</code>]] you must add the [[@|<code>@</code>-address-operator]] to tell the compiler, that you want the pointer to the function, not the result of the function:
<syntaxhighlight>Button1.Click := @Button1Click;</syntaxhighlight>
 
  
Delphi users often confuse this, because Delphi allows it and adds the @ internally. If you prefer the Delphi syntax you can use {$mode Delphi} instead of {$mode ObjFPC}.
+
<syntaxhighlight lang=pascal>Button1.Click := @Button1Click;</syntaxhighlight>
  
[[Category:Compiler Messages]]
+
Delphi users often confuse this, because Delphi allows it and adds the @ internally.
 +
If you prefer the Delphi syntax you can use [[Mode Delphi|<code>{$mode Delphi}</code>]] instead of <code>{$mode ObjFPC}</code>, or use the [[sGlobalModeswitch|mode switch]] <code>{$modeswitch classicprocvars on}</code>.

Latest revision as of 02:06, 16 February 2020

Deutsch (de) English (en)

Missing parameter or too many parameters

You confused the function and forgot a parameter or added a parameter too much.

Missing @

For example:

Button1.Click := Button1Click;

In {$mode objfpc} you must add the @-address-operator to tell the compiler, that you want the pointer to the function, not the result of the function:

Button1.Click := @Button1Click;

Delphi users often confuse this, because Delphi allows it and adds the @ internally. If you prefer the Delphi syntax you can use {$mode Delphi} instead of {$mode ObjFPC}, or use the mode switch {$modeswitch classicprocvars on}.