ReneMiner
17-09-2015, 12:15
we all know the case when a function has to return some value :D
The memory for that value is already allocated somewhere when we write
Function myFun() As <Result>
' where <Result> is the type of the functions return-value
' data as <Result> gets assigned within the function alike:
Function = 1
' but how can it be used within the function?
if Function = 1 Then
' this will work only because "Function" is followed by an equal-sign here
Endif
Function = Function + 1 ' this won't work... :(
End Function
it's not possible to request/use the current functions return-value in other cases, so we have to store it to some other local variable for further calculations, which is a waste of time & memory since the value is already present and stored somewhere.
If we knew the current functions return-values memory-position ("Function_ResultPtr") we could use a layover and alter single subelements if the function-result-type where an udt or if we had a built-in Function that tells us the current Function_ReturnValue then we could use it for further calculations without having to create an additional local variable...
Function myFun1() As t_XY
Local RetVal As t_XY At Function_ResultPtr
RetVal.X = 1
RetVal.Y = 234
End Function
Function myFun2() As String
Function = "Hello "
Function = Function_ReturnValue & "world!"
End Function
Function myFun3() As Long
Poke(Long, Function_ResultPtr, 123)
Function = Function_ReturnValue * 456
End Function
The memory for that value is already allocated somewhere when we write
Function myFun() As <Result>
' where <Result> is the type of the functions return-value
' data as <Result> gets assigned within the function alike:
Function = 1
' but how can it be used within the function?
if Function = 1 Then
' this will work only because "Function" is followed by an equal-sign here
Endif
Function = Function + 1 ' this won't work... :(
End Function
it's not possible to request/use the current functions return-value in other cases, so we have to store it to some other local variable for further calculations, which is a waste of time & memory since the value is already present and stored somewhere.
If we knew the current functions return-values memory-position ("Function_ResultPtr") we could use a layover and alter single subelements if the function-result-type where an udt or if we had a built-in Function that tells us the current Function_ReturnValue then we could use it for further calculations without having to create an additional local variable...
Function myFun1() As t_XY
Local RetVal As t_XY At Function_ResultPtr
RetVal.X = 1
RetVal.Y = 234
End Function
Function myFun2() As String
Function = "Hello "
Function = Function_ReturnValue & "world!"
End Function
Function myFun3() As Long
Poke(Long, Function_ResultPtr, 123)
Function = Function_ReturnValue * 456
End Function