Dev-Pascal.
Editing, compiling and
debugged from a Pascal program
In this first practice of the subject, the aim is to become familiar with the computer and the
basic elements of the Dev-Pascal programming environment. The environment allows working with two
compilers, the GNU-Pascal and FreePascal (interchangeable in the program options). The
The FreePascal compiler in the DevPascal environment allows for easy debugging of errors.
The graphical interface
The following practices of the subject will be carried out using the Dev programming environment.
Pascalhttp://www.bloodshed.net/devpascal.htmlabout computers with Windows operating systems
The graphical user interface of Dev-Pascal looks like this:
Department of Computer Science and Systems Engineering page 1
Essentially, it has the following components:
Menu bar:
a. File. Contains options to manage (create, open, save) source files.
from an application, as well as print them and exit the application.
b. Edit. It contains basic editing functionalities (copy, paste, cut and
select text), do/redo actions, basic programming templates
(comment headers, loops, etc.), marker insertion and access.
c. Search. It contains a search engine within the source code.
d. View. Allows managing the visible elements of the graphical user interface.
e. Project. It facilitates the management of complex programs that use various
source files.
f. Execute. Contains the necessary functionalities to compile, execute and
debug the program.
g. Options. This menu allows you to modify the compiler options (paths.
access, generation of information for debugging, compiler selection,
etc)
h. Tools. Contains a heterogeneous set of functionalities, such as the
access to the build results window, program creation
self-installable, etc.
i. Windows. It contains functionalities for managing sales.
of the program.
j. Help. Contains information about the DevPascal programming environment.
a tutorial, information about Pascal, etc.
2. Toolbars.
Understand the Main toolbar, the Build and Run toolbar, Project,
Options and Help and Special. Its visibility is configurable from View. Toolbars. All
these toolbars provide shortcut buttons to the functionalities
most common of the graphical user interface menu.
3. Editing area. Text editor that facilitates the creation and modification of the source code.
program.
4. Status bar. Provides information about the position of the cursor in the editing area.
(row, column), the editing mode (insert or replace) and on the total number of lines
what the source code file contains.
5. Tab Bar. It facilitates access to vital information, such as the result of the process of
source code compilation.
6. Window control buttons. Allows to minimize, maximize, or close the windows of
source code and of the application.
Department of Computer Science and Systems Engineering page 2
Initial Configuration
Before starting to work with Dev-Pascal, it will be useful to modify the code that is provided by default.
it generates the environment when we create a new file.
For this, in the menu bar, choose the option Options -> Environment options -> Misc. Once
selected, the following dialogue appears:
Replace the default code that appears when creating new source files with this:
{
AUTHOR:
PROJECT:
FILE:
DESCRIPTION:
}
program title;
begin
end.
Press the button on OK. From now on, every time we create a new file in Dev-
Pascal, that initial code will appear, which will need to be completed.
Department of Computer Science and Systems Engineering page 3
Editing a program in Pascal
There can be several files associated with a specific practice or program (the source file of
Pascal, the executable, data files and results, etc.). Therefore, it is a good idea to save
all the files of a practice in a separate directory for each one.
Create a new editing window (File New Source File) and write the following program in
Pascal, don't worry about the typing errors you mentioned for now:
program test1 (input, output);
{
This program contains an error:
The variable 'Celsus' is not defined.
Check that the Pascal compiler detects it.
}
var
real
begin
Enter the amount of degrees Celsius:
readln(Celsius);
(9.0 / 5.0) * Celsus + 32.0;
writeln('The amount of degrees in Fahrenheit is ', Fahrenheit:8:2);
Press Return…
readln
end.
Save the file astest1.pas(File Save unit as…).
Compilation and debugging of a program in Dev-Pascal
Compile the program by accessing Execute Compile. The figure on the next page shows the
result obtained.
The build window will indicate that the program could not be successfully compiled.
Selecting each of the lines with the mouse in the Compiler window of the tab bar,
you will observe the compilation errors that have occurred. In this case, you will verify that you
It alerts that the identifier Celsus has not been declared, and it is used on line 12 of your program.
Edit the source code again and locate the line where the error is (line number 12) and
correct it. Once this error is corrected, and any other possible errors, leave the editor and return to
compile the file. You have to repeat this entire process until there are no detectable errors left by
the compiler.
If the compilation is successful, the compiler will not emit any error messages. Now, access the
Execute menu Run and the application will be executed in a command interpreter window
(Shell). Check its operation. The message 'Enter the amount of' will appear on the screen.
Celsius degrees: Write a real number followed by RETURN and you will get the conversion to degrees.
Fahrenheit. You can repeat the operation as many times as you want.
Now introduce a letter instead of a number. You will see that the program ends because it has
A runtime error has occurred.
Department of Computer Science and Systems Engineering page 4
Examples of program debugging in Pascal
This section provides simple examples to understand some errors that occur in the
program debugging.
Error messages: types and meaning
Compilation error
It is an error generated by the compiler when attempting to obtain an executable program from the code.
source. They are the result of syntactic or semantic errors in the Pascal source code. Example:
...
PROJECT: ...
errors1.p
Program to observe compilation errors
}
program generateCompilationError(input, output);
var grade: real;
begin
nota := 7.50;
The obtained grade is:
end.
Department of Computer Science and Systems Engineering page 5
When trying to compile, the following error message appears:
11 / 34 error1.pas Identifier not found NOTTA
Indicates that an error has occurred while trying to compile on line 11 in NOTTA. The message of
IDENTIFIER NOT DEFINED, which means that this identifier has not been declared (nottay
We note distinct names.
Execution error
It appears when the program is syntactically correct (no compilation errors have occurred)
action), but some of the actions it tries to perform are incorrect and result in an error. Example:
{
AUTHOR: ...
PROJECT: ...
FILE: errores2.p
Program to observe execution errors
}
program generateExecutionError(input, output);
var
counter
file of integer;
begin
assign(dataFile, 'file.dat');
for counter := 1 to 25 do
begin
read(dataFile, data);
writeln('The number data ', contador, ' is ', dato)
end;
close(dataFile)
end.
The source program is compiled as in the previous example. When trying to execute it, an error occurs.
runtime error because an attempt was made to read data from the file 'fichero.dat' from a file that does not
exists.
Monitoring and tracking of programs
There are occasions when the program does not show the desired behavior, but we do not get it right.
to find the error. In those cases, it is advisable to have some type of help to figure out
Which parts of the program have executed correctly.
Department of Computer Science and Systems Engineering page 6
Follow-up Messages
If we try to run the following program, we will find that it 'gets stuck', and
it never ends.
{
...
PROJECT: ...
FILE: sinfin.p
Infinite loop program
}
program always(input, output);
var x: integer;
begin
x := 1;
while x<>0 do begin
x := x + 1;
if x = 5 then x := 1
end;
end.
A good idea could be to insert certain messages to try to find out which parts of the code
they run and detect if there is any point in the program that is not reached.
{
AUTHOR: ...
PROJECT: ...
sinfin.p
DESCRIPTION: Infinite loop program with trace
}
program always(input, output);
var x: integer;
begin
x := 1;
I have assigned a value to x.
while x<>0 do begin
x := x + 1;
if x = 5 then x := 1
end;
I have finished the loop.
end.
In this case, the following output is obtained:
I have assigned a value to x.
Department of Computer Science and Systems Engineering page 7
The second message does not appear, so we can deduce that the program has 'stuck' in
some point between the first and second message. We can refine a little more, inserting
additional messages, or monitor the value of certain variables.
Case 2: Monitoring of variables
We modified the previous program as follows:
{
AUTHOR: ...
PROJECT: ...
endless.p
DESCRIPTION: Infinite loop program with trace
}
program forever(input, output);
var x: integer;
begin
x:= 1;
I have assigned a value to x.
while x<>0 do begin
x := x + 1;
if x = 5 then x := 1;
writeln ('The value of x is: ', x)
end;
I have finished the loop.
end.
And we get the following output:
I have assigned value to x.
The value of x is: 2
The value of x is: 3
The value of x is: 4
The value of x is: 1
The value of x is: 2
...(the messages continue indefinitely...)
to interrupt the execution press Ctrl+C
Thus we discovered that, indeed, the program cannot terminate because it never reaches a value.
0.
FreePascal compiler update
The compiler that Dev-Pascal uses by default is FreePascal 1.0.6, installed automatically.
by the Dev-Pascal installer. As the latest available version at the moment of this
the compiler is 2.4.2, two utilities are provided that modify the configuration of Dev-Pascal
to ensure that I can work with the version of FreePascal that interests us the most: 1.0.6 or the
2.4.2.
•DevPas_FP242.bat changes the compiler used by DevPascal to FreePascal 2.4.2
Department of Computer Science and Systems Engineering pag.8
DevPas_Orig.bath makes DevPascal use the original compiler again
For this utility to work, it is essential that both Dev-Pascal and FreePascal
2.4.2 must be previously installed, and also in the default directories specified in their
respective installers; namely, "C:\Dev-Pas" for Dev-Pascal and "C:\FPC\2.4.2\bin\i386-win32"
for FreePascal 2.4.2. In case these tools have been installed in other
directories, all occurrences of these paths would have to be replaced with the correct ones
in the six provided files: DevPas_FP242.bat, DevPas_Orig.bat, and within the
data folder, fpc_orig.cfg, fpc_nw.cfg, devpas_orig.ini and devpas_FP242.ini.
Insight Debugger
In the Dev-Pascal installed in the practice laboratories, the Insight debugger is available.
Integrated debugger in the environment. If we want to do the same in our Dev-Pascal, we must
follow the following steps:
Download the installer (http://downloads.sourceforge.net/mingw/mingw-insight-6.3.exe)
Install it in the Dev-Pascal folder
Open the insight folder
Move all your content to the Dev-Pascal folder
Rename the file gdb.exe to gdbshell.exe
Rename the file insight.exe to gdb.exe
Delete the insight folder (where the debugger has been installed)
Some easily solvable problems
In our experience using the Dev-Pascal application, we have detected some small issues.
problems, most of which have already been resolved in the installation of the laboratories of
practical, but that will appear when we install this tool.
Tool/Dos shell option does not work
Search the device for the files COMMAND.COM or CMD.EXE
Copy it (do not move it) to the Dev-Pascal folder.
Rename this copy to DOSCOM.EXE
You cannot associate an icon with the application through the option Project / Project options /
Icon Library
Open the Dev-Pascal folder and rename the Icons folder to Icon
After modifying the compiler options, the default ones reappear.
The options stored in devpas.ini are the correct ones (that is, the ones you have selected.
the user); that is, until the Compiler options dialog box is accepted again
The status bar initially does not appear, even though it is checked to do so.
There is no problem: just hide it, as it brings nothing.
Constantly trying to access an unavailable disk drive
If you can open the File menu, select the option File/Reopen/Clear History
Otherwise:
Open devpas.ini with Notepad
Department of Computer Science and Systems Engineering page 9
Near the end, there is a section titled [History] and another titled [History_Open]
or clear the content of both
The characters of the extended ASCII are not displayed correctly in the execution of the
program
The character encoding used by the graphical interface and by the text interface of Windows
they are different. In order for the characters of the extended ASCII code to display the same, the most
it is simple to select in the text interface the same encoding as in the graphic interface, it
What is achieved by executing the following command in the Windows text interface:
MODE CON CP SELECT=1252
It is not possible to start a debugging session
In the dialog box Options/Compiler options/Linker, select Generate debugging
information
It is not possible to open the Insight Debugger help.
They are located in the Dev-Pascal folder, specifically in the folder
share/insight1.0/help. Open the file index.html with the web browser
Department of Computer Science and Systems Engineering page 10