PDA

View Full Version : Dim Byref



Charles Pegge
17-06-2009, 17:41
You can create a variable byref then give it whatever address you choose.

dim byref a
&a= ...




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

Charles Pegge
22-07-2009, 12:27
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 :D
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



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