Nandosta
Member
After copying a structure that has been defined with a user type to another structure of the same type, both structures seem to share the same memory location. Bug or feature?
(B4J version 9.3)
The value change of A.P2 and B.P1 was not expected.
(B4J version 9.3)
Source code:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Type Control_Block(P1 As String, P2 As Int)
Private A As Control_Block
Private B As Control_Block
End Sub
Sub AppStart (Args() As String)
Log("Assign initial values")
A.P1 = "A"
A.P2 = 100
B.P1 = "B"
B.P2 = 200
DMP_Control_Blocks
Log("Copy one user type structure to the other (B = A)")
B = A
DMP_Control_Blocks
Log("Change control block contents (A.P1 = XXX, B.P2 = 999)")
A.P1 = "XXX"
B.P2 = 999
DMP_Control_Blocks
End Sub
Sub DMP_Control_Blocks
Log("> A.P1 = " & A.P1)
Log("> A.P2 = " & A.P2)
Log("> B.P1 = " & B.P1)
Log("> B.P2 = " & B.P2)
End Sub
Log file:
Waiting for debugger to connect...
Program started.
Assign initial values
> A.P1 = A
> A.P2 = 100
> B.P1 = B
> B.P2 = 200
Copy one user type structure to the other (B=A)
> A.P1 = A
> A.P2 = 100
> B.P1 = A
> B.P2 = 100
Change control block contents (A.P1 = XXX, B.P2 = 999)
> A.P1 = XXX
> A.P2 = 999
> B.P1 = XXX
> B.P2 = 999
Program terminated (StartMessageLoop was not called).
The value change of A.P2 and B.P1 was not expected.