[futurebasic] [FB] Note storage examples by Jay

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2004 : Group Archive : Group : All Groups

From: Brian Stevens <brilor@...>
Date: Thu, 29 Jul 2004 18:35:24 -0700
The recent list discussion of strings with Jay and his offer to share 
his INDEX$ routines offlist prompted a tangential but related offlist 
discussion between the two of us. As most of you know,  INDEX$ is 
limited to manipulating pascal strings (i.e. 255 characters maximum), 
so I was looking for an approach using handles/pointers with maybe a 
strong nudge and a code snippet to guide me. Instead, Jay, generous and 
prolific coder that he is, sent me several FNs that do the basic 
maintenance (i.e. get the data, store the data, kill the data) using 
handles. The FNs are not meant to be comprehensive or all-inclusive but 
are clearly sound examples that all of us can understand and build on. 
Below, please find Jay's introductory comments and, with Jay's 
permission, the code following.  Please note the warning about being 
untested.

Thanks again Jay!   Brian


"Below is a selection of small Fns that should allow you to do every 
thing you need using handles. It presumes an edit field #_noteField, 
and that you can manage file things to read and write the array where 
you want it. None of these have been tested, so there are bound to be 
some bugs, but they should be pretty easy to find and fix. Let me know 
if something is unclear."----Jay.

'=======================
begin globals
dynamic noteH&(_maxLong) ' Array of ZTXT handles
end globals

local fn newNoteIndex
' Find first unused noteH
dim index&
index = 1' Leave 0 empty for No Note
while noteH(index) ' Search for first zero entry
index ++
wend
end fn = index

local fn storeNote(index&)
dim note&
' Saves handle from edit field _noteField into noteH(index)
' If index <= 0, chooses and returns new index
' if EF is empty, clears noteH(index) and returns 0
if index < 0 then index = fn newNoteIndex
def disposeH(noteH(index))' Discard old handle
get field note, _noteField ' Get new ZTXT handle
long if fn gethandlesize(note)' See if any text
noteH(index) = note ' Put note into array
xelse' No text...
index = 0 ' Return _NIL
end if
end fn = index

local fn clearNotes
' Dispose of all handles in noteH array
dim count&
count = [@noteH + _autoXREFCurr]
while count
count --
def disposeh(noteH(count))
wend
& @noteH + _autoXREFCurr, 0
end fn

local fn writeNotes(dev%)
' Writes note array to file dev.
' File dev must be opened for writing before calling Fn
'   and closed after return.
dim index&, @count&
count = [@noteH + _autoXREFCurr]
write dev, count
while count
count --
write field dev, noteH(count)
wend
end fn

local fn readNotes(dev%)
' Reads note array from file dev.
' File dev must be opened for reading before calling Fn
'   and closed after return.
dim index&, @count
fn clearNotes
read dev, count
while count
count --
read field dev, noteH(count)
wend
end fn