If you want to do Pascal programming at home, then you need to install a Pascal compiler on your computer. This page shows you how to install and begin using the Free Pascal Compiler.
- Step 1:
- From the Free Pascal Windows download page download the following installer program.
http://downloads.sourceforge.net/freepascal/fpc-2.2.0.i386-win32.exe (32 MB)
- Step 2:
- Double click on this program to run the installer. The installer will create a directory
C:\pp and put the compiler system in this directory. After running the installer, you can delete the installer file.
- Step 3:
- If you want to, you can test your Pascal installation. Use the Start Menu to start up a "Command Prompt" window. At the command prompt, enter the following command.
c:\pp\bin\win32\fpc
You should get back from the Pascal compiler a "help message" that is several screens long. Now download this hello.pp file. At the command prompt, use the cd command to move to the directory where you stored the file hello.pp . Compile hello.pp with the following command.
c:\pp\bin\win32\fpc hello.pp
After the program compiles, run the program with the next (very simple)command.
hello
- Step 3.5: (optional)
- In the last step we used the "full path name",
c:\pp\bin\win32\fpc , at the command prompt for the Pascal compiler fpc . If you want to work with Pascal from the command prompt, using full path names can be inconvenient. So you may want to set the Windows PATH variable to include the Pascal compiler system. Unfortunately, how to do this varies from one version of Windows to another, so I will leave it up to you to figure out how to do this on your version of Windows. Setting the PATH variable in not necessary for the following steps.
- Step 4:
- If you have already installed TextPad on your computer (for use with another programming language), then skip to Step 6. Otherwise, download the TextPad text editor (the current version, at the time of this writing, is TextPad Version 5.1.0). TextPad is shareware; you can download and use it for free for a trial period, but then you are supposed to pay a shareware fee if you plan to continue using it. Use the following link to download the installation file (which is just over 2.7 MB in size).
ftp://download.textpad.com/pub/textpad5.1/txpeng510.exe
- Step 5:
- Install TextPad by double clicking on the installer that you just downloaded.
- Step 6:
- Run TextPad by finding it in your Start Menu. Click on the Tools menu at the top of the TextPad window. Several "tools" are pre-installed by TextPad. We need to install three new tools that let us use Pascal from within TextPad. We will create one tool to compile and link a Pascal program, one tool to run the resulting executable, and one tool for viewing the assembly language listing created by the compiler.
- Step 7:
- We need to create a tool in TextPad to call the Pascal compiler and linker. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\pp\win32\bin and then in that directory double click on the program fpc.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have the item "fpc". Click on the item "fpc". This brings up a window where we can configure the "fpc" tool. In the text box labeled "Parameters:" enter the following text. (Note: Upper and lower case matter! The best way to enter the text is to use cut and paste from here to the text box.)
-alrt $File
In the text box labeled "Initial folder:" enter the following text:
$FileDir
Make sure that the check boxes labeled "Save all documents first" and "Capture output" are checked. Now click on the button "OK" at the bottom of the window. This completes the creation of the compiler and linker tool. (You can check at this point and look in TextPad's "Tools" menu to see if the tool "fpc" is at the bottom of the menu list.)
- Step 8:
- We need to create a tool in TextPad that lets us run a Pascal program that we have compiled and linked. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
C:\windows on a Windows 98/ME computer or the directory C:\WINNT\system32 on a Windows 2000/XP computer. On a Windows 98/ME computer, double click on the program command.exe . On a Windows 2000/XP computer, double click on the program cmd.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should have either the item "command" or "cmd". Click on the appropriate item. This brings up the window where we can configure the tool. In the text box labeled "Parameters:" enter the following text:
/k $BaseName.exe
In the text box labeled "Initial folder:" enter the text:
$FileDir
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window. This tool will run your Pascal program one time and then leave you at a command prompt so that you can type other commands (you can use the "exit" command to close the console window).
Note: If your Pascal program does not prompt the user for any input, then you can configure TextPad to capture your program's output and display it in an editor window. Change the text in the text box labeled "parameters:" to
/c $BaseName.exe
(notice that we are changing the switch /k to /c) and then check the check box labeled "Capture output". This technique can be useful for a variety of reasons, for example, you want to save the program's output, or you want an easier way to read a large amount of output, or you are using Windows 98 and the console window does not have a line buffer, etc.
- Step 9:
- In this step we create a tool to display the assembly language listing created by the Pascal compiler (the assembly language listing is not essential for Pascal programming but it is very informative and of great educational value). Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Program...". In the file dialog box that comes up, navigate to the directory
"C:\Program Files\TextPad 4" . Double click on the program TextPad.exe . Now you should be back to TextPad's "Preferences" window. Click on the button "Apply" at the bottom of this window. Now click on the + next to the word "Tools" in the left hand pane of the window. Under the word "Tools" you should see the item "TextPad". Click on the "TextPad" item. This brings up the window where we can configure the tool. In the text box labeled "Parameters:" enter the following text:
$BaseName.sw
In the text box labeled "Initial folder:" enter the text:
$FileDir
Make sure that all the check boxes are unchecked. Now click on the button "OK" at the bottom of the window.
- Step 10:
- Now it is time to test TextPad with a Pascal program. Use your browser to download and save this short Pascal program, hello.pp, to your computer. Use TextPad to open
hello.pp . (You can use the "File -> Open" menu item in TextPad; you will need to remember where you had your browser store the hello.pp file. Or, you can right click on the file hello.pp and choose TextPad from the pop-up context menu.) Use the "Tools -> fpc" menu item to have TextPad run the Pascal compiler and linker. After the compiler is finished, close the editor window that captured the compiler results. Now use the "Tools -> cmd" menu item to have TextPad open a command window and run the executable hello.exe . After the program runs, close the command window. Purposely create a syntax error in the Pascal program. Try to compile the program. When you get an error message from the compiler, double click on the line number in the error message. TextPad should jump to the line in the Pascal program that the error message referred to (but this does not work yet since I have not yet figured out what "regular expression" in Step 8 describes this compiler's error messages).
- Step 11: (optional)
- At this point, the three Pascal tools that we created have pretty unappealing names. You can use the "Configure -> Preferences..." menu item to edit these names by clicking on the word "Tools" in the left hand pane of the "Preferences" window and then clicking on a tool in the middle pane and editing the name of the tool.
You can also put a Menu Separator in the Tools menu between the Pascal tools and the other tools. Click on TextPad's "Configure -> Preferences..." menu item. In the left hand pane of the window that comes up, click on the word "Tools" (don't click on the + next to the word "Tools"). In the right hand pane, click on the "Add" drop down list and choose the item "Menu Separator". The new Menu Separator appears at the bottom of the list of tool names. Click on the up arrow at the very top of the list of tool names to move the separator up in the list to the position where you want it.
- Step 12:
- So far, the TexPad editor does not know anything about the syntax of Pascal. In this and the next step we fix things so that TextPad can color code Pascal source code according to Pascal's syntax. From the TextPad Syntax Definitions page download the file
pascal.zip . Expand this zip file into a temporary directory. The directory contains a single file, pascal.syn . Move this file to the directory "C:\Program Files\TextPad 4\System" .
- Step 13:
- If TextPad is running, close it and restart it with no open files. We need to create a "Pascal document class" for TextPad. Click on TextPad's "Configure -> New Document Class ..." menu item.This brings up a "Document Class Wizard". In the first step of the wizard, enter the name "Pascal" for the new document class and then click on the "Next >" button. In the second step of the wizard, enter the string "*.pp" (without the quotes) to describe the files in the class and then click on the "Next >" button. In the third third step of the wizard, check the box labelled "Enable syntax highlighting", then in the drop down list choos the item called "pascal.syn", and then click on the "Next >" button. In the fourth step of the wizard, click on the "Finish" button. Open a Pascal source code file (with the extension .pp) and notice that TextPad now color codes the source code.
|
TextPad is a very powerful text editor. It has a lot of tools that make working with Pascal, C, C++, Java, HTML, etc., files very easy. Editors like Notepad really pale in comparison to an editor like TextPad.
When you are editing your Pascal source files, remember to save your work frequently (at least every 15 minutes), otherwise it may be Abort, Retry, Ignore?
|