Normally, "SizeOf" gives the defined length of the fixed string, and "Len" gives the length based on any null characters that might be embedded in the string.
The following example shows how this works:
Code: Select all
Structure udtAbc
xFixed.s{8}
EndStructure
Procedure subProcName(*uAbc.udtAbc)
*uAbc\xFixed = LSet("", SizeOf(*uAbc\xFixed), "x")
EndProcedure
Define uAbc.udtAbc
uAbc\xFixed = "1234"
Debug uAbc\xFixed
Debug "Len = " + Len(uAbc\xFixed)
Debug "SizeOf = " + SizeOf(uAbc\xFixed)
subProcName(uAbc)
Debug uAbc\xFixed
Code: Select all
Structure udtAbc
xFixed.s{8}
EndStructure
Structure strMain
uAbc.udtAbc
EndStructure
Procedure subProcName(*rMain.strMain)
*rMain\uAbc\xFixed = LSet("", Len(*rMain\uAbc\xFixed), "x")
; *rMain\uAbc\xFixed = LSet("", SizeOf(*rMain\uAbc\xFixed), "x") ; <--- SizeOf creates a syntax error
EndProcedure
Define rMain.strMain
rMain\uAbc\xFixed = "1234"
Debug rMain\uAbc\xFixed
Debug "Len = " + Len(rMain\uAbc\xFixed)
;Debug "SizeOf = " + SizeOf(rMain\uAbc\xFixed) ; <--- SizeOf creates a syntax error
subProcName(rMain)
Debug rMain\uAbc\xFixed
Debug "Len = " + Len(rMain\uAbc\xFixed)
;Debug "SizeOf = " + SizeOf(rMain\uAbc\xFixed) ; <--- SizeOf creates a syntax error
Any opinions on whether this is a compiler bug or just a perverse "feature"?
By the way, the following example works. But it uses SizeOf with the structure definition, rather than with the variable definition that works in the first example and which fails in the second example. However, it's not very useful and not as easy to use as passing length parameters.
Code: Select all
Structure udtAbc
xFixed.s{8}
EndStructure
Structure strMain
uAbc.udtAbc
EndStructure
Procedure subProcName(*rMain.strMain)
*rMain\uAbc\xFixed = LSet("", SizeOf(udtAbc\xFixed), "x")
EndProcedure
Define rMain.strMain
rMain\uAbc\xFixed = "1234"
Debug rMain\uAbc\xFixed
Debug "Len = " + Len(rMain\uAbc\xFixed)
Debug "SizeOf = " + SizeOf(udtAbc\xFixed)
subProcName(rMain)
Debug rMain\uAbc\xFixed
Debug "Len = " + Len(rMain\uAbc\xFixed)
Debug "SizeOf = " + SizeOf(udtAbc\xFixed)