Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 UW 5/3/83; site uw-beaver Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!mhuxn!houxm!vax135!cornell!uw-beaver!info-mac From: info-mac@uw-beaver (info-mac) Newsgroups: fa.info-mac Subject: Re: Macintosh Development Techniques (long) Message-ID: <2422@uw-beaver> Date: Tue, 4-Dec-84 02:52:10 EST Article-I.D.: uw-beave.2422 Posted: Tue Dec 4 02:52:10 1984 Date-Received: Tue, 4-Dec-84 23:48:17 EST Sender: daemon@uw-beave Organization: U of Washington Computer Science Lines: 45 From: Gustavo FernandezIn MacView, I found a problem of two subroutines calling a common routine. The first caller and the callee both need a certain memory block accessed by a handle, but the second caller doesn't need it. The first caller needs to lock the handle, and so does the callee. The question is: does the callee return with the handle locked (for the first caller) or unlocked (for the second.) I solved this problem by defining two new routines: CHLock (Conditional Handle Lock) and CHUnlock. PROCEDURE CHLock(H:Handle;VAR F:BOOLEAN); PROCEDURE ChUnLock(H:Handle;F:BOOLEAN); ChLock returns in its second parameter a flag which tells whether the\ handle was locked BEFORE the ChLock. It then unconditionally locks the handle. If the boolean flag in CHUnLock is FALSE, then this subroutine unlocks the handle, else it is a no-op. Assuming that the flag is saved on the stack. CHLock and CHUnLock can be called to any deapth as long as subroutines exit normally. If anyone knows of a better solution, please tell me. Another problem I had was dealing with the (often complex) issue of whether meus were highlighted or not, and if so, which items within the menus were enabled. I solved this problem by defining a resource type with an individual resource for each possible combination. (which in my case depended solely on which window was active (on top) at the time) The resource had the same format as STR# where each "string" corresponded to a menu and has length (number of items in menu)+1. The first character is the master control and further characters control individual menu items. Characters ar E for enable, D for disable, and . for leave alone. A single character line would simply perform the appropriate action for the entire menu. This data driven approach, while perhaps not time efficient is quite space efficient when you want to disable lots of functions inappropriate for a particular window. ----------------------- I would like to hear more of these techniques should you receive any. This would be a very interesting thread for experienced Mac programmers on INFO-MAC -------