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

How to use 'Prototype'

by Danilo Mon Nov 25, 2019 3:14 pm

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: 278
Joined: Wed Aug 19, 2015 3:02 pm
Location: United Kingdom

Re: How to use 'Prototype'

by SparrowhawkMMU Wed Dec 04, 2019 5:32 pm

Thanks for that, I did not know that was possible. It's always nice to learn something new :)
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 0 guests