Free Mac development using

Think Pascal 4.5

written by Ingemar Ragnemalm.

News: (May 2000) There is a patch to make Think Pascal 4.5 compatible with newer versions of MacOS! And this time it works! See "How do I get it" below.

Contents:

  • Introduction
  • What is Think Pascal?
  • How do I get it?
  • Setting it up
  • Getting started
  • Having fun with the debugger
  • Doh! Why doesn't my program work?
  • Learning the Pascal language
  • Using Think 4.0.2 demos with 4.5d4
  • Using Sprite Animation Toolkit from 4.5d4
  • OK, so what's so great with the debugger?
  • Acknowledgements and final words

  • Introduction

    This page is written in order to help you get started with Think Pascal 4.5, the newest version of Think Pascal, freely downloadable off the net. The fact that you can download the complete compiler for free means that we have a complete free development system for the Mac!

    Note, however, that it is provided as an unofficial update. You can get no support whatsoever for it from Symantec! Version 4.5d4 was made by Rich Siegel (of BBEdit fame), who was in the past responsible for the official updates of Think Pascal. We should be thankful to both Rich for making the update and for Symantec for providing it. Both make no money from it. Let's make a note in the "good reputation" column!

    About the author

    I, Ingemar Ragnemalm, have no official status with Symantec and Think Pascal, but am basically just a long-time satisfied user. I have developed large amounts of code with Think Pascal, and I believe that I know both Mac programming and Think Pascal pretty well. Still, I don't claim that I know everything about either of them.

    I started programming the Mac with Borland's Turbo Pascal, and switched to Think C since that's what everybody recommended, and I needed something a bit more professional than Turbo, something that could handle more than one source file at a time.

    One day, a friend had an old Pascal program that he wanted to run on the Mac. For some reason, I tried Think Pascal when doing it. Actually, I think the reason was that TransSkel was made for Think rather than Turbo. And, I was astonished to see how easy it was! Think Pascal nailed my errors far quicker than any of the other systems I knew, and I used the debugger efficiently almost without being aware of it. I gave it a few more shots, and was hooked. I converted the C code I was working on to Pascal, and saw how development speed was multiplied. Today, that old code is known as Sprite Animation Toolkit.

    I was amazed, and I still am. Part of it was that Pascal is a more forgiving language than C, and also nicer to use with the Mac toolbox, but an equal part was the qualities of Think Pascal as a development system.

    What is Think Pascal?

    Think Pascal is an excellent development system for the Macintosh. It was released by Think Technologies in 1986 as Lightspeed Pascal. Think Technologies was bought by Symantec, and the name was changed to Think Pascal. The last official update came 1992, and the product was officially discontinued in 1997.

    Lightspeed Pascal was a fantastic development system, significantly better than its cousin Lightspeed C (Think C). It is surprising that it didn't get more attention. There are some reasons, one that Pascal is often considered to be "just" an educational language, an impression that perhaps was exaggerated by its close relation to MacPascal, an interpreter that definitely is only for educational use.

    But, Lightspeed/Think Pascal is so much more!

    It has some drawbacks, namely:

    All these problems have their solutions:

    How do I get it?

    Download Think Pascal 4.5d4 from Symantec.

    Download a better set of interfaces from my archive.

    Download the Think Pascal 4.5d4->4.5a1 patch. This is necessary to use Think Pascal on MacOS verisons 8.5 and up, and adds some other improvements as well.

    No, you can't use the interface files that come with the compiler. They are buggy, and also tedious to use, with lots of unnecessary "uses". The modified version may not be perfect, but it works a lot better.

    Setting it up

    Decompress THINK Pascal 4.5d4.sit, Ingemar's UPI for TP 4.5d4.cpt and Pascal 4.5a1 Update.sit by dropping them on Stuffit Expander. (Keep the archives in case you want to go back.) The result is three folders, one named THINK Pascal 4.5d4, one named THINK Pascal 4.5d4 Folder and a third named Pascal Update. The first contains my modified UPI,the other Think Pascal and the original UPI, with subfolders named THINK Pascal 4.5d4 and THINKPas Univ Hdr 2.1, and the third is the update.

    Now we must clean up this mess.

    Move the contents of THINK Pascal 4.5d4 (my modified interfaces) into THINK Pascal 4.5d4 Folder:THINK Pascal 4.5d4 - that is, move my interfaces to the folder where the compiler is located. Trash the empty THINK Pascal 4.5d4 folder.

    Open THINKPas Univ Hdr 2.1. Move Runtime.lib and the folder Libraries into the folder where the compiler is. Take THINK Pascal 4.5d4 out of THINK Pascal 4.5d4 Folder, and trash THINK Pascal 4.5d4 Folder (now containing only THINKPas Univ Hdr 2.1).

    Move Interface.Lib from the update frolder to the Think Pascal 4.5 folder. Trash Interface.o. (There was another Interface.Lib in the Univ Hdr folder, but that should be trashed by now.)

    Run THINK Pascal 4.5d4 -> 4.5a1 to update the Think Pascal 4.5 application.

    To clean up the Think Pascal 4.5 folder, you may want to put away the doc files. If you kept the archives, why not trash them? There is some useful information in them, though.

    You should now have a folder with the following files and folders:

    The resulting folder should something like this:

    Rename the folder to THINK Pascal 4.5a1, just to make it tell the truth. OK, now you have a complete development system ready to use!

    You need two more things to make it complete: you need a resource editor and a reference to the Mac toolbox!

    ResEdit is the only choice for resource editor if you have an extremely low budget. Resorceror may be of interest the day your budget is better.

    Finally, how about the documentation to the Mac toolbox? Inside Macintosh is the original text on the subject. If you haven't done so already, I suggest you get a copy of Apple's Inside Macintosh documentation. You can download it from Apple. There is a lot of documentation so I suggest looking at the Overview first to give you an idea of what other documentation volumes might be worthwhile for your needs.

    An alternative that is easier to use is Think Reference, which was made by Symantec but is published by MacTech these days. Commercial, a bit too C-centric, but easy to use.

    An old shareware solution is Inside Mac DA. It only covers up to Inside Mac 4, so it is older than Color QuickDraw, but still small, fast and pretty useful as a reference to the most important parts. A more modern solution that you can also get off the net is ObiWan by Peter Lewis. It is shareware, $10.

    Getting started

    Think Pascal is a fairly intuitive development system, where you can learn a lot by just trial and error. Open dialogs, change settings, try menu commands, and not least, run and modify demo programs!

    Now, how about starting out with the simplest program of all, "Hello world". Do the following:

    Create a new project. Check "instant project" if you want a main program file created for you. Replace the line

    { Insert your program code here }

    by

    ShowText;
    WriteLn('Hello world!');

    Hit cmd-R (Run) to compile and run. No problem!

    Now, how about the "real Mac" version of Hello world? It is longer, but not too bad:

    program Test;
    {Variables:}
    var
    w: WindowPtr; {A window to draw in}
    r: Rect; {The bounding box of the window}
    begin
    {Create the window}
    SetRect(r, 50, 50, 200, 100);
    w := NewWindow(nil, r, '', true, plainDBox, WindowPtr(-1), false, 0);
    {Make it the current drawing port}
    SetPort(w);
    {Draw a string!}
    MoveTo(5, 20);
    DrawString('Hello world!');
    {Wait for a mouse-click, then stop.}
    while not Button do
    ;
    end.

    All the parameters to NewWindow are a bit confusing, but you will usually read windows from resources, which is easier.

    I have no intention of providing a complete manual here, but here are some notes on things that are not entirely intuitive:

    Having fun with the debugger

    Have you tried the debugger yet? You don't really need to know all of it to start working, but there is a lot of potential there, not all of it obvious. It consists of at least four parts: the editor windows, Lightsbug, Instant and Observe.

    The Lightsbug window may seem a bit cluttered. The most useful part is the variable list, but the other parts are worth exploring. You can click-and-drag variables to the icons down the left side to access some special features.

    The top three icons swich between variable view, register view and heap view. You will mostly use the variable view, although the other two are in no way useless! Then follows these: Magnifying glass, File cabinet, Eye Folder, Pencil icon, Groucho icon and Trash icon. All are explained if you click on them!

    The bottom part of the window shows the memory as raw hex numbers. That is occasionally useful, but when you don't use it, you can hide it by dragging the separating line downwards.

    Don't forget the other parts of the debugger! Lightsbug is just one of them. The innocent-looking Observe and Instant are extremely powerful and useful, and the editor windows, where you single-step and set breakpoints, is perhaps the most vital one.

    Note, however, that power should be used with a little care. Be careful with putting expressions in Observe that use pointers or handles that may become invalid, or expressions that allocate memory!

    Here are some specific non-obvious debugger features:

    Doh! Why doesn't my program work?

    There are a few pitfalls, problems that you can run into after a while.

    There is one infamous problem that you should be aware of: When you build a program to disk, and it doesn't work. This can leave a beginner rather stumped and frustrated. Well, don't be. The likely problems are the following:

    Finally, if the compiler is crashing on you for no apparent reason: Are you using MacOS 8.5 or newer? Are you still using 4.5d4 (or older) or have you applied the update mentioned above? If not, do it!

    Learning the Pascal language

    I will not teach you Pascal here. To learn the language, you can just buy a textbook. There is also some resources on the net. A pretty nice, although not Mac-specific, on-line course is available here. Note that there are some bugs in the links, with mixing "htm" and "htlm" extensions incorrectly, but you will figure it out. There is also a link to another Pascal course at Pascal Central.

    Apart from learning the Pascal language, Mac programming require some specific knowledge. Reference material like Inside Mac, Think Reference or ObiWan holds the information, but they don't teach Mac programming. But, there is a way, and it is free: the book Macintosh Pascal. That book, and its demos, deal with CodeWarrior, but the differences are not too big.

    Using Think 4.0.2 demos with 4.5a1

    Now you should go out and get some demos! Here are some places to get them:

    My source-code archive (also by ftp).

    Pascal Central, truly worth the name with links to most net resources of interest for a Pascal programmer. In particular, check its source-code section.

    Peter Lewis has made a large bunch of reusable modules available. (All newer code there is for CodeWarrior, but that isn't too hard to adapt.)

    Water's Edge Software has the Tools Plus library, which supports Think Pascal.

    Leo Possajennikov has made a number of small freeware games available with Think Pascal source-code.

    Want to play music in your TP application? Try Zerius Sound System by Cody DW Jones, the only MOD player that comes with Pascal interfaces in the standard package &endash; and it is also the best MOD playing lib I've found!

    Almost any Pascal source for the Mac is of interest for you. There is one little problem though: there are almost no demos that are written for TP 4.5a1! You will find demos for TP 4.0.2, and for CodeWarrior, and for both, and perhaps some for Turbo Pascal for the Mac or MPW Pascal. You will need to make some changes to make it work.

    It will be easiest with TP 4.0.2 demos. Let's get a simple one and make the necessary changes!

    A very simple animation demo I wrote is MicroAnimationDemo. It demonstrates sprite animation, and is about as simple as it gets. The link above is to a version that works with TP 4.0.2 and CodeWarrior. To see how I adapted it to TP 4.5a1, click here.

    Some demos will work with no changes at all. Such demos include Info, OneTest, On the edge and MemoryGame. Generally speaking, most code that doesn't require any interface units (except the auto-included ones) will run without changes.

    The demo KbdLts required a few changes. Types.p had to be added to the project and to the "uses". Some changes in DeskBus.p also messed it up a little, so I had to hack that.

    When I modified the interfaces, there was one problem that I couldn't solve to 100%, and that was the changed defintion of "Pattern". Painted Black is a program that required some changes to reflect that problem.

    Here are some modified demos:

    MicroAnimationDemo

    KbdLts

    Painted Black

    Using Sprite Animation Toolkit from 4.5a1

    Sprite Animation Toolkit, my game making library, is a package that should be of interest for hobby game programmers, especially using Think Pascal. The standard distribution supports only TP 4.0.2, and most demos require some changes to work with TP 4.5a1. In order to make it easier for 4.5a1 users to get started, I have put together a package with SAT 2.5.0 and a couple of demos, all tested with TP 4.5d4 with the modified interfaces. (It is not yet tested with 4.5a1.)

    Download!

    OK, so what's so great with the debugger?

    Anyone who speaks for Think Pascal is bound to mention the debugger in more or less enthusiastic terms.

    So, what about it? Isn't it just another source-level debugger?

    No, it isn't. Like all other source-level debuggers, you can set breakpoints, single-step though the code, inspect variables, and evaluate simple expressions... but that's where the competitors stop.

    Here's a quick comparison of features:

    Breakpoints and single-stepping:

    Think Pascal: Everything is done in the editor windows. This means no unnecessary windows to clutter your screen, and you can set the breakpoints before you compile and run!

    Think C and CodeWarrior up to CW Pro 2: You must first compile and run. Then the debugger stops, and you can then navigate to the places you want breakpoints. Extra windows, harder to navigate, and compile-and-debug takes much longer!

    CW Pro 3 is better than older CW in this respect. You set breakpoints in the editor windows, but you still single-step in a separate debugger window. Well, it is getting there.

    Viewing variables:

    Think Pascal: All variables accessible in the current context are listed in the Lightsbug window(s).

    Think C: Old versions: no variable list available. In Symantec C++ v8, it finally got variable lists. I don't know if those give the full set of variables or just a subset.

    CodeWarrior: Only a subset of the accessible variables are shown.

    All three can change the value of shown variables.

    Expressions:

    Think Pascal: Any expression that is valid in the code is evaluated, including constants and function calls. (This is the Observe window.)

    Think C: Fairly complex expressions can be evaluated. Function calls can be evaluated, but the feature is off by default.

    CodeWarrior: Only very simple expressions can be evaluated. Constants and function calls are not allowed. On the positive side, expressions can be used for conditional breakpoints, but that would only be useful if the expressions were not so limited.

    Type-and-execute ("Instant"):

    Think Pascal: Any code that is valid in the code can be typed in and executed while the program is halted.

    Think C and CodeWarrior: Don't have it and will never get it.

    Well, that's what I think is the most important differences. Think Pascal wins every comparison with a wide margin! (Anyone who disagrees, please tell me so, but not without solid arguments.) If only the C users realized what they are missing, perhaps we would see as good debuggers in the future, but as it is now, Think is the top of the line. Spread the word and the future might get brighter.

    If nothing else, take a little time learning what you can do with it. It is well worth it.

    Acknowledgements and final words

    Thanks to Rich Siegel, Gale Paeper and all others who have suggested additions and corrections! Some parts of the text is quotes from you. And thanks to Symantec for making this possible.

    I'm sure CodeWarrior fans aren't too amused by the comparison in the previous section. Let me stress that I am not anti-CodeWarrior in any way. I have it, use it, like much of it, but keep wishing for a better debugger for it. As I've said before, the best development system I've been able to come up with is a combination of Think Pascal and CodeWarrior. With TP 4.5a1, it is even easier than before to use the same code with both compilers!

    I belive that this page will be a positive thing for all involved:

    But... what do I get? Well, I don't know. A higher phone bill, I guess.


    Copyright ©1998 Ingemar Ragnemalm.

    Updated: 5-June-2000