2 |
by
Charles
Williams
One of the
major reasons that Mac
applications seem so
interactive is that
they
are “event driven”
that is, the user
can freely redirect the program to a com-
pletely different activity at any time with
just a single mouse click. The ability to
easily create a customized user menu
facility that supports this kind of behavior
is one of the features that distinguishes
the Macversion of Foxbase from its DOS
cousins. Faxbase /Mac not only provides
the commands to build a custom menu
facility that meets Mac standards, but it
also provides a menu “trap” that reacts
automatically and immediately to a user
mouse click on any menu command.
Since Foxbase responds to “menu hits”
whenever the currently executing pro-
gram encounters a READ, a program
containing a looping construct with a
READ in it will give what appears to be
instantaneous response to a menu click.
Although Fox hasn’t provided a slick
graphically-based tool for this purpose, as
they
do for
screen
building
and report
generation, the five commands
and two
special functions used
to
create a menu
facility
are not
difficult
to
understand and
use.
Based
on the
description
in
a recent
George Goley column, building a
menu
facility in FoxPro
with
similar behavior
is
far more complex.
However, since
the
Fox documentation
in this area
leaves
something to be
desired,
and since it
does
take some experimenting
to get
a
proper-
ly
working
menu,
I
offer
the following
very condensed description as
an
ap-
proach that works. I think
it
will
get
you
on the
right track
the
first time you have
to create
a
menu.
This approach contains
five
basic
steps.
The
objective is
to
construct a
menu
bar across
the top of the
display
screen, with
each menu on that bar
having
an
associated set
of
individual commands
that are activated by just sliding the
mouse to the
desired
one and
releasing,
and with immediate action or program
redirection
corresponding
to the
chosen
command. The result will
be
two
programs
-
one
becomes part
of the
in-
itialization
routine of the application, and
the other
is a separate
menu
processing
program.
Foxbase commands support
two ways
of
thinking
about menus;
this
approach thinks in terms
of
arrays
-
the
menu
bar isan array
and
each
set of menu
commands is an
array.
In Step 1 you dimension the menu
bar,
name the individual menus, and use
a
specific
menu command to “install” the
menu bar.
DIMENSION mbartop(4)
mbartop(1)
=
Plain”
mbartop(2)
=
“Fancy”
mbartop(3)
=
“Fancier
mbartop(4)
=
“Very Fancy”
MENU BAR mbaitop
You have now
told Foxbase
to make
a menu bar with 4 separate, named
menus at the top of the
screen.
In Step 2
you
dimension, name and
install the
list
of
commands
on each of
those
4
menus. Here are two
samples:
DIMENSION mbarl (3)
mbarl(1)
=
“First”
mbarl(2)
=
“Second’
mbarl(3)
=
‘Third”
MENU 1, mbarl
DIMENSION mbar3(4)
mbar3(1)
=
“Primary”
mbar3(2)
=
“Secondary”
mbar3(3)
=
‘Tertiary”
mbar3(4)
=
“Quaternary”
MENU 3,
mbar3
You have now
told Foxbase
that the
menu in
position 1
in the menu bar
has
three commands,
and
the
one in position
3
has
4
commands.
In Step 3 you add a submenu (hierar-
chical menu) to one of the
commands
on
menu three. The approach is the same,
but the install command uses a different
option.
DIMENSION
sub3l(4)
sub3l(1)
=
‘Number One’
sub3l
(2)
=
‘Number Two”
sub3l
(3)
=
“Number
Three’
sub3l (4)
=
‘Number Four
MENU 3,
sub3l,4,1
You have now told
Foxbase
that
there
is a submenu with 4 commands attached
to the
first command on
the menu in
position 3 on the menu bar.
In Step 4you install the menu trap and
make a connection to a menu processing
program. This step
uses a special
menu
command and two special functions
designed
just
for this purpose. (This
is the
command that FoxPro
doesn’t
have yet.)
ON MENU DO menuproc.prg;
WITH MENU(O), MENU(1)
You have now told Foxbase that
whenever the user
clicks
a menu, it should
transfer control to the menuproc pro-
gram, and pass it the contents of two
MENU functions. The first function
returns the number of the menu
the
user
clicked, and the second function
returns
the number of the particular command
on
that
menu. One puzzling question
that is not treated in the documentation
is what the MENU
functions
return in the
case of submenus. By experiment it
seems
that MENU(O) returns the
next
number beyond the last full menu, so the
best
approach to keep the menu numbers
straight is to define the whole set of
menus first and then define the sub-
menus. You
can easily
check the num-
bers by just
running
a debug
window
to
watch the MENU(O) and MENU(1)
functions as
you click
the menu
In Step 5 you build the menuproc pro-
gram to take action based on the
users
choice.
This
program is usually nothing
continued on
page
14
LA.
FOX
The Other Foxbase
Foxbase +/Mac
L.A. FOX
A monthly publication of the
Los Angeles FoxPro/Foxbase
User
Group
Published
at
2616 Vargas
Way
Redondo Beat CA 90278
(213)371-6035
This newsletter
is designed
to
provide
a forum
for users
of
FoxPro, Foxbase +,
and
Foxbase+/Mac
to
share
informa-
tion, perspectives, and techniques.
Please note:
This
group
has
no
formal
connection
with
Fox
Software,
Inc..
Opinions
expressed
and
liberties
taken
herein
are
the sole responsibility of the
direct perpetrators. Don’t
blame
Fox
Software.
Editor Greg Dunn
Newsletter Design and Production
Gay Dunn
LA. FOX
St eering Committee:
President:
Greg Dunn
Treasurer George Dvorak
Mem&r Benefits Randy Unruh
Secretary: Charles Williams
Member-at-Large Kris Dahhn
Please send
newsletter material to:
Greg Dunn
2616
Vargas Way
Redondo Beach, CA 90278
(213)371.6035
All
contents
Copyright 1990 by LA.
Fox,
unless indicated otherwise.
2
|
2 |