
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM |
FB II COMPILER
Use arrays of memory addresses
To put the address of a variable var1% in another variable, call it arrayVar&(i,j) do this :
arrayVar&(i,j) = @var1%
Note that arrayVar& has to be a "long" - & - to hold an address. The "@" means "the address of".
To do something _with_ the variable var1%, given the address;
temp% = {arrayVar&(i,j)} ' this is the same as saying temp% = var1%
The {} means "PEEK WORD", or "give me the integer (%) value stored at the address between these braces". If you're dealing with resource numbers, integers are big enough; but if you are dealing with long integers, var1&'s, then you need "PEEK LONG" instead, which is [].
To "swap" which variable is contained in arrayVar&(i,j), you'd just put the address of the other variable in there :
arrayVar&(i,j) = @var2%
Y To swap the _contents_ of the variable etc... just change var1%.
Here's a concrete example with real code:
DIM var1%
DIM arrayVar&(1,1)
END GLOBALS
WINDOW 1,"test",(0,0)-(500,300),_docNoGrow
TEXT _courier,12
var1% = 10
arrayVar&(1,1) = @var1%
PRINT "This is the address of var1%:";arrayVar&(1,1)
PRINT "This is what's in var1%:";{arrayVar&(1,1)}
var1% = 20
PRINT "This is what's in var1% now:";{arrayVar&(1,1)}
DO
HANDLEEVENTS
UNTIL MOUSE(_down)
END
|