Rapid-Q Documentation by William Yu (c)1999 Appendix C: User Defined Types


Introduction to UDTs

User defined types (or UDTs) are structures that you can use in most BASIC languages, Rapid-Q is no exception.

Using TYPE
Here's an example of a user defined type:
    TYPE TWorld
        CityName(100) AS STRING
        Population(100) AS LONG
    END TYPE

    DIM World AS TWorld
As you can see, you can have arrays within UDTs. You can also create arrays of UDTs:
    TYPE TWorld
        CityName(100) AS STRING
        Population(100) AS LONG
    END TYPE

    DIM Country(100) AS TWorld
There is currently an issue with the memory address of your array (within UDT). Please note that this is hardly ever noticed unless you're going to pass one of these structures to a DLL that require arrays within UDTs. This address problem won't affect your program, but it's hard to explain (without getting too deep). NOTE: it only occurs when you create arrays of UDTs that have arrays within UDTs. In the first example (higher up), there is no address problem since you're not creating an array of UDTs. You can safely pass that to a DLL.

Copying UDTs
To copy 2 UDTs, just assign the two:
    TYPE TStuff
        A AS LONG
        B AS INTEGER
    END TYPE

    DIM S1 AS TStuff
    DIM S2 AS TStuff

    S1 = S2
Содержание in S2 are copied to S1. When dealing with arrays within UDTs, the arrays are not copied, only referenced. To copy arrays of UDTs, you'll have to manually copy each one:
    DIM S1(100) AS TStuff
    DIM S2(100) AS TStuff

    FOR I = 1 TO 100
        S1(I) = S2(I)
    NEXT


Unhooking TYPE
There are actually 2 ways to create your types, with TYPE and STRUCT. STRUCT is actually mirrored in TYPE, to unhook the two, you have to undefine TYPE.
    $UNDEF TYPE

    TYPE TWorld
        CityName(100) AS STRING
        Population(100) AS LONG
    END TYPE

    DIM World AS TWorld
Using TYPE and STRUCT are not the same. If you unhook the two, TYPE now reverts back to the old style (pre-May 17 version), where arrays of UDTs is not allowed. Why the heck would I want a stripped down version? Well, perhaps performance. The old style TYPE lacks in many things, but makes up in performance, if that's really necessary.


<- Branching Содержание Conditions ->