' Polymorphic types: type discriminator + variant record
#COMPILE EXE
#DIM ALL

TYPE MyVariant
    dtype AS LONG
    intVal AS LONG
    dblVal AS DOUBLE
    strVal AS STRING
    boolVal AS LONG
END TYPE

FUNCTION PBMAIN() AS LONG
    LOCAL v1 AS MyVariant
    LOCAL v2 AS MyVariant
    LOCAL v3 AS MyVariant
    LOCAL v4 AS MyVariant
    LOCAL s AS STRING
    LOCAL dt AS LONG
    LOCAL iv AS LONG
    LOCAL bv AS LONG

    PRINT "Polymorphic Types (Variant Records)"
    PRINT ""

    v1.dtype = 1
    v1.intVal = 42
    v2.dtype = 2
    v2.dblVal = 3.14159
    v3.dtype = 3
    v3.strVal = "Hello Variant!"
    v4.dtype = 4
    v4.boolVal = 1

    IF v1.dtype = 1 THEN PRINT "v1 = " + STR$(v1.intVal)
    IF v2.dtype = 2 THEN PRINT "v2 = " + STR$(v2.dblVal)
    IF v3.dtype = 3 THEN PRINT "v3 = " + v3.strVal
    IF v4.dtype = 4 THEN PRINT "v4 = " + STR$(v4.boolVal)

    PRINT "Done."
    FUNCTION = 0
END FUNCTION
