Navigation: thinBasic language > Data types and variables > TYPE |
|
Description
Define a User-Defined Data Type (UDT), containing one or more member elements.
Syntax
TYPE MyType [BYTE | WORD | DWORD]
[MemberName AS TypeName]
[MemberArrayName[(nElements)] AS TypeName]
[...]
END TYPE
Returns
None
Member alignment
TYPE definitions may optionally specify an alignment of BYTE (the default), WORD, DWORD
• | BYTE: each member will be aligned on a BYTE boundary - no padding or alignment is applied to the structure. This is the default alignment method. |
• | WORD: each member will be aligned on a WORD boundary. Any odd byte between members of TYPE will be automatically skipped and ignored. The UDT structure is also padded with one trailing byte to ensure the total structure size is a multiple of 2 bytes. |
• | DWORD: each member will be aligned on a DWORD boundary. Up to three bytes will be skipped to accomplish this alignment. The UDT structure is also padded with up to three trailing bytes to ensure the total structure size is a multiple of 4 bytes. |
Remarks
thinBasic support any level of nesting types.
Elements inside a type can be:
• | numeric (any supported type) |
• | string (fixed or dynamic strings) |
• | variants |
• | another type (allowing nesting types inside another one) |
• | union |
To indicate a fixed string as UDT element use the following notation:
'...
DynStr As String * StringSizeInBytes
'...
To indicate a dynamic string as UDT element use the following notation:
'...
DynStr As String
'...
A dynamic string is represented inside an UDT as 32bit number so it will occupy only 4 bytes regardless of its size.
thinBasic will take care of memory allocation and de-allocation of dynamic strings.
A VARIANT element will always occupy 16 bytes.
Restrictions
See also
Examples
'---
Type MyRect
x As Long
y As Long
w As Long
h As Long
End Type
'---
Type MyData
Val1 As Integer
Val2 As Long
Val3 As String * 255
dynStr As String PTR '---Dynamic string
Val4 As EXT
Re As MyRect '---Note, a type inside a type
Val5 As QUAD
Val7 As Double
End Type
Dim Info As MyData
Info.Val1 = 10
Info.Re.x = 20
MSGBOX 0, Info.Val1 & "-" & Info.Re.x
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |