TweetFollow Us on Twitter

Sep 90 Mousehole
Volume Number:6
Issue Number:9
Column Tag:Mousehole Report

teLength, MacApp 2.0, and MPW

By Larry Nedry, Mousehole BBS

From: Fuzzy

Re: Change teLength

I have a programming problem. I hope someone can help me. I am using TC 4.0. I want to change the length of a Text Record as follows:

                (**gTheText).teLength = dataLen;

Using the TC debugger this appears to work just fine. However, when I follow this with a TEUpdate(gTheText), teLength is set back to the old value. Does anyone know why this happens?

From: Lecroy

Re: Change teLength

You need to also change the size of the htext handle to match the new teLength field. Changing teLength alone doesn’t cause anything to happen (except that teLength is temporarily wrong). The next time you call a TextEdit routine (ie. TEUpdate), teLength gets reset to the proper value.

Here is a Pascal(sorry) code fragment:

         gTheText^^.teLength = dataLen;
         HLock(HANDLE(gTheText));
         SetHandleSize(gTheText^^.hText,dataLen);
      {don’t forget to check MemError!!!}
         HUnLock(HANDLE(gTheText));

You don’t need to lock a handle unless you are dereferencing it *AND* passing the dereferenced portion of it as a parameter into a routine that may cause the heap to move. That’s exactly what I did with the SetHandleSize call. Heap movement can even occur when calling routines that can cause a LoadSeg when called. Also, some compilers may also have problems with using dereferenced handles in WITH statements and when making assignments from function calls (ie. aHdl^^:=funcThatMovesHeap;). I don’t know about the THINK compilers, but it’s my understanding that the MPW Pascal compiler deals with the last two examples properly.

From: Mward

Re: Change teLength

Don’t know exactly why that happens, but it’s probably just as well that it does, since if it didn’t, you might be clobbering important data. The TE data structure, like any other structure, has enough memory allocated to it to hold it, and no more. If you just started acting like it was bigger, you would be writing into someone else’s memory. Use one of the TE functions to add data to the Text Record. That way the toolbox will allocate memory as needed.

From: Venture

Re: Change teLength

Thanks for the clear explanation. What makes me leary of the dereferencing is that sometimes you have to really think (always painful) about when something is passed even within an expression. In retrospect it always seems obvious. One of these days I guess I’ll get a more intuitive feel for what is going on.

Relative to the HLock and HUnLock - maybe it was old code or you were completely sure that you were locking and unlocking a 100% private value.

Anyway, In Vol V of IM (almost sounds like a biblical reference) they change the recommended locking and unlocking process. The new “approved” way is to use HGetState to determine the current handle state and then use HSetState to reset the state after you are done. Thus HUnlock is never (?) used and you won’t inadvertently unlock something which someone else wanted to keep locked.

(Ooops, yes HLock would still be used after the HGetState has been used to find the state to save).

From: Lecroy

Re: Change teLength

You’re right, I should have been checking the state of the handle first to make sure it wasn’t already locked, otherwise I would end up unlocking a handle that was initially locked already by someone (something) else.

Here is a corrected code fragment:

     gTheText^^.teLength = dataLen;
     state:=HGetState(HANDLE(gTheText));
     HLock(HANDLE(gTheText));
     SetHandleSize(gTheText^^.hText,dataLen);
     HSetState(HANDLE(gTheText),state);

Alternately, if you’re really worried about knocking off cycles you can possibly get a speed improvement by using GetHandleBits and checking to see if you really even need to do any locking/unlocking like so:

    handleBits := GetHandleBits(aHandle);
    alreadylocked := BTST(handleBits, lockBit);  {lockBit=7}
    IF NOT alreadylocked THEN HLock(aHandle);
                .
                .
          {play with the dereferenced handle here!}
                .
                .
    IF NOT alreadylocked THEN HUnLock(aHandle);

By the way, where is this documented in I.M. V?? I looked everywhere for it to no avail...

I don’t know of a TE manager routine that concats text to a TEHandle, or truncates the text in a TEHandle. Adjusting the size of TEHandle.hText is certainly better than using [GS]etText with multiple copies of the text handle(?).

From: Venture

Re: Change teLength

I’ll go back and check for the reference tonight. I’m pretty sure it was in V, but let me check.

With regard to lockBit, hadn’t even thought of looking that deep. Fortunately I don’t have the need to get that efficient yet, or I would get completely lost.

I’ll get back to you.

From: Atom

Re: MacApp 2.0 -- worth the cost?

An application I intend to write using OOP will need to include code written in Fortran. Can THINK Pascal 3.0 use MPW runtime libraries? My impression after reading the manual is no, which is why I didn’t consider sticking with TCL a possibility.

From: Siegel

Re: MacApp 2.0 -- worth the cost?

You could use MPW .O files in THINK Pascal since 2.0; version 3.0 supports a couple of extra relocation modes and it supports the segmentation directives, so there should be little trouble in using Fortran .O files.

You may also need to add in FRuntime.o....

From: Walrus

Re: MacApp 2.0

For those of you who aren’t completely turned off by the drastic price increase of MacApp 2.0, it should be shipping any day now. The price does include a few extras that previous releases did not have. Apple’s ‘Intro to OOP and MacApp’ and the MacApp Tutorial (updated to the full 2.0 version) are included when you buy the package. This is saying something since ‘Intro’ is a pretty good introduction for the object programming new-comer (altho’ the new book ‘Programming in MacApp’ is probably the best one -- at least for procedural language programmers).

The upgrade for MacApp 2.0 is a bit odd. It is $120 for the disk version, $80 for the CD ROM. Hmmmm. Of course the CD ROM thing is whole new flame, i.e. why can you get an audio CD player for less than $100 but computer peripherals are many times more and it doesn’t seem to be really much of a difference in function?

All in all, unless one is committed to Think’s Class libraries, this is the way it is.

From: Mward

Re: MacApp 2.0

All in all, this Apple rip-off sounds like a real good reason to get committed to Think’s Class libraries. Think’s product is quick, efficient, pleasant to use, reasonably priced, well supported. And they don’t use upgrades to try and jam Marketing’s Hot Scam down your throat. Apple fails on all these counts.

From: Ray

Re: Desktop Discoloration

I’ve written an application is THINK C that uses the animated colors (i.e. I wanted total control of the color palette). Unfortunately, when you come out of this application, you usually find that the desktop is discolored, because dinking with the palette has changed the colors the desktop uses. Is there a way to record the original palette colors, then restore them so that you “clean up your own mess” when you’re finished?

From: Nicks

Re: Desktop Discoloration

It’s not necessary to save and restore the system palette if you do it right. First, never modify the system palette. Instead, create a new palette, and then make the appropriate QD/Palette Mgr calls to attach it to your app’s window. This involves locking/reserving the colors and defining them as animated colors. Next, use the colors any way you like, and when you’re all done, MAKE SURE YOU RELEASE THE PALETTE and its associated colors, or any other application (such as the Finder drawing the desktop) will be unable to revert to their preferred palette. This is probably the step you’ve left out. (BTW: there are a few games out there, such as Gauntlet, that do the same thing: they grab the system colors, and never release them, so any other color app looks very strange after you run that game.

From: Ray

Re: Desktop Discoloration

Thanks for that information. I am leaving that step out. It’s nice to know I have plenty of company.

From: Chip

Re: MPW vs THINK

I have been programming on Mac for 4+ years in Forth, assembler Pascal, C and now Smalltalk. I originally learned ASM, Pascal and C using MPW, I am now using THINK C. The learning curve on think is significantly less then MPW, and I haven’t experienced any limitations thus far. As for OOP, Smalltalk provides a good tool for learning OOP concepts however I am not particularly fond of programming in it because it was developed on a PC and ported to Mac, and the implementation of some things like buttons etc. stinks. Try an object C language.

From: Hweiss

Re: MPW

I am thinking about purchasing MPW since I would eventually like to learn C++. I thought it best to ask those of you familiar with the MPW environment for some advice.

My biggest concern is the possible limitation of my hardware. Will MPW run comfortably on a Mac Plus with 2.5 megs of RAM? If so, can I assume that I must at least purchase the MPW Shell and MPW C as a bare minimum to program in C? Is it also a good idea to buy the Symbolic Debugger (SADE) now?

I also would like to know if MPW C is 100% ANSI C compatible?

From: Walrus

Re: MPW

OK, I have a Mac SE with 2.5 megs and use MPW Assembler and Pascal -- neither of which can be called a resource hog as far as compilers go. Oh yeah, I also use MacApp. With that configuration, compiling Apples TESample application in the Pascal examples takes more than 2 minutes. The compiled application is a little more than 10k. Turbo Pascal it is not. C generally takes longer to compile, on top of C++ (which is only a pre-processor if my memory is correct) and that the SE is a little faster than the Plus, you’re talking about waiting a few minutes for each compile, although MPW is kinda smart and will not re-compile unchanged files.

I don’t use SADE so I don’t know how much that might affect performance. But I can say that using Multifinder, I don’t have a problem with the memory constraints. And if the compiles get a little over-long, you can click over to another application and work on something else.

If you have Think C and that is not good enough, then you probably don’t have much choice in the matter, it all depends on your reasons for going with MPW.

From: Atom

Re: MPW

MPW C will probably work OK with 2.5 megs, but C++ symbol tables take a LOT of memory. You can get by with a 1 MB partition for the MPW Shell if you’re only compiling small files, but beyond that it depends what you want to do. I would say MacApp is probably not feasible -- you need at least 3 megs to compile the headers with C++ 3.1B1. The final release is due real soon (less than a month), so you might want to wait for it and check back then.

As far as speed is concerned, bear in mind that MPW is VERY disk-intensive, so your hard drive is almost as important as your CPU. SADE requires Multifinder and a 1 MB partition. I wouldn’t recommend it with less than a 4 meg configuration.

From: Jumpcut

Re: MPW

I used C++ and MacApp, and didn’t have enough headroom until I got 8 megs. Watch out, those symbol tables get huge. (Fun thing to do: bring up the Finder’s about box, and watch the memory graph as you compile. It’s amazing how much it sucks up!)

From: Derek

Re: Bypass Chooser

Hello there. I am writing a program that needs to use 2 printers. So I need to know how to bypass the chooser within my program. They are both on the network. So what toolbox commands do I use? Is there any code example out there? Any help would be real nice. Thanks in advance.

From: Mrteague

Re: Bypass Chooser

I can’t tell how to bypass the chooser (nor would I recommend that), but there is an FKEY making the rounds at the moment that allows a user to toggle through all printer drivers in their System Folder - maybe you could get a hold of a copy and have a look at it. I imagine all it does it change the STR# resource in the System File that contains the information about the current printer etc.

From: Listhax

Re: Volume Icons

Does anyone know how to get the actual volume icons (e.g., the AppleShare icon) from the device drivers? The Tech Node just talks about the media/drive icons. I’m writing an application that needs to display the icons as they appear on la Desktop.

From: Rino

Re: Mystery globals & Macsbug

There is a “technote” or pamphlet about Macsbug that somewhat describes the MacJmp vector. Macsbug keeps the pc,regs,etc at a special ram location which are sometimes purposely corrupted by some a.....les copy protection. Anyway, Macsbug uses the MacJmp vector to determine if the break is from within or without ???? what. Upon entry into MacsBug, it determines if the breakpoint that was set earlier is still there. That is how it sees if it has been overwritten. I believe that for brkpnts in ROM it is using the special RAM locations to know where the PC is and what the state of the registers is. I hope this was of some help.

From: Ray

Re: Coprocessor help

Is there a way (in Think C in particular) that you can make a program take full advantage of a coprocessor if it is there, but still run on a Plus or SE? I know SysEnvirons will tell you if the coprocessor is there, but I don’t see how to take advantage of this fact, since with Think C you compile either for the coprocessor or not, and you can’t change off within a program (I don’t think) to use the right code. Maybe a macro that calls either of two branches depending on whether the coprocessor is there or not?

From: Fortune

Re: Patching Traps correctly

I was wondering if there was an example init or a document describing the correct method for Patching traps. Most the examples I have seen are tail patches (i.e. they do something, call the original trap, get the return value {if any}, and then return themselves). At the last MacWorld tail patching was something the Apple Guru’s were VERY much against.

I am looking for a *COMPLETE* description of a head patch. I am interested in what values are on the stack when the trap is called, and how to manipulate these values and replace them on the stack before *JUMPING* to the original trap.

The ideal answer to the request is a pointer to a well documented INIT which does a good head patch and manipulates the parameters that are passed to the trap, but pointers to documentation would also be helpful.

From: Rguerra

Re: Standard File Answer

Well, it seems I was a bit premature in posting the prior message. It turns out that just prior to calling the SFdlogHook procedure, Standard file stuffs the name and fileType in the fName and fType fields of the SFReply record respectively for FILES, and stuffs the dirID into the fType field for FOLDERS while leaving the fName field equal to nil. If NOTHING is selected BOTH fields are set to nil. So ... to test if the currently selected item in an SF dialog is a folder:

if (LONGINT(theReply.fType) <> 0) and (theReply.fName = ‘’) then {it’s 
a folder}

if you know the restype you are displaying, you can test the fType field for a specific resType to determine whether you’ve got a file selected.

From: Siegel

Re: 2 questions re: Memory Mgmt.

1) When running under MultiFinder, BufPtr should only be modified at system startup time, otherwise you end up stomping on MultiFinder’s heap.

2) You can preflight segment loads at a low level if you hook the _LoadSeg trap, as MacApp does. Getting in on SysError is way too late. If you don’t want to hook LoadSeg, you can always preflight your segment loads by calling GetNamedResource (assuming you’ve named your code segments), and verifying that the result is non-NIL.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »

Price Scanner via MacPrices.net

Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more
Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more

Jobs Board

*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
IT Systems Engineer ( *Apple* Platforms) - S...
IT Systems Engineer ( Apple Platforms) at SpaceX Hawthorne, CA SpaceX was founded under the belief that a future where humanity is out exploring the stars is Read more
Nurse Anesthetist - *Apple* Hill Surgery Ce...
Nurse Anesthetist - Apple Hill Surgery Center Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Apr 20, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.