Lazarus at TU/e: Frequently Asked Questions

This FAQ concerns Lazarus 0.9.24.
Also see Getting Started with Lazarus at TU/e.

General Lazarus and IDE Questions:

FreePascal Questions:

General Lazarus and IDE Questions

How do I install Lazarus?

Lazarus 0.9.24 for Windows together with FreePascal 2.2.0 is pre-installed (via full install on the disk image) on laptops of first-year 2008-2009 students in the Department of Mathematics and Computer Science at TU/e.

You can check this in het Windows START menu under All Programs: Lazarus should be available in a submenu.

You can install Lazarus yourself:

N.B. You are strongly advised to completely remove old Lazarus and FreePascal installations first.

Note that certain personal Lazarus settings are stored outside the installation folder, e.g. in your AppData\lazarus\ (Windows) or ~/.lazarus/ (Linux) folder. You may wish to keep these settings. However, if you are installing a new Lazarus version because of troubles with the older installation, then it may be advisable to remove those personal settings first. Remove the entire folder; Lazarus will create a fresh set of initial settings.

Also see: I upgraded Lazarus and it no longer works. What now?

How do I use the Lazarus IDE?

See Getting Started with Lazarus at TU/e.

What to do if Lazarus fails to work? Are there alternatives?

This concerns a fresh Lazarus installation as it appears on
the disk image for first-year Computer Science students at TU/e.
If you did the installation of Lazarus yourself,
or if you changed your Lazarus installation,
or used it already for some time,
then you should also look at some of the other questions:

Unfortunately, we have had instances where even the simplest program fails to run properly from within Lazarus. This is probably related to the debugger. The FreePascal compiler works fine.

To use the Lazarus debugger under Windows Vista, it is useful (necessary?) to set a property of Lazarus.exe (typically found in C:\lazarus\) to `Windows XP Compatibility'.

It is also possible to disable the debugger in Lazarus through the menu

Environment > Debugger Options ... > General
and at "Debugger type and path" select "(None)". It is not necessary to use the debugger to complete the course 2IP05.

Some troubles can be solved by removing personal settings, that may have become corrupted. Certain personal Lazarus settings are stored in your AppData\lazarus\ (Windows) or ~/.lazarus/ (Linux) folder. Remove the entire folder; Lazarus will create a fresh set of initial settings.

Alternatives are:

I upgraded Lazarus and it no longer works. What now?

When you upgrade Lazarus, it is best to remove the old installation first. Do this with the uninstaller, or by removing the Lazurus folder (on Windows typically in C:\lazarus).

Furthermore, it may be possible that some older settings survive the upgrade, in particular, to the FPC compiler and its source files. These settings can be upgraded manually:

For Lazarus 0.9.26, the FPC version number in the paths should be 2.2.2 (not 2.2.0).

Also see: How do I install/upgrade Lazarus?

How can I prevent that Lazaraus closes the command window when my program terminates?

See Running the program in a project.

How to get back the Lazarus Toolbar when stepping through a program?

I consider this a bug.

Workaround. Environment Options ... > Windows: uncheck `Hide IDE windows on run'.

What to do if Run fails

When the program is not yet running and you click Run (or menu Run>Run, or function key F9) to start it, the command window may appear but the program's output does not appear, and the program seems to be stuck.

Workaround. Stop program execution via Run>Stop (Ctrl+F2). Reset the debugger by Run>Reset debugger.

After each run, the debugger should be reset to avoid this problem from reoccuring.

What to do if Step Over fails

When the program is not yet running and you click Step Over (or menu item Run>Step Over, or function key F8) to start it, a dialog window may appear, asking you to locate (Bug?) Dismiss this dialog window by clicking `No'.

Workaround. Set a Breakpoint on the first line after the program's first begin (by clicking next to it in the left margin; this should highlight the line in red and mark it with a red bullet). Then Run > Run (F9) the program. After that, you can use Step Over (F8).

Why do I not see the value of a variable when pointing at it?

This sometimes does not work for some variables. (Bug?)

N.B. The program must be active (the Lazarus Toolbar should have (debugging ...) in its title) in order to inspect variables.

Workaround. Put the variable in the Watch List: View > Debug windows > Watches, double click on the topmost empty line, and enter the variable's name next to Expression, click OK.

Why does my program fail in peach³, but not when I run it on my laptop?

Usually, the explanation is that peach³ compiles programs with Range Checking enabled and with Use Ansi Strings enabled (also see here), and your laptop does not.

When indexing strings the index must be inside the current range of the string, i.e., for s: String evaluation of s[i] requires 1 <= i <= Length(s).

See here for recommended settings and how set them.

What if Lazarus crashes with an unsaved program?

It is always recommended to save work often when using a computer. With the default settings, Lazarus automatically maintains a backup of various files in a project. You can inspect and adjust the backup setting through

Environment > Environment Options ... > Backup
Typically, Lazarus keeps backups in a separate folder named backup inside the project folder, but this can be changed.

How can I rename a file in a project?

One should be careful about renaming files that belong to a Lazarus project.

N.B. File names appear in several places, such as in the *.lpi Lazarus Project Information file, and (explicitly or implicitly) in uses clauses to indicate dependence on units in other files. When changing a file name, this should usually be done in a consistent manner.

Workaround. Open the file to be renamed in the Source Editor. Use File > Save As ... to save a copy under the changed name. Find (e.g. through the Search menu) other files in the project that somehow reference the old name. Change relevant occurrences to the new name. Remove the old file from the project, and add the new file to the project. Delete the old file or move it outside the project folder, to avoid confusion.

N.B. Opening a file belonging to a project, and removing from/adding to the project can all be done through Project > Project Inspector.

How can I create a Lazarus project from a given program file?

When you only receive a program text and not a Lazarus project, you somehow need to create a project. There are two alternatives:
  1. Using Project > "New Project from file ...", create a new project from the given main program file (typically *.lpr, content starting with program). Choose for "Create Custom Program".

    In that case, you get a default project, whose option settings do not correspond to the preferred TU/e options in the project TUeConsoleApp. More information on setting project options.

    You still need to save it in an appropriate place.

  2. Copy the given project TUeConsoleApp (open it, and do Project > "Save Project As ..." to put it in its own directory, and give it an appropriate name). Using copy/paste, replace the program text by the one you were given.

Additionally given units (typically *.pas, content starting with unit) can be added to the project by putting them in the same directory, opening them with the editor, and doing Project > "Add editor file to project".

FreePascal Questions:

Why should I pass files as var parameters?

A procedure that needs to read from or write to a (text) file should have this file as a var parameter.

The reason is that both reading and writing may change the state of the communication port associated with the file. The parameter passes this communication port (and not the actual file contents), which keeps track of where the next read/write operation will take place (i.e. the location of the read/write head). Both for reading and writing, the read/write head is at a certain location when the procedure is invoked: the parameter appears in the precondition, stating that it is open for reading/writing. Afterwards the location of the read/write head in the file has changed. Hence, the file parameter (the communication port) must be passed as a var parameter.

It is the case that by reading the contents of the file do not change.

Feedback about this page is welcome