Recent

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

Neville

  • New Member
  • *
  • Posts: 45
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

  • Sr. Member
  • ****
  • Posts: 260
    • 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.

Lulu

  • Sr. Member
  • ****
  • Posts: 265
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!
GitHub repositories https://github.com/Lulu04

Neville

  • New Member
  • *
  • Posts: 45
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