4 |
BIN MEMO
continued
Figure 1.
Structure
of Database Flies Used by BINMEMO.PRG.
Program BINMEMO operates on an arbitrary database file specified at
runtime by the user, storing binary disk files into its memo fields or
reiiieving them from its memo fieids and writing theni back to disk.
SYS.DBF and MEMOLIST.DBF are used by BINMEMO internally. In
between runs of the program, MEMOLIST.DBF is stored in a SYS.DBF
memo field named ML_DBF.
BINMEMO
Is
Based on
can be found in
the
FoxPro
Help file, or
in
Tom
Rettig’s help file. For my part, I
the FoxPro Low-Level File
got simply copied the small code ex-
Functions
amples
for these functions from Tom
The basic technique is not at all
corn-
Rettig’s TRHELP file, and
started twid-
pLicated. It employs the FoxPro low-level
dli. BINMEMO.PRG evolved as a
file functions. To
create
a disk file, you
housing around
these
functions.
use FCREATE ( ) to enable reading from
or writing to a file that already exists, use
How to
Use BINMEMO
FOPENO. FREAD() and FWRITE()
perform the actual reads and writes. The
The operation of the program is as
syntax of their use is straightforward, and
follows: first, the user indicates what
database file has
the memo fields
s/he
wants to work
Introduction to xBase Programming
with. FoxPro
makes
it real easy to
Dialect-independent “hands-on” instruction in dBase
do this. The single
language programming for those wanting to work in Fox-
statement
base, FoxPro, dBase III +, dBase IV, Clipper, or other
USE?
“xBase”
dialects,
takes
care of it!
Next you
tell the
Call for more information!
program whether
Greg Dunn Associates
you want to store a
file into a memo, or
(213) 371-6035
retrieve one from a
memo and
write
it
to disk. Note that I’ve
included,
just for
educational purposes, two different ways
to implement the little menu you choose
from; one is disarmed with comment
asterisks.
I’ve implemented a pop-up menu at
the GETwhere you indicate which memo
field in the tile you want to use. This
popup, displayed by way of an ON KEY
LABEL statement,
presents
the user
with a list of all the MEMO fields
and
only the MEMO fields — in the database
s/he opened. Procedures PICKMEMO
and PICKMEMO2 build the memo field
list in MEMOLIST.DBF, the little
database file we keep tucked away in
SYS.DBF.2
The user selects the record s/he wants
to work with from a BROWSE window.
If s/he needs to add a record into the
database s/he can do it from that same
BROWSE window by pressing Ctrl-N. If
s/he wants to delete unwanted records,
Ctrl-T will take care of it. It would, of
course, be easy to assign more elegant
keys to these operations; I’ve stuck with
those native to FoxPro.
I’ve also thrown two other procedures
of interest into the soup. Function
YesNo displays buttons for the end user
at any binary branching point, returning a
"Y" or “N” depending on which button the
user “pushes”. You pass YesNo() a
numeric parameter to define the default
anwer.
Procedure ERRMSG allows you to
specify a message of arbitrary length, line-
by-line in an array. It then displays this
message, centered and giving you some
control over its placement, using the
MODIFY MEMO command with the
NOEDIT qualifier so the message can’t
be changed. (Come to think of it, the user
might enjoy being able to rewrite your
error message!)
Whenever we get a user group library
I’ll put the routines and other associated
files used with BINMEMO.PRG in it.
Meanwhile I’ll bring a few copies on disk
to the August meeting.
Enjoy!
2 You may note that I am ‘unpack-
ing: MEMOLIST.DBF at the beginning
of program BINMEMO, and deleting it
only at termination of the program. In
a networked application in a situation
requiring better security, you could un-
pack sensitive files only at the moment
of actual need, deleting them from the
disk immediately after use.
4
LA. FOX
|
4 |