Just starting out? Need help? Post your questions and find answers here.
QuimV
Enthusiast
Posts: 337 Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN
Post
by QuimV » Tue Oct 03, 2017 10:17 am
Here is my code:
Code: Select all
Structure triFunction
Function$
Function.l
Map Params.s()
EndStructure
Global triFunction.triFunction
Procedure Test1(*Func.triFunction)
Debug "***************"
Debug "Inside Test1"
Debug *func\Function$
Debug *Func\Params("1")
Debug *Func\Params("2")
Debug "***************"
EndProcedure
Procedure Test2(Param1$)
Debug "***************"
Debug "Inside Test2"
Debug Param1$
Debug "***************"
EndProcedure
Procedure ExecuteAnyFunction (*Func.triFunction)
Protected Param1$
If *Func\Function$ = "Test1(*Func.triFunction)"
CallCFunctionFast(*Func\Function, *Func)
ElseIf *Func\Function$ = "Test2(Param1$)"
Param1$ = *Func\Params("1")
CallCFunctionFast(*Func\Function, @Param1$)
EndIf
;Result = CallCFunctionFast(*FunctionPointer [,Parameter1 [, Parameter2...]])
EndProcedure
; Configure function 1 structure
triFunction\Function$ = "Test1(*Func.triFunction)"
triFunction\Function = @Test1()
AddMapElement(triFunction\Params(),"1")
triFunction\Params() = "Text Param 1"
AddMapElement(triFunction\Params(),"2")
triFunction\Params() = "Text Param 2"
; Call to execute function Test1
ExecuteAnyFunction(@triFunction)
; Configure function 2 structure
triFunction\Function$ = "Test2(Param1$)"
triFunction\Function = @Test2()
AddMapElement(triFunction\Params(),"1")
triFunction\Params() = "Default Text"
; Call to execute function Test2
ExecuteAnyFunction(@triFunction)
If you execute this code step by step you will see that the first execution of "Test1" is correct, but spontaneously , the function is executed again (re-executed) and you will get an "Invalid memory access" in line 13
Is a bug?
Last edited by
QuimV on Tue Oct 03, 2017 12:10 pm, edited 1 time in total.
QuimV
mk-soft
Always Here
Posts: 5335 Joined: Fri May 12, 2006 6:51 pm
Location: Germany
Post
by mk-soft » Tue Oct 03, 2017 10:37 am
No Bug
1. To use pointer for function
2. To use CallFunctionFast for Procedure and CallCFunctionFast for ProcedureC
Code: Select all
Structure triFunction
Function$
*Function
Map Params.s()
EndStructure
Global triFunction.triFunction
Procedure Test1(*Func.triFunction)
Debug "***************"
Debug "Inside Test1"
Debug *func\Function$
Debug *Func\Params("1")
Debug *Func\Params("2")
Debug "***************"
EndProcedure
Procedure Test2(Param1$)
Debug "***************"
Debug "Inside Test2"
Debug Param1$
Debug "***************"
EndProcedure
Procedure ExecuteAnyFunction (*Func.triFunction)
Protected Param1$
If *Func\Function$ = "Test1(*Func.triFunction)"
CallFunctionFast(*Func\Function, *Func)
ElseIf *Func\Function$ = "Test2(Param1$)"
Param1$ = *Func\Params("1")
CallFunctionFast(*Func\Function, @Param1$)
EndIf
;Result = CallCFunctionFast(*FunctionPointer [,Parameter1 [, Parameter2...]])
EndProcedure
; Configure function 1 structure
triFunction\Function$ = "Test1(*Func.triFunction)"
triFunction\Function = @Test1()
AddMapElement(triFunction\Params(),"1")
triFunction\Params() = "Text Param 1"
AddMapElement(triFunction\Params(),"2")
triFunction\Params() = "Text Param 2"
; Call to execute function Test1
ExecuteAnyFunction(@triFunction)
; Configure function 2 structure
triFunction\Function$ = "Test2(Param1$)"
triFunction\Function = @Test2()
AddMapElement(triFunction\Params(),"1")
triFunction\Params() = "Default Text"
; Call to execute function Test2
ExecuteAnyFunction(@triFunction)
QuimV
Enthusiast
Posts: 337 Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN
Post
by QuimV » Tue Oct 03, 2017 12:12 pm
What a stupid mistake!
Thank you very much @mk-soft
QuimV