Results 1 to 4 of 4

Thread: User Defined Types

  1. #1

    User Defined Types


    UDTs support dynamic strings

    [code=thinbasic]



    'USER DEFINED TYPES


    uses "oxygen","file"
    dim src as string


    src = "

    type color32

    r as byte
    g as byte
    b as byte
    a as byte
    lbl as string

    end type

    dim c as color32

    c.r=16
    c.b=16
    c.g=16
    c.a=32
    c.lbl=`Dark: `

    print c.lbl hex c.a

    terminate
    "
    o2_basic src

    'msgbox 0, o2_view "o2h "+src

    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if

    o2_exec


    [/code]

  2. #2

    Re: User Defined Types: Unions


    The equals sign in a UDT causes the element offset counter to be reset. This allows any number of unions to be defined within a type.

    [code=thinbasic]



    'USER DEFINED TYPES
    'UNION

    uses "oxygen","file"
    dim src as string


    src = "

    type color32

    r as byte
    g as byte
    b as byte
    a as byte
    =
    rgba as long 'UNION

    end type

    dim c as color32

    c.r=16
    c.b=16
    c.g=16
    c.a=32

    print hex c.rgba
    print hex c.a

    terminate
    "
    o2_basic src

    'msgbox 0, o2_view "o2h "+src

    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if

    o2_exec

    [/code]

  3. #3

    Re: User Defined Types : Derived



    [code=thinbasic]



    'USER DEFINED TYPES
    'DERIVED TYPES

    uses "oxygen","file"
    dim src as string


    src = "

    type color32

    r as byte
    g as byte
    b as byte
    a as byte
    =
    rgba as long 'UNION

    end type

    '-------------
    'DERIVED TYPE:
    '=============

    type colortext

    c as color32
    txt as string

    end type


    dim t as colortext

    t.c.r=16
    t.c.b=16
    t.c.g=16
    t.c.a=32
    t.txt=`Color code `

    print t.txt hex t.c.rgba

    terminate
    "
    o2_basic src

    'msgbox 0, o2_view "o2h "+src

    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if

    o2_exec

    [/code]

  4. #4

    Re: User Defined Types: Inheritance



    [code=thinbasic]



    'USER DEFINED TYPES
    'INHERITED

    uses "oxygen","file"
    dim src as string


    src = "

    type color32

    r as byte
    g as byte
    b as byte
    a as byte
    =
    rgba as long 'UNION

    end type


    '------------
    'DERIVED TYPE
    '============

    type colortext
    color32,
    txt as string
    end type


    dim t as colortext

    t.r=16
    t.b=16
    t.g=16
    t.a=32
    t.txt=`Color code `

    print t.txt hex t.rgba
    print hex t.c.a

    terminate
    "
    o2_basic src

    'msgbox 0, o2_view "o2h "+src

    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if

    o2_exec


    [/code]

Similar Threads

  1. Article: User defined entities
    By Petr Schreiber in forum vBCms Comments
    Replies: 0
    Last Post: 03-01-2011, 20:52

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •