4D External Area Shell
Volume Number: 7
Issue Number: 2
Column Tag: C Workshop
By Alexander Colwell, Redondo Beach, CA
4th Dimension™ (4D) is an amazing database developed for the Macintosh. It
allows rapid development of an application’s database for specified requirements. One of
the nice features in 4D is the ability to execute external procedures and areas. External
procedure (EP) is similar to HyperCard™ external commands and functions. This gives
the database developers additional controls required in their input and output layout
designs.
The external area (EA) is a section of the layout to display some graphical object
the 4D does not handle. 4D does handle almost every thing the database developer would
normally require. However, there may be some cases where the standard data entry
field types: text, radio button, check-box button, pop-up menus, etc would not handle
the desire operation in user mac-friendly style. For example, Figure 1 shows an EA of
a calendar. (Alex uses an alternate and configurable WDEF; he also uses an alternate
CDEF for scrollbars.-ed)
Figure 1
The calendar EA would be more intuitive to the user determining how to input the
specified days rather than text-base form or some other radio/check-box button
combinations. For example: If using text-base form then the user should enter the data
as: April 1990 18-20,26-27; Apr 1990 18,19,20,26,27; 18-20,26-27 APRIL
90; or other zillion combinations. Clearly, I believe, an EA would be ideal under these
conditions.
This article will attempt to explain how to develop an EA. But wait! With simple
EA as the calendar, it can be difficult to debug the EA with the 4D environment. So, this
article will also cover a 4D debugger emulator similar to Think C’s ‘cdev’ and DA
debugging tools for developing an EA, specifically the Calendar EA. Hence, the database
developer can perform the majority of the debugging phase using Think C’s symbolic
debugger.
Writing EAs are not really difficult, but documentation is rather skimpy on
more advanced EAs other than their simple examples. There is a section describing how
to write an EA in 4D 1.X manuals, and it is completely missing in v2.X manuals!! I
suppose, the people at ACIUS want to keep writing EA a mystery to most database
developers.
The only other documentation available can be found in ACIUS Technical Note
#35 and MacTutor September 1988 issue. Armed with these information, I was able to
write rather interesting EAs.
I used Think C’s Object classes to emulate EA and EPs, which has given me the
ability to use the symbolic debugger. The object classes hierarchy are similar to
MacApp™ other than the different names for the object classes. This helped me to use the
Think C’s objects quickly, but there is still a substantial learning curve associated with
Think C’s objects as well as MacApp’s objects. So you have to put in your time to learn
how to use the object libraries.
External Area Events
The EA can receive two classes of events: standard Mac Events and 4D Events. The
standard Mac events are nullEvent, updateEvt, mouseDown, and keyDown. These events
are generated as one expects. The nullEvent is sent to EA whenever there is nothing to do
and perform standard idling operations. The updateEvt event is sent to EA to update the
rectangular area within the layout. The mouseDown event is sent to EA whenever the
mouse is clicked inside the EAs rectangular area. And, the keyDown event is sent to the
EA whenever there are keyboard inputs. More about keyDown event in selectReq event.
The initEvt 4D event informs the EA to be initialized. Normally, the EA will save
its data handle in the eaData variable. I will discuss about this later in the External
Area Protocol with External Procedures topic. This is the first event the EA will
receive other than the drawReq event when opening a layout containing the EA.
The deInitEvt event informs the EA to release its memory allocation via the
eaData handle. This is the last event the EA will receive before the layout is closed.
The selectReq event asks the EA if it wants to receive keyDown, activeNote, and
deActivNote events. If the EA wants these events then it must reset the
eaEvent->message to 101 value. This event always occurs after the initEvt event.
Otherwise, the EA will not receive these events.
The cursorEvt event informs the EA that the cursor is inside the rectangular
area of the EA. The EA may want to change the cursor into something else other than