Hi Rene,
thank you for really nice visual guideline to your idea
I see you are wondering, why you cannot see "F" after assignment of "0123456789ABCDEF".
AS ASCIIZ * N is meant to contain N-1 specified characters, where Nth one is null character. So the content of .Chars in your example is "0123456789ABCDE" + $NUL. Maybe it could be documented more explicitly.
Do I understand correctly, that this:
Type tMyType
Chars As Asciiz * 16
At Chars Shared( B(16) as Byte )
At Chars Shared( pData as Dword, pName as DWord, Styling As Quad )
At Chars Shared( DoublePointer1 As Quad, Style As Long, ExStyle As Long )
end type
...means:
- overlay BYTE B(16) over Chars memory
- overlay pData, pName, Styling in this sequence over Chars memory
- overlay DoublePointer1, Style , ExStyle in this sequence over Chars memory
?
I understand it, but we can already achieve it like this:
Type tMyCustomTypeA
pData as dword
pName as dword
styling as quad
function ToString() as string
return StrFormat$("{1} {2} {3}", me.pData, me.pName, me.styling)
end function
end type
Type tMyCustomTypeB
DoublePointer1 as quad
Style as long
ExStyle as long
function ToString() as string
return StrFormat$("{1} {2} {3}", me.DoublePointer1, me.Style, me.ExStyle)
end function
end type
union uMyUnion
chars as asciiz * 16
B(16) as byte
myCustomA as tMyCustomTypeA
myCustomB as tMyCustomTypeB
end union
dim var as uMyUnion
var.chars = "01234567890ABCDE"
msgbox 0, var.myCustomA.ToString()
msgbox 0, var.myCustomB.ToString()
I personally do not like UNIONs too much, I prefer DIM .. AT / SetAt - but that is a question of personal preference
Petr
Bookmarks