a simple method for ByRef in procedure calls (non-strings)
Posted: Sun Nov 03, 2013 6:10 pm
This method modifies the recommended PB technique for ByRef calls, so that two simple macros can be used for all data types.
The problem with PB's built-in structures, such as String and Integer, is that the variable names are the same as the data type. This means that the code in the called procedure requires the data type to be attached to every variable reference. For example:
An alternative is to create your own structures for each of the data types that you use, and create two macros to wrap the parm definition and the variable references.
The problem with PB's built-in structures, such as String and Integer, is that the variable names are the same as the data type. This means that the code in the called procedure requires the data type to be attached to every variable reference. For example:
Code: Select all
Structure String
s.s
EndStructure
Structure Integer
i.i
EndStructure
*VariableName\s = *VariableName\s + ....
*VariableName\i = *VariableName\i + ....
Code: Select all
Macro ByRef (Name, Type)
*Name.ref_#Type
EndMacro
Macro Ref (Name)
; the "x" variable name allows all data types to be handled by the "Ref" macro
*Name\x
EndMacro
Structure ref_i
; the structure variable is named "x" in all data type structures
x.i
EndStructure
;-------
Procedure TestRef(ByRef(Value1, i), Value2.i)
Ref(Value1) = Ref(Value1) + Value2
EndProcedure
Define Value1.i = 55
Define Value2.i = 44
TestRef(@Value1, Value2)
Debug Value1