Recent

Author Topic: Passing a function as a parameter  (Read 327 times)

Neville

  • New Member
  • *
  • Posts: 39
Passing a function as a parameter
« on: October 02, 2023, 08:32:01 pm »
I'm tearing my hair out trying to get passing a function as parameter to work.  I try to find the cause of the failure, I've put a skeleton together with just the relevant items in it.

Here's a (very) simple bit of code which when presented to the compiler complains "Wrong number of parameters".  This facility must work, so I assume I'm missing something fairly simple.  Can anyone point it out?

program Project1;

type Tmyfunc = function(s:string):boolean;
     TMyproc = procedure(w:word);



function TestF(s:string):boolean;
begin

end;


procedure NominateF(F:TMyfunc);
begin

end;

procedure NominateP(P:TMyProc);
begin

end;

begin
   NominateF(TestF);
end.


Thanks.

bobby100

  • Full Member
  • ***
  • Posts: 156
    • Malzilla
Re: Passing a function as a parameter
« Reply #1 on: October 02, 2023, 08:39:45 pm »
Code: Pascal  [Select][+][-]
  1. begin
  2.    NominateF(TestF(some_string));
  3. end.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

Lulu

  • Full Member
  • ***
  • Posts: 225
Re: Passing a function as a parameter
« Reply #2 on: October 02, 2023, 08:43:15 pm »
Hi, try this:
Code: Pascal  [Select][+][-]
  1. begin
  2.    NominateF(@TestF);
  3. end.
wishing you a nice life

Neville

  • New Member
  • *
  • Posts: 39
Re: Passing a function as a parameter
« Reply #3 on: October 02, 2023, 08:52:36 pm »
NominateF(@TestF);

That completely solves the problem.  Thank you.

 

TinyPortal © 2005-2018