On Wed, 15 Feb 2006 14:15:42 +0000, Bobby Clarke wrote:
>Hi
>
>
>I want to pass a function name (Y) as a procedure parameter. Can someone
>tell me how to do this? My current solution was OK (just) for a couple
>of forms but unwieldy and non-expandable for even 4 forms. I suspect the
>answer is something to do with addresses and pointers but I have not
>found a solution.
>
>I have had two dead-end thoughts:
>1. I could make a TMyForm which embeds the function Y but I am already
>using this for something else and the number of types would double.
>2. If the routine (RoutineX) were on a Form rather than a Unit, I could
>set the calling Form as a property there before jumping over.
Bobbie,
To pass a procedure as a parameter you need to define a type for the procedure
eg
...
TYPE IFunction = Function (X : Integer) : Integer;
VAR IFun : IFunction;
FUNCTION Int_Fun (Y : Integer) : Integer;
VAR I, J : Integer;
BEGIN
I := 1;
For J := 2 To Y Do
I := I * J;
Result := I;
END; { Int_Fun }
...
FUNCTION Another_Int_Fun (Fun_Param : IFun; I : Integer) : Integer;
BEGIN
Result := Fun_Param (I);
END; { Another_Int_Fun }
...
IFun := Int_Fun;
...
Not very practical but illustrated the point.
NB The formal name of the parameters do not need to match but their types MUST.
--
Regards,
Allan JM Smith
(Northwood, Middlesex, England)
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/