[fpc-pascal] assigning a local function to a var

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Jul 11 10:36:49 CEST 2008


On 10 Jul 2008, at 23:50, Lourival Mendes wrote:

>  var
> //     my_proc : procedure;   // need to specify "local". impossible?
>     my_proc : TProcedure;   // Lourival
>
>  begin
>     what_to_say := 'hello, world!';
>
>     // Lourival Begin
>     my_proc:= nil;
>
>     if not Assigned(my_proc) then begin
>        my_proc:= TProcedure(@proc_a);
>        my_proc ();
>     end

This will compile (because you are disabling the compiler's type  
checking), but is guaranteed to
a) not function correctly most of the time
b) crash in various situations


Jonas



More information about the fpc-pascal mailing list