[futurebasic] Re: [FB] [FB2] XREF Array of Records (lengthy)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: David Cottrell <David.Cottrell@...>
Date: Wed, 20 Oct 1999 11:09:35 +1000
Its a bit hard without FN Mung&.

I dont think there is any need to lock the handle here (but it cant hurt?)

The point of XREF@ is that you can use the handle like it was a normal
array of records.

ie.
studentId%.studentInfo(3) = 1111
studentName$.studentInfo(3) = "some name"

I'm not sure that adding the length info into the handle is a good idea - I
would keep these seperate. My guess is that this is your problem.

Think array of records - you just have to do the memory allocation yourself.

I usually get a function like this working as a global array, and then add
the XREF stuff (much easier to debug this way).

HTH

David

Here are the functions I use in a program which tracks and records movement
of the cursor.


DIM RECORD positionData'record
	DIM xPos	'horizontal axis position
	DIM yPos	'vertical axis position
	DIM timelog&	'time in microseconds
DIM END RECORD .positionData

_bazillion      = 1000000	'max of 1000s at 1000s/s

DIM gDataArray&;0,gDataHndl&	'use data handle (nice trick)
XREF@ gDataArray.positionData (_bazillion)	'does not alocate memory

end globals

'=========================================
'this function grabs a chunk of memory for an array
'this is used for a growable global array (I think)
LOCAL FN setUpDataArray (noPoints,ptSize)
memReq&       = (noPoints+1) * ptSize'calculate memory required
memAvail&     = SYSTEM(_memAvail)'get available memory
LONG IF memReq& < memAvail&'check that there is enough memory
myHndl&     = FN NEWHANDLE _clear (memReq&)'create new handle
gHndlSize&  = memReq&'store the current handle size
XELSE'if not enough memory
FN pGshowErr(16)
END IF
END FN = myHndl&
'=========================================

'=========================================
LOCAL FN shrinkArray (theHndl&,theSize&)
LONG IF theHndl& <> _nil
osErr% = FN SETHANDLESIZE (theHndl&,theSize&)'adjust memory block
LONG IF osErr%'check memory
FN pGshowErr(14)'Error shinking array
END IF
END IF
END FN = osErr%
'=========================================

'=========================================
LOCAL FN trackResponse
LONG IF gWhichClass = _responseWnd'mouse click in target window (could be a
problem!)
LONG IF gStartTime&
lastLogTime& = FN MicroSeconds&
LONG IF gTrackResponse = _checked
CALL PENSIZE (1,1)'set pensize
CURSOR _pencilCursor'change cursor to pencil
CALL MOVETO (gMouseX,gMouseY)'get mouse location and move pencil there
END IF

'record first data point after mouse click
gDataArray.xPos (gsampleCount&)         = gMouseX'horizontal co ord
gDataArray.yPos (gsampleCount&)         = gMouseY'vertical coord
gDataArray.timelog& (gsampleCount&)     = lastLogTime& - gStartTime&'time
of mouse click
gLineStart& = gsampleCount&'this is for delayed response tracking
gDataSize& = gDataSize& + _positionData
gsampleCount& = gsampleCount& + 1

DO
CALL GETMOUSE (gMouseY)'get current location
currTime& = FN MicroSeconds&
LONG IF currTime& > lastLogTime& + (1000000 / gSampleRate)
lastLogTime& = currTime&

LONG IF gHndlSize& < gDataSize& + (2 * _positionData)'check that memory
available for next 2 data points
'do this so there is always room in case pen lifted
oldSize& = gHndlSize&
newSize& = oldSize& + (gSampleRate *_positionData)'grab memory for another
second of recording
osErr% = FN SETHANDLESIZE _clear (gDataHndl&, newSize&)'adjust memory block
LONG IF SYSERROR = _memFullErr'check memory
FN pGshowErr(16)
XELSE
gHndlSize& = newSize&
END IF
END IF

LONG IF SYSERROR = _memFullErr
FN pGshowErr(16)
STOP'skip over this!!!
XELSE
gDataArray.xPos(gsampleCount&)      = gMouseX'horizontal co ord
gDataArray.yPos (gsampleCount&)     = gMouseY'vertical coord
gDataArray.timelog& (gsampleCount&) = currTime& - gStartTime&'time
gDataSize& = gDataSize& + _positionData
gsampleCount& = gsampleCount& + 1
END IF

END IF
LONG IF gTrackResponse = _checked
CALL LINETO (gMouseX,gMouseY)'draw
END IF
UNTIL FN STILLDOWN = _False'button lifted

'record a marker that the pen was lifted
gDataArray.xPos (gsampleCount&)         = 0'horizontal co ord
gDataArray.yPos (gsampleCount&)         = 0'vertical coord
gDataArray.timelog& (gsampleCount&)     = 0'time of mouse click
gDataSize& = gDataSize& + _positionData
gsampleCount& = gsampleCount& + 1

LONG IF gTrackResponse = _checked
CURSOR _Arrowcursor'restore to arrow cursor
FN saveWindowG (_responseWnd,_respWndOS)'save window to gWorld for updates
XELSE
FN drawLine'draw line now
END IF
gDataDirty = _True'data needs to be saved
END IF
END IF
END FN
'=========================================