ReneMiner
19-04-2020, 02:58
just try- it will not break anything
uses "console"
$Sep = crlf & repeat$(20, "==-==") & crlf & crlf
printl repeat$(3, crlf) & " I am testing to find out if" in %CCOLOR_FINTENSEWHITE
printl crlf & repeat$(5, $Tab) & "Type can extend Union?" in %CCOLOR_FLIGHTBLUE
printl repeat$(3, crlf)
printl " Now i will create a UNION and a TYPE"
printl $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl crlf & crlf
union Bytes16
Chars As asciiz * 16
B(16) as Byte
P(4) as DWord
Q(2) as quad
end union
printl " Union Bytes16" & crlf & " Chars As asciiz * 16" & crlf & " B(16) as Byte" &
crlf & " P(4) as DWord" & crlf & " Q(2) as quad" & crlf & " End Union" in %ccolor_fintensewhite
printl crlf & crlf
printl " Union created that occupies 16 Bytes"
Printl " it can be 16 chars or bytes, 4 Dword or 2 Quad"
printl $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
printl "Now i create " & repeat$(3, crlf)
printl $TAB & $TAb & " Type tTest Extends Bytes16" & crlf In %CCOLOR_FLIGHTGREEN
Type tTest extends Bytes16
function _Create(byval data as string)
if lenf(data) > 16 then
data = left$(data, 16)
else
while lenf(data) < 16
data &= $spc
Wend
EndIf
printl "content of data inside _Create() before storage:"
printl ">>>" & data & "<<<" in %ccolor_flightred
me.Chars=data
end function
function Text$() as string
function = memory_Get(Varptr(Me), 16)
end function
function GetByte(byval Index as Long) as Byte
function = me.B(Index)
end function
function GetDword(byval Index as Long) as dword
function = me.p(index)
end function
function GetQuad(byval Index as Long) as Quad
function = me.q(Index)
end function
end type
printl "I defined an udt that extends Bytes16. No additional subelements"
printl "that would occupy any memory but only functions to test it"
printl crlf & "lets see if the subelements of the union are valid" in %ccolor_flightCyan
printl crlf & $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
dim myUDT as tTest("0123456789ABCDEF")
printl "Dim myUDT as tTest('0123456789ABCDEF') ... done"
printl "i dimensioned a variable of the udt and assigned 16 hex-digits from 0 to F"
printl "by using the _Create-feature." & crlf & "Now check if that was successful:"
printl crlf & $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
print crlf & "the output: >>>" in %ccolor_flightblue
print myUDT.Text$ in %CCOLOR_FINTENSEWHITE
printl "<<<" in %ccolor_flightblue
printl crlf & $Tab & " returned length is 16 bytes but the 'F' is missing" in %ccolor_flightred
printl repeat$(4, crlf) & "ok, then lets have a look at the other unions names..."
printl crlf & $sep & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
long i
printl $sep & "as Quads:" in %ccolor_flightcyan
printl
printl "1= " & tstr$(myUDT.GetQuad(1)) & " 2= " & tstr$(myUDT.GetQuad(2))
printl $sep & "as Dwords:" in %ccolor_flightcyan
printl "1= " & tstr$(myUDT.GetDword(1)) & $tab & " 2= " & tstr$(myUDT.GetDword(2)) & " 3= " & tstr$(myUDT.GetDword(3)) & $tab & " 4= " & tstr$(myUDT.GetDword(4))
printl $sep & "as Bytes:" in %ccolor_flightcyan
for i = 1 to 15 step 4
printl tstr$(i) & "= " & tstr$(myUDT.GetByte(i)) & $Tab & $spc & tstr$(i+1) & "= " & tstr$(myUDT.GetByte(i+1)) & $Tab & $spc &
tstr$(i+2) & "= " & tstr$(myUDT.GetByte(i+2)) & $Tab & $spc & tstr$(i+3) & "= " & tstr$(myUDT.GetByte(i+3))
next
printl $sep in %CCOLOR_FYELLOW
printl "Obviously the udt only accepts the unions subsets names" in %ccolor_flightGreen
printl "else it would raise an Error for invalid subelement-names," in %ccolor_Flightred
printl "but it does not unite the elements that they would share the memory."
printl $sep & crlf & crlf & "...any key to read a suggestion" in %CCOLOR_FYELLOW
waitkey
$Suggest = crlf & rawtext
I would prefer the union within a type as this and to seperate
alternative ways of dividing with something as "[OR] AT" and also
to share the memory using different names and types alike
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
end rawtext
printl crlf & $Suggest & crlf
printl $sep & "...any key to end" in %CCOLOR_FYELLOW
waitkey
' try exchange in this script :
'1 * "Extends Bytes16" --> "\n Data as Bytes16"
'4 * "me." --> "me.Bytes16."
uses "console"
$Sep = crlf & repeat$(20, "==-==") & crlf & crlf
printl repeat$(3, crlf) & " I am testing to find out if" in %CCOLOR_FINTENSEWHITE
printl crlf & repeat$(5, $Tab) & "Type can extend Union?" in %CCOLOR_FLIGHTBLUE
printl repeat$(3, crlf)
printl " Now i will create a UNION and a TYPE"
printl $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl crlf & crlf
union Bytes16
Chars As asciiz * 16
B(16) as Byte
P(4) as DWord
Q(2) as quad
end union
printl " Union Bytes16" & crlf & " Chars As asciiz * 16" & crlf & " B(16) as Byte" &
crlf & " P(4) as DWord" & crlf & " Q(2) as quad" & crlf & " End Union" in %ccolor_fintensewhite
printl crlf & crlf
printl " Union created that occupies 16 Bytes"
Printl " it can be 16 chars or bytes, 4 Dword or 2 Quad"
printl $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
printl "Now i create " & repeat$(3, crlf)
printl $TAB & $TAb & " Type tTest Extends Bytes16" & crlf In %CCOLOR_FLIGHTGREEN
Type tTest extends Bytes16
function _Create(byval data as string)
if lenf(data) > 16 then
data = left$(data, 16)
else
while lenf(data) < 16
data &= $spc
Wend
EndIf
printl "content of data inside _Create() before storage:"
printl ">>>" & data & "<<<" in %ccolor_flightred
me.Chars=data
end function
function Text$() as string
function = memory_Get(Varptr(Me), 16)
end function
function GetByte(byval Index as Long) as Byte
function = me.B(Index)
end function
function GetDword(byval Index as Long) as dword
function = me.p(index)
end function
function GetQuad(byval Index as Long) as Quad
function = me.q(Index)
end function
end type
printl "I defined an udt that extends Bytes16. No additional subelements"
printl "that would occupy any memory but only functions to test it"
printl crlf & "lets see if the subelements of the union are valid" in %ccolor_flightCyan
printl crlf & $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
dim myUDT as tTest("0123456789ABCDEF")
printl "Dim myUDT as tTest('0123456789ABCDEF') ... done"
printl "i dimensioned a variable of the udt and assigned 16 hex-digits from 0 to F"
printl "by using the _Create-feature." & crlf & "Now check if that was successful:"
printl crlf & $sep & crlf & crlf & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
print crlf & "the output: >>>" in %ccolor_flightblue
print myUDT.Text$ in %CCOLOR_FINTENSEWHITE
printl "<<<" in %ccolor_flightblue
printl crlf & $Tab & " returned length is 16 bytes but the 'F' is missing" in %ccolor_flightred
printl repeat$(4, crlf) & "ok, then lets have a look at the other unions names..."
printl crlf & $sep & "...any key to continue..." in %CCOLOR_FYELLOW
waitkey
printl
long i
printl $sep & "as Quads:" in %ccolor_flightcyan
printl
printl "1= " & tstr$(myUDT.GetQuad(1)) & " 2= " & tstr$(myUDT.GetQuad(2))
printl $sep & "as Dwords:" in %ccolor_flightcyan
printl "1= " & tstr$(myUDT.GetDword(1)) & $tab & " 2= " & tstr$(myUDT.GetDword(2)) & " 3= " & tstr$(myUDT.GetDword(3)) & $tab & " 4= " & tstr$(myUDT.GetDword(4))
printl $sep & "as Bytes:" in %ccolor_flightcyan
for i = 1 to 15 step 4
printl tstr$(i) & "= " & tstr$(myUDT.GetByte(i)) & $Tab & $spc & tstr$(i+1) & "= " & tstr$(myUDT.GetByte(i+1)) & $Tab & $spc &
tstr$(i+2) & "= " & tstr$(myUDT.GetByte(i+2)) & $Tab & $spc & tstr$(i+3) & "= " & tstr$(myUDT.GetByte(i+3))
next
printl $sep in %CCOLOR_FYELLOW
printl "Obviously the udt only accepts the unions subsets names" in %ccolor_flightGreen
printl "else it would raise an Error for invalid subelement-names," in %ccolor_Flightred
printl "but it does not unite the elements that they would share the memory."
printl $sep & crlf & crlf & "...any key to read a suggestion" in %CCOLOR_FYELLOW
waitkey
$Suggest = crlf & rawtext
I would prefer the union within a type as this and to seperate
alternative ways of dividing with something as "[OR] AT" and also
to share the memory using different names and types alike
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
end rawtext
printl crlf & $Suggest & crlf
printl $sep & "...any key to end" in %CCOLOR_FYELLOW
waitkey
' try exchange in this script :
'1 * "Extends Bytes16" --> "\n Data as Bytes16"
'4 * "me." --> "me.Bytes16."