How to use 'Prototype'

Share your advanced knowledge/code with the community.
User avatar
Danilo
Posts: 51
Joined: Wed Feb 26, 2014 7:11 am

How to use 'Prototype'

Post 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)
cya,
...Danilo
User avatar
SparrowhawkMMU
Posts: 281
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

Re: How to use 'Prototype'

Post by SparrowhawkMMU »

Thanks for that, I did not know that was possible. It's always nice to learn something new :)
Post Reply