You are on page 1of 59

Lazarus Tutorial

Deutsch (de) English (en) espaol (es) suomi (fi) franais (fr) magyar (hu) Bahasa

Indonesia (id) italiano (it) (ja) (ko) (mk) Nederlands (nl) portugus (pt) (ru)

slovenina (sk) shqip (sq) (zh_CN) (zh_TW)

Lazarus is a free and open source development tool for the Free Pascal compiler, which is also free and
open source. The Lazarus Integrated Development Environment (IDE, see Screenshots) is a programming
environment to create standalone graphical and console applications.

Lazarus currently runs on Linux, Mac OS X, FreeBSD and Win32 and provides a customizable source
editor and visual form creation environment along with a package manager, debugger and complete GUI
integration with the Free Pascal compiler.
Contents
[hide]

1 Getting Started

o 1.1 Your first Lazarus Program!

o 1.2 Modify your Program

2 The Editor Windows

3 The Main Menu

o 3.1 File

o 3.2 Edit

o 3.3 Search

o 3.4 View

o 3.5 Source

o 3.6 Project

o 3.7 Run

o 3.8 Package

o 3.9 Tools
o 3.10 Window

o 3.11 Help

4 The Button bar

5 The Component Palette

o 5.1 How To Use the Palette

o 5.2 Customization

o 5.3 Examples

6 How to use Common Controls

o 6.1 Ways to Set Properties

o 6.2 Common Properties

o 6.3 Event Actions

o 6.4 Constructors & Destructors

7 Menu controls

o 7.1 TMainMenu

o 7.2 TPopupMenu

o 7.3 Menu editor

o 7.4 ActionList use

8 The Debugger

9 The Lazarus files

10 See also
Getting Started

Get, install and launch Lazarus which will also make the Free Pascal Compiler available.
Note: On Linux Ubuntu at least, the command to start Lazarus from a console is "startlazarus". Otherwise, if you

installed it from a Debian package, you should have a Lazarus menu entry under Application/Programming. (Issue:

In Debian and Ubuntu the main binary and the package was renamed to "lazarus-ide" because the "tct" package

already comes with a utility called "lazarus").

Your first Lazarus Program!


From the Main Menu, choose Project-New Project-Application (or: File-New-Project-Application). A new
GUI application is created, see also Form Tutorial.

Several windows will appear on the desktop: the Main Menu at the top, the 'Object Inspector' on the left,
the 'Source Editor' occupying most of the desktop, and a ready-made 'Form1' window (form1) overlying the
Source Editor.

To place a button on the form: on the top Menu window, underneath the menu line, is a row of tabs. If the
'Standard' tab is not already selected, select it by clicking with the mouse. Then find the Button icon (a
rectangle with 'OK' on it) and click on that with the mouse. Then click on the Form1 window, somewhere to
the left of the middle. A shadowed rectangle labelled 'Button1' will appear. Click again on the Button icon in
the Standard tab, and click on the Form1 somewhere to the right of centre: a second rectangle labelled
'Button2' will appear.

Now click on Button1 to select it. The 'Object Inspector' window will now display the properties of the object
Button1. Near the top is a property named 'Caption', with the displayed value 'Button1'. Click on that box,
and change 'Button1' to 'Press'. If you hit ENTER or click in another box, you will see the label of the first
button on Form1 change to 'Press'. Now click on the Events tab on the Object Inspector, to see the various
events that can be associated with this button1. These include OnClick, OnEnter, OnExit etc. Select the
box to the right of OnClick: a smaller box with three dots (... ellipsis) appears. When you click on this, you
are taken automatically into the Source Editor and your cursor will be placed in a piece of code related to
button1, starting:

procedure TForm1.Button1Click(Sender: TObject);


begin
{now type (or copy&paste):} Button1.caption := 'Press again';
{the editor has already completed the procedure with}
end;

Press F12 to select the Form1 window instead of the Source Editor.

Now edit the properties of Button2: click on Button2 to display its properties in the Object Inspector.
Change its Caption property to 'Exit' instead of 'Button2'. Now select the Events tab, and click on the box
for OnClick. Click on the ... ellipsis, and you will be taken into the Source Editor, in the middle of another
procedure for button2:

procedure TForm1.Button2Click(Sender: TObject);


begin
{now type (or copy&paste):} Close;
{the editor has already completed the procedure with}
end;

Now Press F12 to see the Form1 window again. You should save your work now (and frequently!!) by
selecting from the Main Menu Project-Save Project As > your_selected_file_name.pas. Next, you will be
asked to save a Lazarus Project Information file, with the suffix .lpi. (Note: For Lazarus-0.9.30 you will be
asked for project name first and then file name). Choose a different name for this file, if both are identical
you will get a "duplicate identifier" compile error (see chapter "The Lazarus files" at the end of this tutorial).

You are now ready to try to compile. The simplest way to compile is to select 'Run' from the main menu at
the top, and then the 'Run' option on the sub-menu. Alternatively you could simply press F9. This will first
compile and then (if all is well) link and execute your program.

Several text windows will appear and all sorts of compiler messages will be typed, but eventually your
Form1 window will re-appear, but without the grid of dots; this is the actual main window of your application,
and it is waiting for you to push buttons or otherwise interact with it.

Try clicking on the button labelled 'Press'. You will notice that it changes to 'Press again'. If you press it
again, it will still say 'Press again'!!

Now click on the button marked 'Exit'. The window will close and the program will exit. The original Form1
window with the grid of dots will reappear, ready to accept more editing activity.

Modify your Program


Re-open your saved Project and on the Form1 window click on the 'Press' button (Button1) to select it.
Select the 'Events' tab on the Object Inspector, click on the right side box next to OnClick, click on the ...
ellipsis, to go back to the appropriate point in the Source Editor.

Edit your code to read as follows:

procedure TForm1.Button1Click(Sender: TObject);


{ Makes use of the Tag property, setting it to either 0 or 1}
begin
if Button1.tag = 0 then
begin
Button1.caption := 'Press again';
Button1.tag := 1;
end else
begin
Button1.caption := 'Press';
Button1.tag := 0;
end;
end;

Save your work, re-compile and run. The left button will now toggle between two alternative messages.
The rest is up to you!

If you prefer to write Console- or text-based Pascal programs (for example if you are following a basic
Pascal programming course, or you need to write programs to use in batch mode or for system
programming), you can still use Lazarus to edit, compile and run your programs. See Console Mode
Pascal.

The Editor Windows

When you launch Lazarus for the first time, a series of separate disconnected or 'floating' windows will
appear on your desk-top.

The first, running right along the top of the desk-top, is titled project1 - Lazarus IDE vXXXXXX (which will
subsequently be modified to reflect the name of your currently-open project). This is the main controlling
window for your project, and contains the Main Menu and the Component Palette.

On the line below the title bar is the Main Menu with the usual entries for File, Edit, Search, View categories
and so on, with a few selections that are specific to Lazarus. Below this on the left is a set of symbols
(icons which take you rapidly to particular menu commands); and on the right is the Component Palette.

Under the Lazarus Editor window will appear the 'Object Inspector' window on the left, and the Lazarus
'Source Editor' on the right. There may be another smaller window, labelled 'Form1', overlying the Lazarus
Source Editor window. If this is not visible immediately, it can be made to appear by pressing the F12 key,
which toggles between the Source Editor view and the Form view. The Form window is the one on which
you will construct the graphical interface for your application, while the Source Editor is the window which
displays the Pascal code associated with the application which you are developing. The operation of the
Object Inspector is discussed in more detail below while the Component Palette is described. Finally, there
may also be a Message window in the lower of the screen: this one is used by Lazarus to show feedback to
the programmer, for instance when compiling a program.

When you start a new project (or when you first launch Lazarus) a default Form will be constructed, which
consists of a box in which there is a grid of dots to help you to position the various components of the form,
and a bar along the top which contains the usual Minimise, Maximise and Close buttons. If you click with
your mouse cursor anywhere in this box, you will see the properties of this form displayed in the Object
Inspector on the left side of the desk-top.
Other windows that may become visible during your work: the 'Project Inspector', which contains details of
the files included in your project, and allows you to add files to or delete files from your project;
the Messages window, which displays compiler messages, errors or progress reports on your project; if
Lazarus was launched from a terminal window, the original terminal remains visible and detailed compiler
messages are also printed there.

The Main Menu

The Lazarus main menu contains the following entries:

File Edit Search View Source Project Run Package Tools Window Help

As usual, the options can be selected either by placing the mouse cursor over the menu option and clicking
the left mouse button, or by typing Alt+F on the keyboard (provided the main menu window has focus: if it
has not, hit Tab repeatedly to cycle focus through the various windows until the desired window has its
title bar highlighted in colour).
File

New Unit: Creates a new Unit file (Pascal Source).

New Form: Creates a new Form: both the visual on-screen window and the associated Pascal
source file.

New ...: Offers a pop-up menu box with a variety of new document types to create.
Open: Offers a pop-up Dialog Box to enable you to navigate the filesystem and choose an existing

file to open.

Revert: Abandon editing changes and restore the file to its original state.

Open Recent: Offers a list of recently edited files, and an opportunity to select one.

Save: Save the current file, using its original filename. If there is no name, the system will prompt

for one (just like Save As).

Save As: Allows you to choose a directory and filename for saving the current file.

Save All: Saves all the files attached to the editor, not just the current one selected.

Export As HTML: Export the contents of the current file to a new file in HTML format.

Close: Closes the current file, prompting whether to save all editor changes.

Close all editor files: Close all files currently open in the editor. Prompt for saving changes.

Clean directory: Offers a dialog with a series of editable filters for removing files from the current

directory. Useful for removing .bak files and remnants of former Delphi projects.

Print: Uses the system printer to print the selected file. This menu item may not appear by default

if you are not using Windows; you will then need to install
$Lazdir/components/printers/design/printers4lazide.pas and re-compile the IDE

Restart: Re-start Lazarus - useful if files have got hopelessly scrambled!

Quit: Exit Lazarus, after prompting for saving all edited files.
Edit
Undo: Undo the last edit action, leaving the Editor in the state just before the last action.

Redo: Re-instates the last action that was reversed by Undo.

Cut: Remove the selected text or other item and place it on the Clipboard.

Copy: Make a copy of the selected text, leaving the original in place, and placing the copy on the
Clipboard.

Paste: Places the contents of the Clipboard at the cursor position. If text has been selected at the
cursor position, the contents of the Clipboard will replace the selected text.

Select: Allows selection of blocks of text. Options include select all, select to brace, select
paragraph or line etc.

Indent Selection: Move the selected text to the right by the amount specified in Environment ->
Editor options -> General -> Block indent. This feature is useful for formatting your Pascal source code
to show the underlying Block structure.
Unindent selection: Removes one level of indenting, moving the text to the left by the amount

specified in Block indent.

Uppercase Selection: Convert selected text to uppercase.

Lowercase Selection: Convert selected text to lowercase.

Swap Case in Selection: Convert selected text to lowercase or uppercase.

Sort selection: Sort lines (or words or paragraphs) alphabetically; options for ascending or

descending order, case sensitive or insensitive. In the middle of program source code, of course, it
makes no sense, but if you have a list you need to have sorted this will do the trick.

Tabs to Spaces in Selection: Converts any tabs in the selected text to the number of spaces

specified by Environment -> Editor options -> General -> Tab widths. The number of spaces is not a
fixed quantity, but is the number needed to fill the remaining width of the tab.

Break Lines in Selection: If any lines in the selected text are longer than 80 characters or the

number specified in Environment -> Editor options -> Display -> Right Margin, then the line is broken
at a word boundary and continued on the next line.

Insert from Character Map: Allows insertion of non-keyboard symbols such as accented

characters, picked from a pop-up character map.


Search
Find: Similar to the facility in almost all graphic text editors: a pop-up dialog box appears allowing
entry of a search text string, with options such as case sensitivity, whole words, origin, scope and
direction of search.

Find Next, Find Previous: Search again for the previously entered text string, in the specified
direction.

Find in Files: Search for text string in files: pop-up dialog with options all open files, all files in
Project, or all directories; masks available for selecting file types.

Replace: Similar to Find; shows pop-up dialog with place to enter search text string and
replacement text, and options for case sensitivity, direction etc.

Incremental Find: Search for the string while you are entering the search string. Example: after
you choose "Incremental Find" if you press "l" the first "l" will be highlighted. If then you press "a", the
editor will find the next "la" and so on.
Goto Line: Move editing cursor to specified line in file.

Jump Back: Jump to previous position. Everytime jumping to an error or find declaration the IDE

saves the current source position. With this function you can jump back in the history.

Jump Forward: Jump to next position. Undoes a Jump back.

Add Jump Point to History: Add the current source position to the jump hsitory.

Jump to Next Error, Jump to Previous Error: Jump to the positions in the source file of the next

or previous reported error.

Set a Free Bookmark: mark the current line where the cursor is located with the next available

(free) numbered bookmark, and add this to the list of bookmarks. Note that a pop-up menu (obtained
by right-clicking with the mouse on the appropriate line of the source file) gives a larger range of
Bookmark options, allowing the number of a bookmark to be specified, or allowing the user to jump to
a numbered bookmark, not just the next or previous ones.

Jump to Next Bookmark, Jump to Previous Bookmark: Jump to next or previous bookmark in

the numerical sequence.

Find Other End of Code Block: If positioned on a begin, finds the corresponding end or vice

versa.

Find Code Block Start: Moves to the begin of the procedure or function in which the cursor is

placed.

Find Declaration at Cursor: Finds the place at which the selected identifier is declared. This may

be in the same file or another file already open in the Editor; if the file is not open, it will be opened (so
if a procedure or function is declared, for example, in classesh.inc , this will be opened in the Editor).
(More)

Open Filename at Cursor: Opens the file whose name is selected at the cursor. Useful for looking

at Include files or the files containing other Units used in the project.

Goto Include Directive: If the cursor is positioned in a file which is Included in another file, goes

to the place in the other file that called the Include file.

Find Identifier References: Produces a list of all the lines in the current file, or the current project

or all attached files, in which an identifier is mentioned.


Procedure List: Produces a list of all Procedures and Functions in the current file, with the line

numbers where they are defined.


View

Controls the display of various windows and panels on the screen.

Object Inspector: The window that usually occupies the left side of the Desktop, and displays the

features of the Form which is on the desktop. Clicking with the mouse on any component of the form
will cause the details of that component to be displayed in the Object Inspector. There is a panel at the
top which shows the tree-structure of the current project, and the components of the form may
optionally be selected in this panel: this will also cause the corresponding details to be displayed in the
Object Inspector. The main lower panel has two tabs which allow selection of
either Properties or Events to be displayed. Selection of Properties causes features such as name,
color, caption, font, size etc to be displayed: there are two columns, the left showing the property, and
the right showing the value associated with that property. Selection of Events displays two columns:
the left lists the possible events such as MouseClick or KeyDown associated with that component, and
the right shows the action that results from that event. If there is no action defined, then clicking in the
appropriate box or on the

...
button causes the Source Editor to be displayed, with the cursor already positioned in a dummy
Procedure declaration, waiting for event-defining code to be typed in.

Source Editor: The main window in which source code is edited. Its behaviour is very like that of

most other graphical text editors, so that the mouse can move the cursor over the displayed text, and
clicking with the left mouse button while dragging the mouse will select and highlight text. Right clicking
with the mouse displays a pop-up menu, it includes the usual Edit Cut, Copy or Paste functions, Find
Declaration and Open File at Cursor. The top of the Source Editor window has a number of tabs,
corresponding to the files that are open for the current project; clicking on any tab makes that file
visible, and you can move easily from file to file, copying and pasting between files and performing
most of the normal editing functions. The Source Editor performs color syntax highlighting on the code,
with different colors for punctuation marks, comments, string constants etc. It will also maintain the
level of indentation from line to line as you type in code, until you change the indentation. The function
and appearance of the Source Editor are very configurable from the Main Menu by selecting
Environment -> Editor options and then selecting one of several tabs in the pop-up dialog box.

Code Explorer: A window usually placed on the right of the Desktop which displays, in tree form,

the structure of the code in the current unit or program. It usually opens with just the Unit name and
branches for Interface and Implementation sections, but clicking on the

box to the left of any branch will open up its sub-branches or twigs, in more and more detail until
individual constants, types and variables are displayed as well as procedure and function declarations.
If you change the file displayed in the main Source Editor window, you need to click on the Refresh
button of the Code Explorer to display the structure of the new file.

Units...: Opens a pop-up dialog window with a list of the unit files in the current project.Clicking

with the mouse on a filename selects that file; click on Open to display that file in the Source Editor.
Checking the Multi box allows several files to be selected simultaneously, and they will all be opened in
the Source Editor (but only one at a time will be displayed). This Menu Option is rather like the Project
-> Project Inspector option, but only displays the list of Unit files and allows them to be opened.

Forms...: Opens a pop-up dialog window with a list of the Forms in the current project, and allows

the selection of one or more of them for display.

View Unit Dependencies: Opens a pop-up dialog window that shows, in a tree-like manner, the

structure of dependencies of the currently open unit file. Most of the files listed as dependencies will
have their own
+

boxes, which allow the dependencies of the individual files to be explored, often in a highly recursive
manner.

Toggle form / unit view F12: Toggles whether the Source Editor or the current Form is placed on

the top layer of the Desktop, and given focus. If the Source Editor has focus, then you can edit the
source code; if the Form is given focus, you can manipulate the components on the desktop and edit
the appearance of the Form. The easiest way to toggle the display between Editor and Form is to use
the F12 key on the keyboard, but the same effect is achieved by selecting this option on the Main
Menu.

Messages: A window that displays compiler messages, showing the progress of a successful

compilation or listing the errors found.

Search Results: A window that displays the results of find in files.

Debug windows: Opens a pop-up menu with several options for operating and configuring the

Debugger. See below where the debugger is described.


Source

Comment Selection: Comment out the currently selected text.


Uncomment Selection: Uncomment the currently selected text.

Toggle Comment in Selection: Comment out or uncomment the currently selected text.

Enclose Selection...: Enclose the currently selected text with a statement such as Try...Finally.

Enclose in $IFDEF...: Enclose the currently selected text with an IFDEF (conditional defines)

statement.

Complete Code:

Add Unit to Uses Section: Add one or more Units to the uses section in the current file.

Refactoring: Open the Refactoring sub-menu.

Quick Syntax Check: Run a quick syntax check.

Guess Enclosed Block: Let the editor end the enclosed block, such as a missing "End" in an "If"

statement.

Guess Misplaced IFDEF/ENDIF: Let the editor correct a misplaced conditional defines statement.

Insert CVS Keyword...: Insert a CVS keyword, such as "Author" or "Date".

Insert General: Insert a general value, such as a "GPL Statement".

Insert Full Filename...: Insert the filename.

Insert ToDo: Insert a ToDo comment.

Unit Information...: Display information about the current unit.

Unit Dependencies...: Display the dependencies for the current unit.

JEDI Code Format: View the JEDI Code Format options for the project.
Project
New Project: Create a new project. A pop-up dialog window appears offering a choice of types of

project to create.

New Project from File: A Navigation dialog window appears, alowing selection of a file from which

to create a new project.

Open Project Open a project which has already been created and saved. A navigation dialog

appears with a list of Lazarus Project Information (.lpi) files from which a project may be chosen.

Open Recent Project: Displays a pop-up list of recent projects on which you have been working,

and allows selection of one of these.

Close Project Close the current project.

Save Project: Similar to File -> Save: all the files of the current project are saved; if they have not

previously been saved, there is a prompt for filename(s)- similar to Save Project As...

Save Project As...: Prompts for filename to save project. A default filename of Project1.lpi is

offered, but you should choose your own filename. Lazarus will not permit you to use the same name
for the Project file and the Unit File (see below).

Publish Project: Creates a copy of the whole project. If you want to send someone just the

sources and compiler settings of your code, this function is your friend. A normal project directory
contains a lot of information. Most of it is not needed to be published: the .lpi file contains session
information (like caret position and bookmarks of closed units) and the project directory contains a lot
of .ppu, .o files and the executable. To create a lpi file with only the base information and only the
sources, along with all sub directories use "Publish Project". In the dialog you can setup the exclude
and include filter, and with the command after you can compress the output into one archive.
See Lazarus IDE Tools

Project Inspector: Opens a pop-up dialog with a tree-like display of the files in the current project.

Allows you to add, remove or open selected files, or change options of the project.

Project Options...: Opens a pop-up dialog window with tabs for setting options for Application

(Title, Output Target file name), Forms (allowing you to select among the available forms, make them
Auto-create at start of application) and Info (specifying whether editor information should be saved for
closed files, or only for project files).

Compiler options ...: (Recently moved here from the Run Menu). Opens a multi-page tabbed

window which allows configuration of the compiler. Tabs include Paths which allows definition of
search paths for units, include files, libraries etc, as well as allowing choice of widget type for the forms
(gtk, gnome, win32); Parsing which allows choice of rules for parsing source programs, Code which
allows choice of optimisation for faster or smaller programs, choice of target processor, types of
checks, heap size etc; Linking allowing choice of whether or how to use debugging, static or dynamic
libraries, and whether to pass options through to the linker; Messages to define what type of
messages should be generated during error conditions; Other which allows decision to use default
configuration file (fpc.cfg) or some other file; Inherited which shows a tree structure diagram to
indicate how options have been inherited from units already incorporated; Compilation which allows
definition of commands to be executed before or after the compiler is launched and can allow use of
Make files.

Add Editor File to Project: Add the file currently being edited to the Project

Remove from Project: Gives a pop-up menu of files available for removal from project.

Units...: View a list of all the units in the project.

Forms...: View a list of all the forms in the project.

View Project Source: No matter which file you are editing, takes you back to the main program

file (.lpr)or the main .pas file if there is no .lpr.


Run
Compile: Compiles all the files in the project.

Build: Builds all files in the project.

Quick Compile: Compiles the files in the project that have changed.

Clean up Build Files: Cleans up the build files in the project.

Abort build: Stop the build process once it is running - either you have remembered that you did
something silly and want to stop the build, or the system seems to be taking far too long and
something is obviously wrong.

Run: This is the usual way to launch the compiler and, if compilation is successful, to start
execution of the application. What actually happens is that Lazarus saves a copy of your files, then
starts the compiler and linker, then begins execution of the final linked binary program.

Pause: Suspend execution of the currently running program. This may allow you to inspect any
output that has been generated; execution may be resumed by selecting Run again.
Show Execution Point: Shows the current execution point.

Step Into: Used in conjunction with the debugger, causes execution of the program one step at a

time up to a bookmarked point in the source.

Step Over: Causes stepwise execution up to the statement marked, then skips the marked

statement, and continues execution at normal speed. Useful in trying to isolate a statement that
introduces a logical error.

Step Out: Step out of the current code block.

Run to cursor: Causes execution at normal speed (ie NOT one statement at a time) until either

the statement is reached where the cursor is located or the current procedure is exited; then stops.
Does not stop, if location is reached during recursion. Resume execution at normal speed by
selecting Run.

Stop: Cease execution of the running program. Cannot be resumed by selecting Run; this will

start the program again from the beginning (re-compiling if necessary).

Run Parameters: Opens a multi-page pop-up window which allows command-line options and

parameters to be passed to the program to be executed; allows selection of display to run program (eg
a remote X terminal may be used in Linux); some system Environment variables may be overridden.

One very important use of this sub-menu is to activate a terminal window in which conventional
Pascal console input/output is displayed. If you are developing a console-mode Pascal program (ie
one that doesn't use the Graphical User Interface with its forms, buttons and boxes) then you
should check the box for "Use launching application". The first time you do this and try the
Compile/Run sequence, you will probably get a rude message to say

"xterm: Can't execvp /usr/share/lazarus//tools/runwait.sh: Permission


denied".

If this happens, you need to change the permissions on the appropriate file (for example using
chmod +x filename, or using the Windows utility for changing permissions); you might have to do
this as root. After this, each time you launch you program, a console box will appear and all your
text i/o (readln, writeln etc) will appear in it.

After your program has finished execution, a message "Press enter" appears on the screen. Thus
any output your program generated will remain on the screen until you have had a chance to read
it; after you press 'enter' the console window closes.
Note: as for the current version, there is no prepared console command for Windows users. Until
the Lazarus team adressess that, the following line should work (on WinXP -- someone please
update for other Windows versions).

C:\Windows\system32\cmd.exe /C ${TargetCmdLine}

See the separate tutorial on Console Mode Pascal programming.

Reset debugger: Restores the debugger to its original state, so that

breakpoints and values of variables etc are forgotten.

Build file: Compile (build) just the file that is currently open in the Editor.

Run file: Compile, link and execute just the currently open file.

Configure Build + Run File: Opens a multi-page tabbed window with options

to allow for build of just this file when Build Project is selected, allows selection
of the working directory, the use of various Macros, etc. Then Builds and Runs
the file.

These last three options enable you to open (and maintain) a test project. Use File -> Open to
open an .lpr file, pressing cancel on the next dialog to open this file as "normal source" file.

Inspect...: Inspect a value when the program is paused.

Evaluate/Modify...: Evaluate or modify an expression or value when the

program is paused.

Add Watch...: Add a variable to the watch list.

Add Breakpoint...: Add a breakpoint, which will will pause execution of the

program at that line of code.


Package
New Package...: Create a new package.

Open Loaded Package...: Open one of the files in the selected package.

Open Package File (.lpk)...: Displays a list of installed packages, with an

invitation to open one or more of them, or to select various general or


compiler options.

Open Package of Current Unit: Open the package for the unit currently in

the editor.

Open Recent Package: Open a package that was opened recently.

Add Active File to Package...: Place the file (currently in the editor) into a

package.

New Component: Create a new component.

Package Graph: Displays a showing the relationships of the packages

currently being used (if you aren't using any other packages, the Lazarus
package and the FCL and LCL will be displayed).

Install/Uninstall Packages...: Install or uninstall one or more packages.


Tools
Options...: View and changed the options and settings in the Lazarus IDE.

Re-scan FPC Source directory Looks through the directory again.

Lazarus uses the fpc sources to generate correct event handlers and while
looking for declarations. If somebody changes the directory in the
environment options, then this directory is rescanned, to make sure
Lazarus uses the version stored in that location. But if this directory has
changed without Lazarus noticing, then you may get some errors when
designing forms or doing "Find declaration". If you get such an error, you
can do two things:

1. Check the FPC source directory setting in the environment option.

2. Re-scan FPC source directory.

Code Templates...: View the code templates that are available.

CodeTools Defines Editor...: Edit the code templates.

Project templates options...: Set the options for the project templates.
Configure external tools: Allows the user to add various external tools

(usually macros) to the toolkit

Example Projects...: View the example projects that are available.

Diff: Allows comparison between two files (or, usually, two versions of the

same file) to find differences. Options to ignore white space at beginning or


end of lines or differences in line termination: CR+LF versus LF). Useful for
checking if there have been changes since last CVS update etc.

Leak View: View the heap trace output.

Check LFM File in Editor: Allows inspection of the LFM file which contains

the settings that describe the current form

Convert Delphi Unit to Lazarus Unit: Helps in porting Delphi applications

to Lazarus; makes the necessary changes to the source file. See Lazarus
For Delphi Users and Code Conversion Guide.

Convert Delphi Project to Lazarus Project: For porting from Delphi to

Lazarus: converts a Delphi project to Lazarus.

Convert Delphi Package to Lazarus Package: For porting from Delphi to

Lazarus: converts a Delphi package to Lazarus.

Convert DFM file to LFM: For porting from Delphi to Lazarus: converts the

Form Description files from Delphi to Lazarus.

Convert Encoding of Projects/Packages...:

Build Lazarus with Profile: Normal IDE: Launches a re-build of Lazarus

from the most recently downloaded or updated SVN files. Hit the button
and sit back to watch it happen! (track the process on
your Messages window).

Configure "Build Lazarus": Allows the user to determine which parts of

Lazarus should be re-built, and how. For example, you could select to have
just the LCL re-built, or to have everything except the examples built; you
can select which LCL interface to use (ie which set of widgets), and you
can select the target operating system and specify a different target
directory.
Window

Contains a list of the currently opened files and the available windows such
as Source Editor, Object Inspector and Project Inspector. Clicking on the
name of one of the windows brings it to the foreground and gives it focus.
Help

At present this has three selections:

Online Help which at present opens a browser window that contains a

picture of the running cheetah and a few links to the Lazarus, Free Pascal
and Wiki websites

Reporting a bug opens the wiki page, which describe the bug reporting

procedure

About Lazarus Displays a pop-up box with some information about

Lazarus.

Help can be configured with [Tools|Options|Help]

The Button bar

A small toolbar area on the left of the main editor window, just below the Main
Menu and to the left of the Component Palette, contains a set of buttons which
replicate frequently-used Main Menu selections:

New unit, Open (with a down-arrow to display a drop-down list of recently used files), Save, Save
all, New Form, Toggle Form/Unit (ie show either form or source code of Unit), View Units, View
Forms, Run (ie compile and Run), Pause, Step Into, Step over (the last two are Debugger
functions).
The Component Palette
The Component Palette of the IDE is a tabbed toolbar which displays a
large number of icons representing commonly used components for
building Forms.

Component Palette

Standard - Additional - Common Controls - Dialogs - Data Controls - Data


Access - System - Misc - LazControls - RTTI - SQLdb - Pascal Script - SynEdit - Chart - IPro

Each tab causes the display of a different set of icons, representing a


functional group of components. The left-most icon in each tabbed group is
an obliquely leftward-facing arrow, called the Selection Tool.

If you allow the mouse cursor to hover over any of the icons on the
Component Palette, without clicking on the icon, the title of that component
will pop-up. Note that each title begins with a 'T' - this signifies 'Type' or
more accurately 'Class' of the component. When you select a component
for inclusion in a form, the Class is added to the type section of
the interface part of the Unit (usually as part of the overall TForm1), and
an instance of that class is added to the var section (usually as the
variable Form1). Any Methods that you design to be used by the Form or
its Components (ie Procedures or Functions) will be placed in
the implementation part of the Unit.
How To Use the Palette

To use the palette, there must be an open form on view in the editor (if
there isn't one, select File -> New Form). Click on the icon in the
appropriate tab of the palette for the component you want to use, then click
on the form, near where you want the component to appear. When the
desired component appears, you can select it by clicking with the mouse.
Once selected on the form, the object is also selected in the Object
Inspector window, where you can edit its properties and events.

Adjustments to the visual appearance of an object can be made either by


altering the picture itself on the Form using the mouse, or by changing the
relevant Property in the Object Editor for that component.
If you install additional components, either those you have written yourself,
or some coming as a package from some other source, then extra tabs
with the relevant icons will appear in your Component Palette. These new
components can be selected and used on your forms in the same way as
those supplied by default.

In the following list of the Components, you will find links to files that
contain descriptions of the Units in which they are found. If you want to find
out about the properties of a particular component, it is often worth looking
at the Inheritance of that component and then inspecting the properties of
the base type from which it is derived. For example, to
understand TMaskEdit it is also useful to examine TCustomMaskEdit.

Customization
Using the menu [Tools|Options] or Crtl-Shift-O it is possible to change layout
and visibility of the component palette items.

Examples
Several useful dialog procedures or functions don't appear on the palette,
but are easily used as direct calls from your source program.

For several good examples of the use of Components see the


$LazarusPath/lazarus/examples subdirectory of your source installation.
Many of the programs show how to use dialogs and other components
directly without using the IDE and component palette or having a separate
form definition file: all the components are fully and explicitly defined in the
main Pascal program. Other example programs make full use of the IDE.

Remember to open these examples as projects, with the .lpi file. Opening
the .pas source code file and hitting RUN will just append this source file to
whatever project you opened last.

Some examples don't work straight away: you may need to play about with
paths and permissions of files or directories. If you want to compile any of
the examples, make sure that you have read/write/execute permissions for
the files and directories, or copy the files to a directory where you do have
the appropriate permissions.

Try running the 'testall' program to see a menu of the available components
together with small example test forms for most of them; then inspect the
code to find out how they work!

How to use Common Controls

The Units StdCtrls, ComCtrls and ExtCtrls contain definitions and


descriptions of many of the most commonly used controls for constructing
Forms and other Objects in Lazarus Applications.

Many of the final target controls that the application developer wants to
use, such as TButton, TMemo, TScrollBar etc, have a corresponding
ancestor class such
as TCustomButton, TCustomMemo or TCustomScrollBar. Several of
the properties and methods relevant to the final target control are defined
(and explained) more fully in the TCustomXXX class, and are inherited by
the final target control.

If you drop a component on the form editor you don't need to add code
explicitly to create it. The component is automatically created by the IDE
together with the form, and destroyed when the form is destroyed.
However, if you create the component yourself by code don't forget to free
it when it is no longer needed.
Ways to Set Properties

If you place a component on the Form Designer and look at the Object
Inspector, you can observe the properties change as you move the
component around.

For example, if you place a button (TButton) on the form, click on it to


select it, then move it around the form with the mouse, you can watch the
values of Top and Left change in the Object Inspector to reflect the new
position. If you use the object's re-sizing bars to adjust its size, you can
watch the Height and Width properties change as well.

On the other hand, by using the Object Inspector, you can select the value
associated with a property such as height, and type in a new value; you
can watch the size of the object on the form change to reflect the new
value.

You can also explicitly change the properties of the object in code by typing
(in the appropriate Implementation section of the Source editor), for
example

Form1.Button1.Height := 48; If you type this new value into the


Source Editor and then look back at the Form Designer, you will see that
the button on the Form has taken the new size. The new value will also be
shown in the Object Inspector.

In summary, there are usually about three different ways to determine each
property of an object:

by using the mouse on the form,

by setting the values in the Object Inspector,

or explicitly by writing code in the editor.


Common Properties

The components defined in these Units have several properties that are
common to most of them, and other properties that are specific to the
individual components. We shall describe the most common ones here.
Unusual or control-specific properties will be described for the individual
controls.

Additional Help can always be obtained by selecting a property or keyword,


in either the Object Inspector or the Source Editor, and pressing F1. You will
be taken by your Help browser to the appropriate page in the
documentation.

If the description of a property on that page is insufficient, you can navigate


to the corresponding description in the ancestor classes, by selecting the
links in the Inheritance listing or by selecting the ancestor Type in the
declaration of the object.

Some commonly listed properties


Property Meaning
The main action or event associated with the object. For example selecting an '
Action
might cause the 'Close' action
Defines the way in which an object is to be lined up with the parent object. Pos
are alTop (placed at the top and using the full available width), alBottom, alLef
Align
left and using the full available height), alRight. alNone (place anywhere on pa
alClient (takes all available space next to controls aligned to top, bottom, left o
Used to keep a control a certain distance from the defined edges of a parent con
Anchor parent is resized. For example [akBottom, akRight] will keep the control a fix
from the bottom right corner.
When True, an editing control will select all its text when it receives focus or w
AutoSelect
key is pressed.
True indicate that the edit or combobox control has just performed an AutoSele
AutoSelected
that subsequent mouse-clicks and keystrokes proceed normally without selectin
BorderSpacing The space around the edge between an Anchored control and its parent.
The text that is displayed on or near the control; it should preferably give some
function of the control, or an instruction such as 'Close' or 'Execute'. By defaul
Caption
to be the same as the 'Name' property, and the application programmer should s
meaningful text instead of the default values.
Indicates how text is displayed in a text editing control: Normal (retaining the c
CharCase
letters typed by the user), converted to uppercase, or converted to lowercase
Sets the minimum and maximum sizes for a control. If a control is resized the n
Constraints dimensions are always within the ranges given here. You should take care when
options that they do not conflict with the Anchors and Align settings.
Color The Colour to be used to draw the control or to write the text it contains.
A Boolean property to determine whether or not a control is capable of being s
Enabled
performing an action. If it is not Enabled, it is often Grayed out on the Form.
The Font to be used for writing the text associated with the control - either the
label, or the text-strings contained within the control. The entry on the Object I
Font
usually has a (+) box on the left, and selecting this box reveals further options
character set, colour and size.
A short piece of informative pop-up text that appears if the mouse-cursor hover
Hint
control. See the ShowHint property.
The list of 'Things' that the object contains, such as a group of images, a series
Items
a number of actions in an actionlist, etc
An array of strings, containing the textual data in controls with more than a sin
Lines such as an Edit-Box or a Combo-Box. The array is zero-indexed, ie the lines ar
[0..numLines-1]
The identifier by which the control is known in the program. The IDE gives it a
based on the underlying type, for example successive instances of TBitButton w
named Form1.BitBitton1 and Form1.BitButton2; it is up to the application pro
Name
give them more meaningful names such as ExitButton or OKButton. By defaul
the control is applied to the Caption for the control, but the text of the Caption
changed separately.
A window containing context-sensitive menu information that pops up when th
PopUpMenu
button is clicked on the object.
Position (or Top, Left) Determines where the control is located on the parent form or window
Boolean property which, if True, signifies that the contents of the control can b
ReadOnly
user or the calling routine, but cannot be written or changed.
Allows a small window containing a context-sensitive Help or other descriptio
ShowHint
displayed when the mouse cursor 'hovers' over the control. See the Hint proper
Size (or Height and
The dimensions of the control
Width)
The options available for Style depend upon the sort of Control being consider
Style
the Style may be defined by TFormStyle, TBorderStyle, TButtonStyle etc.
TabOrder Integer defining where in the sequence of tabs on the Form this control is to lie
Boolean property which if True places this control in the sequence of objects th
TabStop
reach by successively pressing the Tab key
The String of Text that represents the actual data that this control contains. App
particularly to Text, Memo and StringList types of object. Most of the editing o
(such as Select, Clear, Cut, Copy) are performed in this part of the object, wh
Text
actual string being edited. If the control contains more than a single line of text
example TMemo or TComboBox, then the textual elements are arranged as an
strings (zero-indexed, ie numbered from [0..numLines-1]) in Lines.
Visible If true, the object can be seen on the Form; if False, object is hidden
Logical flag to show whether or not word-wrap is enabled, ie if a word comes
WordWrap
of a line and is going to be too long for the line, it is wrapped down to the next
Event Actions

Many actions are commonly listed in the 'Events' tab of the Object
Inspector. If you select an entry in the list, a ComboBox appears with a
DropDown list showing any actions that have aleady been defined, and
allowing you to choose one to be associated with this event. Alternatively
you can select the ellipsis (three dots ...) and you will be taken to an area of
the Source Editor where you can begin typing your own action instructions
for the selected event.

While a large number of events is available for any given control, in


practice it is only necessary to populate a few of them. For most controls, it
is sufficient to provide coding for 'OnClick'; for more complex controls it
may be necessary also to provide for 'OnEntry' (when the mouse cursor
enters the Control and gives it focus) and 'OnExit' (when the mouse cursor
leaves the Control; or you may need to write an event handler for
'OnChange' or 'OnScroll', depending on the nature of the particular control
with which you are dealing.

The pop-up menu that appears when you right-click an object in the Form
Designer has, as its first item: 'Create default event' and selecting this
option will have the same effect as selecting the ellipsis in the Object
Inspector for the default event, usually OnClick: you are taken to the
Implementation area of the Source Editor where you can type the code for
the event handler.

A common strategy in Object-Oriented programming is to provide


an ActionList with the facility for entering, removing or editing a number of
pre-defined actions from which the most appropriate can be selected to use
in any particular instance.
Some commonly listed Actions
Action Meaning
Action to be taken if any change is detected (eg mouse move, mouse click, key
OnChange
text, alter picture, etc)
Action to be taken when the (first, usually left) mouse button is clicked. This is
main or default action of the control; for example clicking on a button or check
OnClick
the action associated with the checkbox. It may alternatively initate a process o
instance in a TextBox or Memo, or signal the beginning of painting with a Pen
A method to emulate in code the effect of clicking on a control. This method is
found in Button-type controls (TButton, TBitBtn, TSpeedButton etc). A proced
written that calls the same code as the OnClick action. This facility can be part
Click
if the activation of one control by clicking causes a cascade of other controls to
and the Click method can be used to initiate the action rather than having the u
click on a lot of controls.
Action to be taken during Drag-Drop manoeuvres, ie when the mouse is used t
OnDragDrop
item or some text etc and move it around the screen to a new location.
Action to be taken when the user has finished all edits/modifications to the con
OnEditingDone
often used to validate the control content (e.g. check if an entered text is a valid
Action to be taken when the mouse cursor enters the area occupied by the obje
OnEntry transfering focus to that object. This might include changes in the appearance o
such as highlighting or raising the border.
Action to be taken when the mouse moves out of the area of the object, usually
OnExit
focus out of the object.
Action to be taken for any key-press. Subtly different from OnKeyDown, whic
OnKeyPress responds to a key being down, whether or not it was already down when focus
this control. OnKeyPress requires that a key becomes pressed while focus is in
Action to be taken if a key is down while focus is in this control. Subtly differe
OnKeyDown OnKeyPress - for example the key might already have been down when focus
control, whereas OnKeyPress requires the key to become pressed while focus i
OnKeyUp Action to be taken if a key is up (ie not pressed) while focus is in this control.
OnMouseMove Action to be taken if the mouse cursor moves while focus is in this control.
OnMouseDown Action to be taken if the mouse button is down while focus is in this control.
Action to be taken if the mouse button is up while the cursor is over this contro
the mouse button was previously down and has been released. The case where
OnMouseUp
enters the control but the mouse button has not yet been pressed is covered by
OnMouseEnter.
Action to be taken when the control is resized. Might include re-alignment of t
OnResize
of a different font size etc.
Constructors & Destructors

These are two special methods associated with each control:

Constructors: such as Create allocate memory and system


resources needed by the object. They also call the constructor of any
sub-objects present in the class.

Destructors: remove the object and de-allocate memory and other


resources. If you call Destroy for an object which hasn't being
initialized yet it will generate an error. Always use the Free method to
deallocate objects, because it checks whether an object's value
is nil before invoking Destroy.
Take the following precautions when creating your own Destroy method:

Declare Destroy with the override directive, because it is

a virtual method.

Always call 'inherited Destroy;' as the last thing on the destructor

code

Be aware that an exception may be raised on the constructor in

case there is not enough memory to create an object, or something


else goes wrong. If the exception is not handled inside the
constructor, the object will be only partially built. In this
case Destroy will be called when you weren't expecting it, so your
destructor must check if the resources were really allocated before
disposing of them.

Remember to call Free for all objects created on the constructor.


Menu controls

Hints for creating menus for your forms.

TMainMenu
TMainMenu is the Main Menu that appears at the top of most forms; form
designers can customise by choosing various menu items.

TMainMenu is a non-visual component: that is, if the icon is selected from


the Component Palette and placed on the form, it will not appear at run
time. Instead, a menu bar with a structure defined by the Menu Editor will
appear.

TPopupMenu
TPopupMenu is a menu window that pops up with pertinent, usually
context-sensitive, details and choices when the right mouse button is
clicked on a control if the popupmenu is linked to the PopupMenu property
of that component, thus providing a context sensitive menu for that
component.

Menu editor
To see the Menu Editor, right-click on the Main Menu or Popup Menu icon
on your Form. A pop-up box appears that invites you to enter items into the
Menu bar.
An edit box is displayed, containing a button labeled "New Item1". If you
right-click on that box, a pop-up menu is displayed that allows you to add a
new item before or after (along the same level) or create a sub-menu with
the opportunity to add further items below (or above) the new item in a
downward column.

Any of the TMenuItems that you add can be configured using the Object
Inspector.

At the least you should give each item a Caption which will appear on the
Menu Bar. The caption should indicate the activity to be selected, such as
"File Open" or "Close", "Run" or "Quit". You may also wish to give it a more
meaningful Name.

If you want a particular letter in the Caption to be associated with a shortcut


key, that letter should be preceded by an ampersand (&). The Menu item at
run-time will appear with the shortcut letter underlined, and hitting that letter
key will have the same effect as selecting the menu item. Alternatively you
can choose a shortcut key sequence (such as Ctrl+C for Copy or Ctrl+V for
Paste - the standard keyboard shortcuts) with the ShortCut property of
the TMenuItem.

ActionList use
It is often helpful to use the Menu controls in conjunction with
a TActionList which contains a series of standard or customised TActions.
Menu items can be linked in the Object Inspector to actions on the list, and
the same actions can be linked
to TButtons, TToolButtons, TSpeedButtons etc. It is obviously more
efficient to re-use the same code to respond to the various events, rather
than writing separate OnClick event handlers for each individual control.

By default, a number of standard actions are pre-loaded from StdActns or,


if DataAware controls are used, from DBActns. These actions can be
chosen using the ActionList editor which appears when you right-click on
the TActionList icon on the Form Designer.

The Debugger
Still to be written.

1) Make sure you read the setup: Debugger_Setup

2) See also category: IDE Window - Debug


3) Read
limitations: GDB_Debugger_Tips#Inspecting_data_types_.28Watch.2F
Hint.29 This page also helps with some platform/version specific
issues

The Lazarus files

(Thanks to Kevin Whitefoot.)


(Additions by Giuseppe Ridin, User:Kirkpatc
and Tom Lisjac)

When you save you will actually be saving two files:

xxx.pas and yyy.lpr

(You save more than that but those are the ones you get to name).
The project file (lpr) and the unit file (pas) must not have the same
name because Lazarus will helpfully rename the unit (inside the
source code) to the same as the unit file name and the program to the
name of the project file (it needs to do this or the compiler will probably
not be able to find the unit later when referred to in the project file). Of
course to be consistent it changes all the occurrences of unit1 to xxx.

So if you are saving a project called again, trying to save again.pas


and again.lpr fails because unit names and program names are in the
same name space resulting in a duplicate name error.

So here is what I ended up with:

e:/lazarus/kj/lazhello:

total 4740 free 76500


-rwxrwxrwx 1 kjwh root 4618697 Mar 24
11:19 again.exe
-rw-rw-rw- 1 kjwh root 3002 Mar 24
11:21 again.lpi
-rw-rw-rw- 1 kjwh root 190 Mar 24
11:18 again.lpr
-rw-rw-rw- 1 kjwh root 506 Mar 24
11:08 againu.lfm
-rw-rw-rw- 1 kjwh root 679 Mar 24
11:08 againu.lrs
-rw-rw-rw- 1 kjwh root 677 Mar 24
11:08 againu.pas
-rw-rw-rw- 1 kjwh root 2124 Mar 24
11:08 againu.ppu
-rwxrwxrwx 1 kjwh root 335 Mar 24
11:07 ppas.bat

Note that there are many more files than the two that I thought I was
saving.

Here is a brief note about each file:

again.exe: The main program binary executable. Win32 adds an "exe"


extension. Linux has none (just the name of the program). This file will
be huge in Linux due to the inclusion of debugging symbols. Run the
"strip" utility to remove them and substantially shrink the executable
size.

again.lpi: (Lazarus Project Information). This is the main information


file of a Lazarus project; the equivalent Delphi main file of an
application will be the .dpr file. It is stored in an XML format and
contains instructions about all the libraries and units required to build
the executable file.

again.lpr: The main program source file or master file. Despite its
Lazarus specific extension it is in fact a perfectly normal Pascal source
file. It has a uses clause that lets the compiler find all the units it
needs. Note that the program statement does not have to name the
program the same as the file name. This file is usually fairly small, with
just a few statements to initialise, build the forms, run and close the
application. Most of the work is done in the unit source files, with suffix
'.pas'

againu.lfm: This is where Lazarus stores the layout of the form unit, in
human readable form. It reflects the properties of the various
components, as set in the Object Inspector. Each object description
starts with a line:

object xxxx
then there follows a list of properties
(including embedded or nested objects) then an
end

line. Lazarus uses this file to generate a resource file (.lrs) that is
included in the initialisation section of the againu.pas unit. Delphi dfm
files can be converted to lfm format in the Lazarus IDE using the Tools-
>Convert DFM file to LFM utility.

againu.lrs: This is the generated resource file which contains the


instructions to the program for building the form (if you look in the main
Unit file, you will see in the initialization section the line

{$i againu.lrs}

which instructs the program to load the resource file). Note that it is not
a Windows resource file.

againu.pas: The unit that contains the code for the form; this is
usually the only file that the application programmer needs to edit or
inspect, and contains any code specifically supplied by the
programmer (especially event handlers).

againu.ppu: This is the compiled unit which gets linked into the
executable file together with any other units named in the Uses
section.

ppas.bat: This is a simple script that links the program to produce the
executable. If compilation is successful, it is deleted by the compiler.

See also

Lazarus IDE Tools


Deutsch (de) English (en) espaol (es) suomi (fi) franais (fr) (ja) (ko) Nederlands (nl) portugu

s (pt) (ru) slovenina (sk) (zh_CN)

The Lazarus IDE Tools is a library of Free Pascal source parsing and editing tools, called the "codetools".

These tools provide features like Find Declaration, Code Completion, Extraction, Moving
Inserting and Beautifying Pascal sources. These functions can save a lot of time and duplicated work. They
are customizable, and every feature is available via shortcuts (see Editor Options).

Because they work solely on Pascal sources and understand FPC, Delphi and Kylix code, they do not
require compiled units or an installed Borland/Embarcadero compiler. Delphi and FPC code can be edited
at the same time, with several Delphi and FPC versions. This makes porting Delphi code to FPC/Lazarus
much easier.
Contents
[hide]
1 Summary Table of IDE shortcuts

2 Method Jumping

3 Include Files

4 Code Templates

5 Parameter Hints

6 Incremental Search

o 6.1 Hint: Quick searching an identifier with incremental search

7 Syncro Edit

8 Find next / previous word occurrence

9 Code Completion

o 9.1 Class Completion

o 9.2 Forward Procedure Completion

o 9.3 Event Assignment Completion

o 9.4 Variable Declaration Completion

o 9.5 Procedure Call Completion

o 9.6 Reversed Class Completion

o 9.7 Comments and Code Completion

o 9.8 Method update

10 Refactoring

o 10.1 Invert Assignments

o 10.2 Enclose Selection

o 10.3 Rename Identifier


o 10.4 Find Identifier References

o 10.5 Show abstract methods

o 10.6 Extract Procedure

11 Find Declaration

o 11.1 Hints

12 Identifier Completion

o 12.1 Matching only the first part of a word

o 12.2 Keys

o 12.3 Methods

o 12.4 Properties

o 12.5 Uses section / Unit names

o 12.6 Statements

13 Word Completion

14 Goto Include Directive

15 Publish Project

16 Hints from comments

o 16.1 Comments shown in the hint

o 16.2 Comments not shown in the hint

17 Quick Fixes
Summary Table of IDE shortcuts
Declaration Jumping Ctrl+Click or Alt+ (jump to declaration of type or variable)
Method Jumping Ctrl+ Shift+ (toggle between definition and body)
Code Templates Ctrl+J
Syncro Edit Ctrl+J (while text is selected)
Code Completion (Class Completion) Ctrl+ Shift+C, Ctrl+ Shift+X for creating class fields instead of local variables
Identifier Completion Ctrl+space
Word Completion Ctrl+W
Parameter Hints Ctrl+ Shift+space
Incremental Search Ctrl+E
Rename Identifier Ctrl+ Shift+E

Method Jumping

To jump between a procedure body (begin..end) and the procedure definition (procedure Name;)
use Ctrl+ Shift+.

For example:

interface

procedure DoSomething; // procedure definition

implementation

procedure DoSomething; // procedure body


begin
end;

If the cursor is on the procedure body and Ctrl+ Shift+ is pressed, the cursor will jump to the definition.
Pressing Ctrl+ Shift+ again will jump to the body, after 'begin'.

This works between methods (procedures in classes) as well.

Hints: 'Method Jumping' jumps to the same procedure with the same name and parameter list. If there is no
exact procedure, it jumps to the best candidate and positions the cursor on the first difference. (For
Delphians: Delphi can not do this).

For example a procedure with different parameter types:

interface

procedure DoSomething(p: char); // procedure definition

implementation

procedure DoSomething(p: string); // procedure body


begin
end;

Jumping from the definition to the body will position the cursor at the 'string' keyword. This can be used for
renaming methods and/or changing the parameters.

For example:
You renamed 'DoSomething' to 'MakeIt':

interface

procedure MakeIt; // procedure definition


implementation

procedure DoSomething; // procedure body


begin
end;

Then you jump from MakeIt to the body. The IDE searches for a fitting body, does not find one, and hence
searches for a candidate. Since you renamed only one procedure there is exactly one body without
definition (DoSomething) and so it will jump to DoSomething and position the cursor right on
'DoSomething'. Then you can simply rename it there too. This works for parameters as well.

Include Files

Include files are files inserted into sources with the {$I filename} or {$INCLUDE filename} compiler
directive. Lazarus and FPC often uses include files to reduce redundancy and avoid unreadable {$IFDEF}
constructs, needed to support different platforms.

Contrary to Delphi, the Lazarus IDE has full support for include files. You can for example jump from the
method in the .pas file to the method body in the include file. All codetools like code completion consider
include files as special bounds.

For instance: When code completion adds a new method body behind another method body, it keeps them
both in the same file. This way you can put whole class implementations in include files, as the LCL does
for nearly all controls.

But there is a trap for newbies: If you open an include file for the first time and try method jumping or find
declaration you will get an error. The IDE does not yet know to which unit the include file belongs. You must
open the unit first.

As soon as the IDE parses the unit, it will parse the include directives there and the IDE will remember this
relationship. It saves this information on exit and on project save to ~/.lazarus/includelinks.xml. The next
time you open this include file and jump or do a find declaration, the IDE will internally open the unit and the
jump will work. You can also hint the IDE by putting

{%mainunit yourunit.pas}

at the top of yourinclude.inc.

This mechanism has limits. Some include files are included twice or more. For example:
lcl/include/winapih.inc.

How you will jump from the procedure/method definitions in this include file to their bodies will depend on
your last action. If you worked on lcl/lclintf.pp the IDE will jump to winapi.inc. If you worked on
lcl/interfacebase.pp, then it will jump to lcl/include/interfacebase.inc (or one of the other include files). If you
are working on both, then you can get confused. ;)

Code Templates
Code Templates converts an identifier into a text or code fragment.

Code Templates default short cut is Ctrl+J. You can type an identifier, press Ctrl+J and the identifier is
replaced by the text defined for the identifier. Code Templates can be defined in Tools -> Options ->
CodeTools.

Example: Write the identifier 'classf', leave the cursor right behind the 'f' and press Ctrl+J. The 'classf' will be
replaced by

T = class(T)
private

public
constructor Create;
destructor Destroy; override;
end;

and the cursor is behind the 'T'. You can get the list of templates by positioning the cursor on space (not on
an identifier) and pressing Ctrl+J. The list of code templates will pop up. Use the cursor keys or type some
chars to choose one. Return creates the selected template and Escape closes the pop up.

The biggest time savers are templates 'b'+Ctrl+J for begin..end.

Parameter Hints

Parameter Hints shows a hint box with the parameter declarations for the current parameter list.

For example

Canvas.FillRect(|);

Place the cursor in the brackets and press Ctrl+ Shift+space. A hint box will show up showing the parameters
of FillRect.

Since 0.9.31 there is a button to the right of each declaration to insert the missing parameters.This will copy
the parameter names from the chosen declaration to the cursor position.

Hint: Use the Variable Declaration Completion to declare the variables.

Note: The short cut's name is "Show code context".


Incremental Search

Incremental Search changes the statusbar of the source editor. Type some characters and the editor will
search and highlight immediately all occurrences in the text. Shortcut is Ctrl+e.

For example pressing e will search and highlight all occurrences of 'e'.

Then pressing t will search and highlight all occurrences of 'et' and so forth.

You can jump to the next with F3 (or Ctrl+e while in search) and the previous with Shift+F3.

Backspace deletes the last character

return stops the search without adding a new line in the editor.

You can resume the last search by pressing Ctrl+e a second time, immediately after you started

incr-search with Ctrl+e. that is while the search term is still empty.

Paste Ctrl+V will append the text from the clipboard to the current search text (since lazarus 0.9.27

r19824).
Hint: Quick searching an identifier with incremental search

Place text cursor on identifier (do not select anything)

Press Ctrl+C. The source editor will select the identifier and copy it to the clipboard

Press Ctrl+E to start incremental search

Press Ctrl+V to search for the identifier (since 0.9.27)

Use F3 and Shift+F3 to quickly jump to next/previous.

Use any key (for example cursor left or right) to end the search
Syncro Edit
Syncro Edit allows you to edit all occurrences of a word at the same time (synchronized). You simple edit
the word in one place, and as you type, all other occurrences of the word are updated too.

Syncro Edit works on all words in a selected area:

Select a block of text


press Ctrl+J or click the icon in the gutter. (This only works, if there are any words that occur more

than once in the selection.

use the Tab key to select the word you want to edit (if several different words occurred more than

once)

Edit the word

Press Esc to finish

See an animated example here

Note: Ctrl+J is also used for template edit. It switches its meaning if you select some text.

Find next / previous word occurrence


The two functions can be found in the popup menu of the source editor

Source editor / popup menu / Find / Find next word occurrence

Source editor / popup menu / Find / Find previous word occurrence

And you can assign them shortcuts in the editor options.

Code Completion
Code Completion can be found in the IDE menu Edit -> Complete Code and has as standard short
cut Ctrl+ Shift+C.

For Delphians: Delphi calls "code completion" the function showing the list of identifiers at the current
source position (Ctrl+Space). Under Lazarus this is called "Identifier completion".

Code Completion combines several powerful functions. Examples:

Class Completion: completes properties, adds/updates method bodies, add private variables and
private access methods

Forward Procedure Completion: adds procedure bodies

Event Assignment Completion: completes event assignments and adds method definition and
body

Variable Declaration Completion: adds local variable definitions

Procedure Call Completion: adds a new procedure


Reversed procedure completion: adds procedure declarations for procedure/function bodies

Reversed Class Completion: adds method declarations for method bodies

Which function is used, depends on the cursor position in the editor and will be explained below.

Code Completion can be found in the IDE menu Edit -> Complete Code and has as standard short
cut Ctrl+ Shift+C.

Class Completion
The most powerful code completion feature is "Class Completion". You write a class, add the methods and
properties and Code Completion will add the method bodies, the property access methods/variables and
the private variables.

For example: Create a class (see Code Templates to save you some type work):

TExample = class(TObject)
public
constructor Create;
destructor Destroy; override;
end;

Position the cursor somewhere in the class and press Ctrl+ Shift+C. This will create the method missing
bodies and move the cursor to the first created method body, so you can just start writing the class code:

{ TExample }

constructor TExample.Create;
begin
|
end;

destructor TExample.Destroy;
begin
inherited Destroy;
end;

Note: The '|' is the cursor and is not added.

Hint: You can jump between a method and its body with Ctrl+ Shift+.

You can see, that the IDE added the 'inherited Destroy' call too. This is done, if there is an 'override'
keyword in the class definition.

Now add a method DoSomething:

TExample = class(TObject)
public
constructor Create;
procedure DoSomething(i: integer);
destructor Destroy; override;
end;

Then press Ctrl+ Shift+C and the IDE will add

procedure TExample.DoSomething(i: integer);


begin
|
end;

You can see, that the new method body is inserted between Create and Destroy, exactly as in the class
definition. This way the bodies keep the same logical ordering as you define. You can define the insertion
policy in Tools > Options -> Codetools -> Code Creation.

Complete Properties
Add a property AnInteger:

TExample = class(TObject)
public
constructor Create;
procedure DoSomething(i: integer);
destructor Destroy; override;
property AnInteger: Integer;
end;

Press Ctrl+ Shift+C and you will get:

procedure TExample.SetAnInteger(const AValue: integer);


begin
|if FAnInteger=AValue then exit;
FAnInteger:=AValue;
end;

The code completion has added a Write access modifier and added some common code. Jump to the
class with Ctrl+ Shift+ to see the new class:

TExample = class(TObject)
private
FAnInteger: integer;
procedure SetAnInteger(const AValue: integer);
public
constructor Create;
procedure DoSomething(i: integer);
destructor Destroy; override;
property AnInteger: integer read FAnInteger write SetAnInteger;
end;

The property was extended by a Read and Write access modifier. The class got the new section 'private'
with a Variable 'FAnInteger' and the method 'SetAnInteger'. It is a common Delphi style rule to prepend
private variables with an 'F' and the write method with a 'Set'. If you don't like that, you can change this in
Tools -> Options > Codetools -> Code Creation.

Creating a read only property:

property PropName: PropType read;

Will be expanded to

property PropName: PropType read FPropName;

Creating a write only property:

property PropName: PropType write;

Will be expanded to

property PropName: PropType write SetPropName;

Creating a read only property with a Read method:

property PropName: PropType read GetPropName;

Will be kept and a GetPropName function will be added:

function GetpropName: PropType;

Creating a property with a stored modifier:

property PropName: PropType stored;

Will be expanded to

property PropName: PropType read FPropName write SetPropName stored


PropNameIsStored;

Because stored is used for streaming read and write modifiers are automatically added as well.

Hint: Identifier completion also recognizes incomplete properties and will suggest the default names. For
example:

property PropName: PropType read |;

Place the cursor one space behind the 'read' keyword and press Ctrl+Space for the identifier completion. It
will present you the variable 'FPropName' and the procedure 'SetPropName'.

Forward Procedure Completion


"Forward Procedure Completion" is part of the Code Completion and adds missing procedure bodies. It is
invoked, when the cursor is on a forward defined procedure.

For example: Add a new procedure to the interface section:

procedure DoSomething;

Place the cursor on it and press Ctrl+ Shift+C for code completion. It will create in the implementation
section:

procedure DoSomething;
begin
|
end;

Hint: You can jump between a procedure definition and its body with Ctrl+ Shift+.

The new procedure body will be added in front of the class methods. If there are already some procedures
in the interface the IDE tries to keep the ordering. For example:

procedure Proc1;
procedure Proc2; // new proc
procedure Proc3;

If the bodies of Proc1 and Proc3 already exists, then the Proc2 body will be inserted between the bodies of
Proc1 and Proc3. This behaviour can be setup in Tools -> Options -> Codetools -> Code Creation.

Multiple procedures:

procedure Proc1_Old; // body exists


procedure Proc2_New; // body does not exists
procedure Proc3_New; // "
procedure Proc4_New; // "
procedure Proc5_Old; // body exists

Code Completion will add all 3 procedure bodies (Proc2_New, Proc3_New, Proc4_New).

Why calling it "Forward Procedure Completion"?

Because it does not only work for procedures defined in the interface, but for procedures with the "forward"
modifier as well. And because the codetools treats procedures in the interface as having an implicit
'forward' modifier.

Event Assignment Completion


"Event Assignment Completion" is part of the Code Completion and completes a single Event:=| statement.
It is invoked, when the cursor is behind an assignment to an event.

For example: In a method, say the FormCreate event, add a line 'OnPaint:=':

procedure TForm1.Form1Create(Sender: TObject);


begin
OnPaint:=|
end;

The '|' is the cursor and should not be typed. Then press Ctrl+ Shift+C for code completion. The statement
will be completed to

OnPaint:=@Form1Paint;

A new method Form1Paint will be added to the TForm1 class. Then class completion is started and you
get:

procedure TForm1.Form1Paint(Sender: TObject);


begin
|
end;

This works just like adding methods in the object inspector.

Note: You must place the cursor just after the ':=' assignment operator. If you place the cursor on the identifier (e.g.

OnPaint) code completion will invoke "Local Variable Completion", which fails, because OnPaint is already defined.

Hints:

You can choose the default visibility of the new method in Tools / Options / Codetools / Class
Completion / Default section of methods (since 1.8)

You can define the new method name by yourself. For example:
OnPaint:=@ThePaintMethod;

Since 0.9.31 Lazarus completes procedure parameters. For example

procedure TForm1.FormCreate(Sender: TObject);


var
List: TList;
begin
List:=TList.Create;
List.Sort(@MySortFunction|);
end;

Place the cursor on 'MySortFunction' and press Ctrl+ Shift+C for code completion. You get a new
procedure:

function MySortFunction(Item1, Item2: Pointer): Integer;


begin
|
end;

procedure TForm1.FormCreate(Sender: TObject);


var
List: TList;
begin
List:=TList.Create;
List.Sort(@MySortFunction);
end;
Variable Declaration Completion
"Variable Declaration Completion" is part of the Code Completion and adds a local variable definition for a
Identifier:=Term; statement. It is invoked, when the cursor is on the identifier of an assignment or a
parameter.
For example:

procedure TForm1.Form1Create(Sender: TObject);


begin
i:=3;
end;

Place the cursor on the 'i' or just behind it. Then press Ctrl+ Shift+C for code completion and you will get:

procedure TForm1.Form1Create(Sender: TObject);


var
i: Integer;
begin
i:=3;
end;

The codetools first checks, if the identifier 'i' is already defined and if not it will add the declaration 'var i:
integer;'. The type of the identifier is guessed from the term right to the assignment ':=' operator. Numbers
like the 3 defaults to Integer.

Another example:

type
TWhere = (Behind, Middle, InFront);

procedure TForm1.Form1Create(Sender: TObject);


var
a: array[TWhere] of char;
begin
for Where:=Low(a) to High(a) do writeln(a[Where]);
end;

Place the cursor on 'Where' and press Ctrl+ Shift+C for code completion. You get:

procedure TForm1.Form1Create(Sender: TObject);


var
a: array[TWhere] of char;
Where: TWhere;
begin
for Where:=Low(a) to High(a) do writeln(a[Where]);
end;

Since 0.9.11 Lazarus also completes parameters. For example

procedure TForm1.FormPaint(Sender: TObject);


begin
with Canvas do begin
Line(x1,y1,x2,y2);
end;
end;

Place the cursor on 'x1' and press Ctrl+ Shift+C for code completion. You get:
procedure TForm1.FormPaint(Sender: TObject);
var
x1: integer;
begin
with Canvas do begin
Line(x1,y1,x2,y2);
end;
end;

Since 0.9.31 Lazarus completes pointer parameters. For example

procedure TForm1.FormCreate(Sender: TObject);


begin
CreateIconIndirect(@IconInfo);
end;

Place the cursor on 'IconInfo' and press Ctrl+ Shift+C for code completion. You get:

procedure TForm1.FormCreate(Sender: TObject);


var
IconInfo: TIconInfo;
begin
CreateIconIndirect(@IconInfo);
end;

In all above examples you can use Ctrl+ Shift+X to show a Code Creation dialog where you can set more
options.

Procedure Call Completion


Code completion can create a new procedure from a call statement itself.

Assume you just wrote the statement "DoSomething(Width);"

procedure SomeProcedure;
var
Width: integer;
begin
Width:=3;
DoSomething(Width);
end;

Position the cursor over the identifier "DoSomething" and press Ctrl+ Shift+C to get:

procedure DoSomething(aWidth: LongInt);


begin

end;

procedure SomeProcedure;
var
Width: integer;
begin
Width:=3;
DoSomething(Width);
end;

It does not yet create functions nor methods.

Reversed Class Completion


"Reversed Class Completion" is part of the Code Completion and adds a private method declaration for
the current method body. It is invoked, when the cursor is in a method body, not yet defined in the class.
This feature is available since Lazarus 0.9.21.

For example:

procedure TForm1.DoSomething(Sender: TObject);


begin
end;

The method DoSomething is not yet declared in TForm1. Press Ctrl+ Shift+C and the IDE will add
"procedure DoSomething(Sender: TObject);" to the private methods of TForm1.

For Delphians: Class completion works under Lazarus always in one way: From class interface to
implementation or backwards/reversed from class implementation to interface. Delphi always invokes both
directions. The Delphi way has the disadvantage, that if a typo will easily create a new method stub without
noticing.

Comments and Code Completion


Code completion tries to keep comments where they belong. For example:

FList: TList; // list of TComponent


FInt: integer;

When inserting a new variable between FList and FInt, the comment is kept in the FList line. Same is true
for

FList: TList; { list of TComponent


This is a comment over several lines, starting
in the FList line, so codetools assumes it belongs
to the FLIst line and will not break this
relationship. Code is inserted behind the comment. }
FInt: integer;

If the comment starts in the next line, then it will be treated as if it belongs to the code below. For example:

FList: TList; // list of TComponent


{ This comment belongs to the statement below.
New code is inserted above this comment and
behind the comment of the FList line. }
FInt: integer;
Method update
Normally class completion will add all missing method bodies. (Since 0.9.27) But if exactly one method
differ between class and bodies then the method body is updated. For example: You have a
method DoSomething.

public
procedure DoSomething;
end;

procedure TForm.DoSomething;
begin
end;

Now add a parameter:

public
procedure DoSomething(i: integer);
end;

and invoke Code Completion (Ctrl+ Shift+C). The method body will be updated and the new parameter will
be copied:

procedure TForm.DoSomething(i: integer);


begin
end;
Refactoring
Invert Assignments
Abstract

: "Invert Assignments" takes some selected pascal statements and inverts all assignments from
this code. This tool is usefull for transforming a "save" code to a "load" one and inverse operation.

Example:

procedure DoSomething;
begin
AValueStudio:= BValueStudio;
AValueAppartment :=BValueAppartment;
AValueHouse:=BValueHouse;
end;

Select the lines with assignments (between begin and end) and do Invert Assignments. All
assignments will be inverted and identation will be add automatically. For example:

Result:

procedure DoSomething;
begin
BValueStudio := AValueStudio;
BValueAppartment := AValueAppartment;
BValueHouse := AValueHouse;
end;
Enclose Selection
Select some text and invoke it. A dialog will popup where you can select if the selection should be
enclosed into try..finally or many other common blocks.

Rename Identifier
Place the cursor on an identifier and invoke it. A dialog will appear, where you can setup the search
scope and the new name.

It will rename all occurences and only those that actually use this declaration. That means it does

not rename declarations with the same name.

And it will first check for name conflicts.

Limits: It only works on pascal sources, does not yet rename files nor adapt lfm/lrs files nor lazdoc

files.
Find Identifier References
Place the cursor on an identifier and invoke it. A dialog will appear, where you can setup the search
scope. The IDE will then search for all occurences and only those that actually use this declaration.
That means it does not show other declarations with the same name.

Show abstract methods


This feature lists and auto completes virtual, abstracts methods that need to be implemented. Place
the cursor on a class declaration and invoke it. If there are missing abstract methods a dialog will
appear listing them. Select the methods to implement and the IDE creates the method stubs. Since
Lazarus 1.3 it adds missing class interface methods too.

Extract Procedure
See Extract Procedure.

Find Declaration
Position the cursor on an identifier and do 'Find Declaration'. Then it will search the declaration of this
identifier, open the file and jump to it. If the cursor is already at a declaration it will jump to the previous
declaration with the same name. This allows to find redefinitions and overrides.

Every find declaration sets a Jump Point. That means you jump with find declaration to the declaration
and easily jump back with Search -> Jump back.

There are some differences to Delphi: the codetools work on sources following the normal pascal
rules, instead of using the compiler output. The compiler returns the final type. The codetools see the
sources and all steps in between. For example:

The Visible property is first defined in TControl (controls.pp), then redefined in TCustomForm and
finally redefined in TForm. Invoking find declaration on Visible will you first bring to Visible in TForm.
Then you can invoke Find Declaration again to jump to Visible in TCustomForm and again to jump to
Visible in TControl.

Same is true for types like TColor. For the compiler it is simply a 'longint'. But in the sources it is
defined as

TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;
TColor = TGraphicsColor;

And the same for forward defined classes: for instance in TControl, there is a private variable

FHostDockSite: TWinControl;

Find declaration on TWinControl jumps to the forward definition

TWinControl = class;

And invoking it again jumps to the real implementation

TWinControl = class(TControl)

This way you can track down every identifier and find every overload.

Hints

ump back with Ctrl+H.

view/navigate all visited locations via Menu: View -> "jump history"

With a 5 button Mouse the 2 extra buttons to go forward/backward between the visited points

using advanced mouse options the buttons can be remapped.


Identifier Completion
"Identifier Completion" is invoked by Ctrl+space. It shows all identifiers in scope. For example:

procedure TForm1.FormCreate(Sender: TObject);


begin
|
end;

Place the cursor between begin and end and press Ctrl+space. The IDE/CodeTools will now parse
all reachable code and present you a list of all found identifiers. The CodeTools cache the results,
so invoking it a second time will be much faster.

Note: for Delphians: Delphi calls it Code completion.

Some identifiers like 'Write', 'ReadLn', 'Low', 'SetLength', 'Self', 'Result', 'Copy' are built into the
compiler and are not defined anywhere in source. The identifier completion has a lot of these
things built in as well. If you find one missing, just create a feature request in the bug tracker.
Identifier completion does not complete all keywords. So you can not use it to complete 'repe' to
'repeat'. For these things use Ctrl+W Word Completion or Ctrl+J Code Templates. Since
0.9.27 identifier completion completes some keywords.

Identifier completion shows even those identifiers, that are not compatible.

Matching only the first part of a word


You can invoke identifier completion only on the first few characters in a word. Position the cursor
within a word. Only characters to the left of the cursor will be used to look up identifiers. For
example:

procedure TForm1.FormCreate(Sender: TObject);


begin
Ca|ption
end;

The box will show you only identifiers beginning with 'Ca' ( | indicates the cursor position).

Keys

Letter or number: add the character to the source editor and the current prefix. This will

update the list.

Backspace: remove the last character from source editor and prefix. Updates the list.

Return: replace the whole word at cursor with the selected identifier and close the popup

window.

Shift+Return: as Return, but replaces only the prefix (left part) of the word at the cursor.

Up/Down: move selection

Escape: close popup without change

Tab: completes the prefix to next choice. For example: The current prefix is 'But' and the

identifier completion only shows 'Button1' and 'Button1Click'. Then pressing Tab will complete
the prefix to 'Button1'.

Else: as Return and add the character to the source editor


Methods
When cursor is in a class definition and you identifier complete a method defined in an ancestor
class the parameters and the override keyword will be added automatically. For example:

TMainForm = class(TForm)
protected
mous|
end;

Completing MouseDown gives:

TMainForm = class(TForm)
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer); override;
end;
Properties
property MyInt: integer read |;

Identifier completion will show FMyInt and GetMyInt.

property MyInt: integer write |;

Identifier completion will show FMyInt and SetMyInt.

Uses section / Unit names


In uses sections the identifier completion will show the filenames of all units in the search path.
These will show all lowercase (e.g. avl_tree), because most units have lowercase filenames. On
completion it will insert the case of the unit (e.g. AVL_Tree).

Statements
procedure TMainForm.Button1Click(Sender: TObject);
begin
ModalRe|;
end;

becomes:

procedure TMainForm.Button1Click(Sender: TObject);


begin
ModalResult:=|;
end;
Word Completion
Word Completion is invoked by Ctrl+W. It shows all words of all currently open editors and can
therefore be used in non pascal sources, in comments and for keywords.

Otherwise it works the same as identifier completion.

Goto Include Directive


"Goto Include Directive" in the search menu of the IDE jumps to {$I filename} statement where the
current include file is used.

Publish Project
Creates a copy of the whole project. If you want to send someone just the sources and compiler
settings of your code, this function is your friend.
A normal project directory contains a lot of information. Most of it is not needed to be published:
the .lpi file can contain session information (like caret position and bookmarks of closed units) and
the project directory contains a lot of .ppu, .o files and the executable. To create a lpi file with only
the base information and only the sources, along with all sub directories use "Publish Project".

Note: Since version 0.9.13 there is a new Project Option that allows you to store session information in a

separate file from the normal .lpi file. This new file ends with the .lps extension and only contains session

information, which will leave your .lpi file much cleaner.

In the dialog you can setup a filter to include and exclude certain files; with the command after you
can compress the output into one archive.

Hints from comments


At several places the IDE shows hints for an identifier. For example when moving the mouse over
an identifier in the source editor and waiting a few seconds. When the IDE shows a hint for an
identifier it searches the declaration and all its ancestors and looks for comments and fpdoc files.
There are many coding styles and many commenting styles. In order to support many of the
common comment styles the IDE uses the following heuristics:

Comments shown in the hint


Comments in front of a declaration, without empty line and not starting with the < sign:

var
{Comment}
Identifier: integer;

Comments with the < sign belong to the prior identifier.

Comments behind an identifier on the same line:

var
identifier, // Comment
other,

Comments behind the definition on the same line:

var
identifier:
char; // Comment

An example for < sign:

const
a = 1;
//< comment for a
b = 2;
// comment for c
c = 3;

All three comment types are supported:

{Comment}(*Comment*)//Comment
c = 1;
Comments not shown in the hint
Comments starting with $ or % are ignored. For example //% Hiddden, //$ Hidden, (*$ Hidden*).

Comments in front separated with an empty line are treated as not specific to the following
identifier. For example the following class header comment is not shown in the hint:

type
{ TMyClass }

TMyClass = class

The class header comments are created on class completion. You can turn this off in the Options /
Codetools / Class completion / Header comment for class. If you want to show the header
comment in the hint, just remove the empty line.

The following comment will be shown for GL_TRUE, but not for GL_FALSE:

// Boolean
GL_TRUE = 1;
GL_FALSE = 0;
Quick Fixes
Quick Fixes are menu items for specific compiler messages. They help you to quickly fix the
problem. Select a message in the Messages window and right click, or right click in the source
editor on the icon to the left.

Unit not found: remove from uses section

Unit not found: find unit in loaded packages and allow to auto add package dependency

Constructing a class "$1" with abstract method "$2": show dialog to override all abstract
methods

Local variable "$1" not used: remove definition

Circular unit reference between $1 and $2: show Unit Dependencies dialog with full path
between the two units

Identifier not found: search via Code Browser

Identifier not found: search via Cody Dictionary (needs package Cody)
Identifier not found: add local variable

Recompiling $1, checksum changed for $2: show a dialog with search paths and other

information

IDE warning: other sources path of package %s contains directory...: open package

any hint, note, warning: add IDE directive {%H-}

any hint, note, warning: add compiler directive {$warn id off} (since 1.7)

any hint, note, warning: add compiler option -vm<messageid>

Local variable "i" does not seem to be initialized: insert assignment (since 1.5)

You might also like