Roy, the any pointer parameter story as follows. When you create a function
call with an any pointer as a parameter, the block editor creates code in the
background. All parameters to functions are passed as area pointers (4 bytes),
so, as any pointers occupy 10 bytes the parameter passed to the FC will be an area
pointer giving the location of the any pointer. The temp local area is always used
for passing any pointers. In the example code below FC2 has one input parameter of type
anypointer.
Example 1:
Any pointer to Static data area var address=2.0
Static data for this fb starts at 4.0
Here is the code as normally shown by the editor:
Code:
CALL FC 2
pAny:=#StaticVarReal
NOP 0
And now with the hidden code produced by the editor revealed. The any pointer
is contructed by the code starting at L21.0 and then L21.0 is passed as the area pointer
to FC2. Note that in this example even though the data is located in the static data area
of a function block, the code generates the absolute address of the variable within the
instance DB, so the anypointer is actually refering to global data.
Code:
Call
BLD 1
= L 20.0
TAR2 LD 16 //Save ar2 in local data
L W#16#1008 //generate any pointer of type 8=Real
T LW 21
L 1 //number of elements=1
T LW 23
L DINO //get current instance DB
T LW 25
+AR2 P#2.0 //add on address of staticvarReal to give
TAR2 //absolute area pointer of StaticVarReal
LAR2 LD 16 //restore AR2
T LD 27 //ptr address into any area
UC FC 2
P#L 21.0 //any pointer has been contructed starting at L21.0
LAR2 LD 16
BLD 2
End Call
NOP 0
Example 2:
Any pointer to Temp local data var address=2
Here is the normal code
Code:
CALL FC 2
pAny:=#TempVarReal
NOP 0
And now with the hidden code produced by the editor revealed.The any pointer
is contructed by the code starting at L21.0 and then L21.0 is passed as the area pointer
to FC2. TempVarReal exists in local memory at L2.0
Code:
Call
BLD 1
= L 20.0
TAR2 LD 16 //save ar2
L W#16#1008 //generate any pointer of type 8=real
T LW 21
L 1 //number of elements=1
T LW 23
L 0 //DB number=0 for local data
T LW 25
L P#L 2.0 //Area pointer to TempVarReal
T LD 27
UC FC 2
P#L 21.0 //any pointer has been contructed starting at L21.0
LAR2 LD 16
BLD 2
End Call
NOP 0
Example 3:
any pointer to hardcoded area
Normal code
Code:
CALL FC 2
pAny:=P#DB99.DBX 0.0 INT 33
NOP 0
And now with the hidden code produced by the editor revealed. Same story as the previous examples.
Code:
Call
BLD 1
= L 20.0
TAR2 LD 16 //save ar2
L W#16#1005 //generate any pointer of type 5=int
T LW 21
L 33 //number of elements=33
T LW 23
L 99 //DB number=99
T LW 25
L P#DBX 0.0 //area pointer
T LD 27
UC FC 2
P#L 21.0 //any pointer has been contructed starting at L21.0
LAR2 LD 16
BLD 2
End Call
NOP 0
Example 4:
any pointer from temp var of type any at address=6
Normal code
Code:
CALL FC 2
pAny:=#TempVarAny
NOP 0
And now with the hidden code produced by the editor revealed. The editor produces the
following code when you specify a temp variable of type any. The editor has not produced
any code to contruct the any pointer, it just passes the area pointer to the any pointer.
The assumption here is that you, the programmer, have contructed the any pointer yourself
starting at L6.0 before calling the FC. (In this example I have not done so)
Code:
Call
BLD 1
= L 20.0
TAR2 LD 16 //save ar2
UC FC 2
P#L 6.0 //code assumes any pointer has been contructed at L6.0
LAR2 LD 16
BLD 2
End Call
NOP 0
Hope this fills that gap in the weekend !
Regards, Simon