Define variable type

Syntax

type typename members

 

Members can be in the same line or/and in multiple lines (use tabs):

 

type typename
	member1
	member2
	...

 

Instead of the type keyword, you can use class or category.

 

Parts

typename - name of new type.

members - list of members. Syntax of member definition: [membertype]membername . For members of type int, membertype can be omitted. Note that spaces cannot be used between membertype and membername. Instead use ' (if not pointer) or * (if pointer), or nothing (if type character or ARRAY).

globals - list of global identifiers.

 

Remarks

QM has 7 intrinsic variable types - int, byte, word, long, double, lpstr and str. It also defines 7 OLE types and several other types. You can combine variables of several different types to create user-defined types (also known as structures or records). User-defined types are useful when you want to create a single variable that contains several related pieces of information . You create a user-defined type with the type statement. Once you have new type defined, you can create variables of that type (typename) like variables of intrinsic types. The type definition exists until QM exits or other file is opened.

 

An user-defined type can contain member variables of any type, including other user-defined types.

 

An user-defined type can contain embedded single-dimension arrays. The number of elements must be enclosed in square brackets and immediately follow member name: [membertype]membername[numelem]. Embedded strings (not lpstr or str) must be declared as byte array. Such array cannot be used directly as lpstr or pointer. Instead, use & operator to get address of array, and assign it to a lpstr or pointer variable. Example: lpstr s = &structure.array. Array name, when used without [], means first element.

 

It is possible to specify member offsets, and define anonymous types within types. It can be used to define unions or types with nonstandard member alignment.

 

It is possible to use a base type (inheritance).

 

It is possible to add global identifiers. Usually it is used to define a category. The syntax is:

 

type typename [members] [: globals]

 

User-defined types also can be defined in reference files and type libraries, which allows you to use them without defining explicitly. Many declarations are in WINAPI and WINAPIV reference files. Usage example:

 

WINAPI.PARAFORMAT p

 

Some Windows types are defined by default. Some of them are defined by QM, others in the System\Declarations folder.

 

Some Windows types actually are not user-defined types, but rather aliases of other types or of pointers to other types. For example, instead of various handle types (HWND, HANDLE, HMODULE, HICON, etc), in QM is used int. Instead of various pointer types (usually LPTYPENAME), use TYPENAME*. Instead of string types (LPSTR, etc), use lpstr.

 

QM 2.3.0. Allowed comments. See example. Also can contain lines containing only comments, but the comments must always begin with ;;.

 

See also: usage unions classes categories declarations scope

 

Examples

type RECT left top right bottom
type PAINTSTRUCT hdc fErase RECT'rcPaint fRestore fIncUpd !r[32]
type MY @w !b ~s i[4] ~*sp RECT*rp[10]
type MY2 word'w byte'b str's int'i[4] str*sp RECT*rp[10]
type MY3 ;;the same as above, but in multiple lines
	word'w byte'b str's ;;the same as @w !b ~s
	int'i[4] ;;embedded array
	str*sp ;;pointer
	RECT*rp[10] ;;embedded array (10 pointers)
type ARR2 ARRAY(str)a ARRAY(int)b