Results 1 to 2 of 2

Thread: Dim Byref

  1. #1

    Dim Byref

    You can create a variable byref then give it whatever address you choose.

    dim byref a
    &a= ...



    [code=thinbasic]
    uses "oxygen"

    '-----------------------
    'DIM BYREF
    '=======================

    'and assigning an address to a byref variable


    dim src as string

    src = "
    #o2h
    #indexbase 0
    '
    dim d(1000)
    d(10)=42
    '
    '-----
    'BYREF
    '=====
    '
    dim byref a
    &a=&d + 10 * sizeof d
    print str a
    '
    '----------
    'POINTERING
    '==========
    '
    dim pb
    dim b at pb
    pb=&d + 10 * sizeof d
    print str b

    "



    o2_basic src
    if len(o2_error) then msgbox 0, o2_error() : stop
    o2_exec
    [/code]

  2. #2

    Byref, Pointers, Dynamic Objects - mind bending :)

    This code illustrates 9 different ways to create a dynamic object mapped to a dynamic string.

    Most of these you would not want to use in practice
    But they show how addresses and pointers and byref work together.

    In Oxygen, unlike C, addresses and pointers themselves are all treated as long.

    Charles

    [code=thinbasic]
    uses "oxygen"
    dim src as string

    '-----------------------------
    'DYNAMIC OBJECTS
    '(also testing string boolean)
    '=============================

    src ="
    #basic

    '-------
    class ts
    '=======

    sa as string

    '----------------------
    method set(s as string)
    '======================
    sa=s
    end method

    '--------------
    method boolit()
    '==============
    if sa then print `True` else print `False`
    end method boolit

    end class ts


    dim as string s=nuls 100

    '
    '-----------------------------------------------------------------------
    'THESE DIMS ARE ALL CREATE A DYNAMIC OBJECT MAPPED INTO DYNAMIC STRING S
    '=======================================================================
    '
    ' & address of
    ' ? long value at
    ' * long value at pointer at
    ' ** long value at pointer pointer at
    '
    '------------------------------------
    'dim po=&s : dim as ts o at **po
    'dim po=?s : dim as ts o at *po
    'dim po=*s : dim as ts o at po
    'dim po=**s : dim as ts o at &po
    '------------------------------------
    'dim po=&s : dim as ts byref o at *po
    'dim po=?s : dim as ts byref o at po
    'dim po=*s : dim as ts byref o at &po
    '------------------------------------
    'dim as ts byref o at s
    dim as ts o at *s
    '------------------------------------

    'o.set ``
    'o.set ` `
    o.set `x`
    o.boolit

    "

    'msgbox 0,o2_prep src
    o2_basic src
    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if
    o2_exec


    [/code]

Similar Threads

  1. byref or not byref that is the question.
    By Michael Clease in forum Module SDK (Power Basic version)
    Replies: 2
    Last Post: 04-11-2010, 02:55

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
  •