Here's a system for giving windows access to arrays (Based on OTYAX):
Because SB doesn't let you create an array of arrays, the next best thing is to make a bunch of global arrays, and access them with VAR("name")
When the window is created, you use VARS_ARRAY_ALLOC to request an array.
The array ID number is stored in VARS_NUM, so you can access it later with VARS_ARRAY
'Put this code in __APMN, after DIM VARS_STR$ or something
DIM A_USED[256] 'this keeps track of which window is using each array (-1 = unused)
FILL A_USED,-1
DIM A_FREE[0] 'empty array
IF FALSE THEN DIM _A_0[0],_A_1[0],_A_2[0],_A_3[0],_A_4[0],_A_5[0],_A_6[0],_A_7[0],...,_A_FF[0]
'Code to generate that really long DIM list:
'FOR I=0 TO 255
' S$=S$+"_A_"+HEX$(I)+"[0],"
'NEXT
'CLIPBOARD S$
'Request an array to use.
'WID: window ID
'VNUM: VARS_NUM index to use
'ARRAY: array
'Returns 1 if it succeeded, or 0 if it failed (ran out of arrays)
DEF VARS_ARRAY_ALLOC(WID,VNUM,ARRAY)
VAR I
FOR I=0 TO LEN(_A_USED)-1
IF _A_USED[I]==-1 THEN
_A_USED[I]=WID
VARS_NUM[WID,VNUM]=I
VARS_ARRAY_SET WID,VNUM,ARRAY
RETURN TRUE
ENDIF
NEXT
VARS_NUM[WID,VNUM]=-1
RETURN FALSE
END
DEF VARS_ARRAY_SET WID,VNUM,ARRAY
VAR("_A_"+HEX$(VARS_NUM[WID,VNUM]))=ARRAY
END
DEF VARS_ARRAY(WID,VNUM)
RETURN VAR("_A_"+HEX(VARS_NUM[WID,VNUM]))
END
'put this at the end of DEF APP_WINDOW_DESTROY
FOR J=0 TO LEN(_A_USED)-1
IF _A_USED[J]==I THEN
VAR("_A_"+HEX$(J))=_A_FREE
_A_USED[J]=-1
ENDIF
NEXT
'examples:
'allocating an array (usually inside `IF ON_OPEN(WND) THEN...`)
'uses VARS_NUM[WID,45]
DIM NEW$[10,23]
IF !VARS_ARRAY_ALLOC(WID,45,NEW$) THEN APP_WINDOW_DESTROY WND:RETURN
'(close the window if there weren't any arrays available)
'accessing the array
IF FALSE THEN DIM ARRAY$[0]
ARRAY$=VARS_ARRAY(WID,45)
ARRAY$[0,7]="HELLO"
PRINT ARRAY$[4,5]
Note: IF FALSE THEN DIM... is used to create array variables without actaully creating the arrays (this is faster and uses less memory)