Page 1 of 1

How to use 'Prototype'

Posted: Mon Nov 25, 2019 3:14 pm
by Danilo
Using 'Prototype' we are able to call functions using function pointers.

Code: Select all

Prototype ProtoMax(Value, Print = #False)

Procedure Max1(Value, Print)
    Debug "Max1 : " + Value
EndProcedure

Procedure Max2(Value, Print)
    Debug "Max2 : " + Value
EndProcedure

Max.ProtoMax = @Max1() ; Set the function pointer
Max(10)

Max.ProtoMax = @Max2() ; Change the function pointer
Max(20)                ; the function call doesn't change

Structure s_evenmore
    f.ProtoMax
EndStructure

Structure s_more
    f.ProtoMax
    evenmore.s_evenmore
EndStructure

Structure tst
    f1.ProtoMax
    f2.ProtoMax
    more.s_more
EndStructure

*struct.tst             = AllocateStructure( tst )
*struct\f1              = @Max1()
*struct\f2              = @Max2()
*struct\more\f          = @Max1()
*struct\more\evenmore\f = @Max2()

*struct\f1(30)
*struct\f2(40)
*struct\more\f(50)
*struct\more\evenmore\f(60, #True)

Re: How to use 'Prototype'

Posted: Wed Dec 04, 2019 5:32 pm
by SparrowhawkMMU
Thanks for that, I did not know that was possible. It's always nice to learn something new :)