The Free Pascal Compiler is an open source compiler that is similar to Turbo Pascal. Pascal was originally designed as a teaching language for computers, but it can be used to create commercial software and to perform complex mathematical operations.
Teachers should consider using Free Pascal for teaching computer programming because it works on all of the major platforms and school, library, and home computers can have Free Pascal installed at no charge. Pascal has a simple syntax that is English-like. This syntax makes Pascal easy to learn and use for both teachers and students. Because of these features, Free Pascal is ideal for educational settings.
The Free Pascal Compiler can be downloaded at : www.freepascal.org
The Free Pascal Compiler comes in 32 and 64 bit versions. It is available for Intel x86, AMD64 x86/64, PowerPC, PowerPC64, Sparc, and ARM processors. There an old version 1.0 that supports Motorola 68k processors.
The Operating System supported include Windows 95+, Windows 64 Bit OS, DOS, Mac OS X, Mac Classic OS, Darwin, Linux, Netware (libc and classic), OS/2, MorphOS. (Other operating system may be supported or become supported with new releases of free pascal)
Free Pascal also supports the following systems:
Game Boy Advanced
Nintendo DS
Note: The Mac X version of Free Pascal requires the development tools (Xcode) to be installed on the computer. Xcode can be found on the CD/DVD that came with the Mac or can be downloaded at Apple’s Developer Connection: http://developer.apple.com
For users who have Windows, Mac X, and Linux computers, there is an IDE called Lazarus. Lazarus is similar to Delphi and works with the Free Pascal Compiler to create GUI and console applications. Lazarus is free and can be downloaded at: www.lazarus.freepascal.org
This tutorial series will focus on using the Lazarus as the IDE on Windows. This tutorial series will start by using the console application of Free Pascal as maintained by Lazarus and then move to GUI applications once the syntax and logic are shown.
Note:
If you get an error with “end.” highlighted within the lpr tab, comment out the {$IFDEF Windows} {$R project1.rc} {$ENDIF} line. Lazarus will recreate this line later on in the tutorial. It seems to have to do with an icon bug.
More Information:
http://bugs.freepascal.org/view.php?id=15581
Let’s start making some programs:
The first thing to do is close the project.
Do not save the project, unless you need to.
Next, click on File --> New . . . --> Project --> Program
The computer will create some code in the Source Editor Window. Do not change the computer generated code.
Put the following line in between begin and end
writeln(‘This is the first program!’);
The code should look like:
begin
writeln(‘This is the first program!’);
end.
Run the program by clicking Run --> Run
The computer will run the program.
Hum.... It looks like nothing happened.
Something did happen. The computer ran the program. Once the program ran the console window closed and that was the end of the program.
To fix this, a readln(); must be entered into the code. This will force the computer to stop until the Enter (Windows) or Return (Mac) key is pressed.
The new code will look like this:
begin
writeln(‘This is the first program!’);
readln();
end.
This is the first program!
Should be printed on the screen.
Once Enter is pressed the program will end. It is a good idea to let the user know that the Enter Key has to be pressed for the program to end.
Here is a modification of the program:
begin
writeln(‘This is the first program!’);
writeln;
writeln;
writeln(‘Press <Enter> To Quit’);
readln();
end.
This is the first program!
Press <Enter> To Quit
Should be printed on the screen, once the program is run.
Program Download: FPTutorial1.zip
To create a stand alone executable program. First save the source code, then click Run --> Build
Lazarus will create an executable file located next to the saved source code
Video Tutorial: Free Pascal Tutorial 1 - The First Program (7:52) Blip.tv
Beginning Next