AppleTalk Shell
Volume Number: 5
Issue Number: 12
Column Tag: Pascal Procedures
Related Info: AppleTalk Mgr Event Manager
AACK gives AppleTalk Shell
By Ajay Nath, Oakland Gardens, NY
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
[Ajay Nath has two B.A.s, one in Chemistry and one in Mathematics. He is
currently a second year medical student and is using Macs to develop Color Vision
tests.]
AACK OR ATApp?
Example AppleTalk programs have appeared before in MacTutor but none
recently except in one of the HyperCard columns. The introduction of MultiFinder, a
new interface to the AppleTalk routines and new features added to AppleTalk itself,
have changed the way applications should use AppleTalk. In this article I present a
program called AACK, the “AppleTalk Application Construction Kit”, which was
written in LightSpeed Pascal 2.0, which demonstrates how to use the new AppleTalk
interface and how to use the background features of MultiFinder. The resources of the
program were created by ResEdit and stored in a file called “aack.rsrc”, a rez
description of the resources is found in the file “ resources.r”. The code of the
program is in 4 files/units as follows:
FILE/UNIT CONTENTS
globals.p global declarations
lowlevelATprocs.p low level procs
hooks.p code specific to the application
main.p generic application code
The code is designed to be easily modifiable. By simply changing code in the file
hooks.p the nature of the applications produced can be changed. For example, in the
file main.p, the code that handles menu selections look like:
{1}
IF HookedMenuChoice(theMenu, theItem) = FALSE THEN BEGIN
CASE theMenu OF
APPLEMENUID:
DoAppleMenu(theItem);
FILEMENUID:
DoFileMenu(theItem);
SPECIALMENUID:
DoSpecialMenu(theItem);
OTHERWISE
END;
END;
where the function HookedMenuChoice is declared in the file/unit ‘hooks.p’. It returns
false if it DIDN’T handle the menu choice, it allows the programmer to ‘hook’ or handle
menu choices before the applications generic code does and to override the generic
codes response. For example, the generic code of AACK simply puts up a windows, some
menus, and allows the user to see others of his type on the network and to confirm
their presence. There is a menu titled “Special” which has items labeled “LookUp”,
“Confirm” and “Send”. The generic code handles the first two items (this can be
overridden) but does nothing but beep when “Send” is chosen. By changing the code in
the hooks.p file, you can create an application that does something else with AppleTalk,
perhaps sending strings through the net as was shown in a previous MacTutor article.
There is obviously a code/speed overhead introduced by using this method, but its far
more easy to get something to work and to later go back and optimize than to start each
application from scratch. (Maybe I should have called it “ATApp: The Expandable
Macintosh AppleTalk Application”?)
Bypassing Generic (Brand?) Code OR OverRid’em CowBoy!
Most of the generic code is trivial stuff to MacTutor readers and I have left out
some things such as handling DAs which is left to the reader as an exercise. The code
does use LSPs ability to have compiler variables. I declare a compiler option called
“TALK_DEBUG” and set it to TRUE when I want the compiler to include certain
debugging code in the app. Basically, the generic code does a “SetUp” routine and lets
the code from the “Hooks” unit do any “SetUp” - i.e. - the generic routine
SetUpGlobals does its “SetUps” and then calls the procedure “SetUpHooksGlobals”,
which lets the Hooks code do its “SetUps”. Similarly the generic code lets the Hooks
code do any Window and AppleTalk “SetUps” after it has done its own such “SetUps”.
The generic code also checks to see if the Hooks code has decided to take over the duties
of taking care of the applications window by examining a global Boolean variable called
“UserWindowProcsChanged” which the Hooks code can set to true in its “SetUp” code.
For example when activating the UserWindow the generic code does the following:
{2}
IF UserWindowProcsChanged THEN
HooksActivateUserWindowProc {Let hook code do its magic}
ELSE
LActivate(T, NameListHdl);
One consequence of this is that even if the Hooks code wants to override only one
of the procedures that controls the windows activation, deactivation, updating, or
disposal, it must override them ALL. You only have to copy and paste the generic code
from the file main.p into the file hooks.p to mimic the generic codes handling of the
other procedures though. For example, you might write an app using AACK which
receives/sends messages and overrides the way the generic code draws the windows
contents to draw any received messages at the bottom of the window, but it wouldn’t
need to override any other of the generic codes window handling routines. You could
just copy the other generic code routines from the file main.p and pasted them into the