Ottawa PC Users' Group (OPCUG)


   Copyright and Usage

   Privacy Policy

   Contact Us


A Free Pascal Compiler

by Alan German

A recent venture into programming (see the earlier newsletter article Back to Basics) using a language that I initially thought I knew something about turned into a research project on a very different, object-oriented variant. I came across a reference to Free Pascal, seemingly a version of yet another language I have used previously. So, attracted by the combination of “free” (my favourite category of software) and “Pascal”, I decided to take a look at this open-source Pascal compiler.

The documentation for Free Pascal indicates that it supports multiple hardware platforms and operating systems. In particular, it will support 32- and 64-bit Windows and Linux which, potentially, makes it a useful tool for my purposes.

I didn’t find downloading the installation package all that intuitive. On the download page of Free Pascal’s web site, I selected AMD64/Intel 64/x86_64, Windows 64-bit, and SourceForge as the mirror, and was confronted by a number of packages. These included fpc-3.0.4.i386-win32.exe and fpc-3.0.4.i386-win32.cross.x86_64-win64.exe. Now, while the latter package appears to be related to 64-bit systems, Windows indicated that the installed Free Pascal Compiler (fpc) was not compatible with my 64-bit operating system. It turned out that I needed to install fpc-3.0.4.i386-win32.exe, after which fpc ran quite happily.

I opted to install the compiler in C:\FPC. The program is then activated by running C:\FPC\3.0.4\bin\i386-win32\fp.exe. The display is interesting. The compiler essentially opens in a command window, and displays (on my system at least) an extremely pixelated “FPC” graphic. More importantly, there is a File, Edit, Search, Run… menu bar running across the top of the window. This DOS-type menu system is FreePascal’s Integrated Development Environment (IDE).

The IDE provides the tools that we need to create, edit, save, compile and run our Pascal programs. It displays multiple windows such as a text-entry screen in which we can enter the Pascal source code, and a window in which messages (e.g. errors) from the compiler are reported.

Our first task is to establish contact with an existing data folder (D:\FreePascal) in which we are going to store our source code. Click on File and select the Change dir… option to display the default directory tree. The easiest way to get to our existing folder is to navigate to Drives, double-click to show the available drives, double-click on D, and finally double-click on the FreePascal folder. Now click on the Ok button in the dialogue box to make D:\FreePascal the active directory. (And, that was the easiest way!)

Now, we select File – New and, thinking back to our Turbo Pascal days, we type in the five lines of code for the infamous “Hello world” program. We can use File – Save to store this as the source file hello.pas. Selecting the Compile item from the main menu allows us to choose the Compile option. If there are no mistakes in our typing (or in our memory!), the compiler will return the message “Compile successful: Press any key”.

However, suppose that we forgot that the “Hello world” writeln statement must end with a semi-colon. Now, when the source code is compiled, two message windows will pop-up. One of these, labelled Compiling (Debug mode) will tell us that there are 2 errors and that “Compile failed”; the second window, labelled “Compiler Messages” will indicate:

hello.pas(4,3) Fatal: Syntax error “;” Expected but “identifier READLN” found

hello.pas(0) Fatal: Compilation aborted

The (4,3) portion of the error message tells us that the error is on line 4 in column 3. This seems to indicate that the syntax of the readln statement is at fault. However, the error message also indicates that FreePascal is expecting a semi-colon but it found readln instead. Perhaps this is a clue! There is no semi-colon on line 3. We can fix any such errors in the source code window and click on the small green square in each of the error-message windows to remove them from the display.

Once we have successfully compiled the program, we are left with our source code visible in the editor. In the background, FreePascal has created the files hello.o (the object file) and hello.exe, the executable program. If we navigate to D:\FreePascal in File Explorer and double-click on hello.exe, a command window opens and “Hello world” is displayed. Success!

Note that we can also run the program by selecting Run from FreePascal’s menu, and then selecting the Run option. The IDE changes to a command window and displays:

To return to the IDE, we simply (but non-intuitively) hit the Enter key.

So, we know a few of the basics of how to create, compile, and run FreePascal programs. Now the trick is to produce a program that will do something useful! However, before we move on to such heady tasks, we will take a small detour to explore a somewhat more sophisticated version of the IDE – a package named Lazarus. But, this will have to wait for Part 2 in the series…

Bottom Line:

Free Pascal (Open Source)
Version 3.0.4
Free Pascal Development Team

Originally published: January 2019

top of page



Archived Reviews





The opinions expressed in these reviews
do not necessarily represent the views of the
Ottawa PC Users' Group or its members.