pjhayward's Pascal Tutorial

pjhayward.net Home

Got a question?

Tutorial Home
Lesson One - Sample Program
Lesson Two - Program Structure
Lesson Three - Data Types
and Constants
Lesson Four - Variables
Lesson Five - Text I/O
Lesson Six - Subroutines
Lesson Seven - Conditional
Lesson Eight - Arrays
Lesson Nine - Loops
Lesson Ten - Units

To start out, you will need to have a Pascal compiler. Generally, a compiler is a program capable of reading in "source code" (usually stored in a file, but not necessarily) and translating it into machine code. I will be using the Freepascal compiler for these tutorials. If you are using an old version of Pascal, such as Borland Pascal 7, or Turbo Pascal, I HIGHLY recommend you upgrade. If you are planning on writing code for DOS, you MIGHT want to stick with your current compiler, just because DOS support in FreePascal is shaky at best. Not many people use it anymore, and they just don't have capable people interested in spending time maintaining it. With that said, I will be using version 2.2.0 of the FreePascal compiler. You can download the latest version here. If you want more information on FreePascal, please visit their website.


If you are using Windows, you will generally want the i386/Win32 version. I386 represents the family of processors found in most Windows computers. Newer systems may have the AMD64 or x64 type processor - I'm going to leave that up to you to figure out. Just make sure you download the correct compiler for your system. Installation on Windows is straightforward - they provide a 27MB installer that takes care of everything for you.


If you are using linux, you have a couple of options. You can either try to packages provided by your distribution, or you can install it yourself (I recommend the latter). To install FreePascal 2.2.0, download the full 30 MB tar file from one of the FreePascal mirrors. The file should be named fpc-2.2.0.i386-linux.tar - note the .tar extension. If you download the .rpm files, or the .deb files, you're on your own. Save the tar file to some folder on your system - any folder you have write access to will do. Unpack the tar file (use 'tar -xf fpc-2.2.0.i386-linux.tar' from the command line). If you haven't yet, become root (run 'sudo -s', or just 'su' from the command line). Run the installation script by typing 'sh install.sh' on the command line. It will prompt you for a number of installation options. I chose to install to the /usr folder. You won't want to do this if you have another copy of FreePascal installed there (i.e. one from your distro). If you decide to have two versions of FreePascal, make sure you are very clear about which you are using - version differences can cause a lot of confusion. At any rate, once you decide where to install it (use the default /usr/local if you're not sure), it will ask you whether you want to install various components of the FreePascal system. I installed everything - I may not use it, but if I want to, it's nice to have it already there. Accept the default options for documentation and demo locations, unless you know what you're doing. Once the script completes, switch back to your regular user account (type 'exit' on the console). You should now have a usable installation of FreePascal. To test it, type fp at the command line. It should bring up the FreePascal textmode IDE.

Note: If you're using Debian, you may get an error message about an incompatible or nonstandard GPM daemon. What this basically means is that you might see strange mouse behavior. Personally, I don't use the mouse in the FP IDE, so it's not really an issue for me. If you need to use the mouse, I recommend you try the Ubuntu Linux distribution. It has many of Debian's strong points, but is updated regularly, and has a wider range of software available. You can find it at http://ubuntu.com/. They have a Live CD available, so you can try it before you install it.