Notice that in the code above I used the AnonMeth symbol to refer to the anonymous method, not to invoke it. For invoking it, I should have typed: | AnonMeth (2)
The difference is clear; I need to pass a proper parameter to invoke the method. Things are slightly more confusing with parameterless anonymous methods. If you declare:
TAnyProc = reference to procedure; var
The call to AnyProc must be followed by the empty parenthesis, otherwise the compiler things you are trying to get the method (its address) rather than call it: | AnyProc ();
Something similar happens when you call a function that returns an anonymous method, as in the following case taken from the usual AnonymFirst example:
function GetShowMethod: TIntProc; var x: Integer; begi n x := Random (l00);
ShowMessage ('New x is ' + IntToStr (x)); Result :=
ShowMessage (IntToStr (x)); end;
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.