[fpc-devel] procedure Types

Christian Iversen chrivers at iversen-net.dk
Sat Mar 4 11:15:33 CET 2006


On Saturday 04 March 2006 10:09, Amir Aavani wrote:
> I have problem with procedure Types.
> Look at the following code:
>
>   TProcedure= procedure (S: String);
>   TTest= class
>     MyF: TProcedure;
>      procedure F1 (S: String);
>     procedure F2 (S: String);
>     ....
>     ...
>   end;
>
> TTest.constructor ;
> begin
>   MyF:= @F1;
> end;
>
> it says it can't cast "Procedure (S: String); Object" to TProcedure. The
> problem is clear but I don't know
> (can't find) any solution to define TProcedure as a procedure of a class
> which accepts one argument.

You have declared MyF as a TProcedure, so this is just not going to work.

Try this instead:

type
  TMyFProc = Procedure(S: String) of Object;

...
  MyF: TMyFProc;
...


that should work.

-- 
Regards,
Christian Iversen



More information about the fpc-devel mailing list