Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2026-02

Clean FreePascal coding in Lazarus IDE

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Goh

Hi Lazarus Team,
How do I code in Lazarus without the switches such as {IFDEF +/,,,,? ?} etc.? How do I disable it. I am unable to do clean FreePascal coding.as the environment demands that I use a set of those "switches"?? ?It is hence impossible to implement a simple "Hi welcome to FreePascal or Lazarus" program.?? However I am grateful that the FreePascal language has been build into the Lazarus IDE (if I am correct to say so) or the Lazarus package includes FreePascal. My main purpose is to remind myself of the concepts of programming and GUI desktop development after years of inactivity in the programming domain, so that I can rapidly pick up content in these other production languages - Python 3, six major Python frameworks, NodeJS, Perl 5.42 and Java 17/25 (LTS) using a patoea of tools such as WebStorm, PyCharm, IntelliJ IDEA with the Perl plugin, and a assortment of other tools as I experiment with them. My production environment will shift from Windows 11 to a distribution of GNU/Linux such as Ubuntu, Fedora, SUSE Linux, Mint etc, with the use of a lightweight desktop such as xfce, or LXQt etc. With thanks and regards,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20260211/d96e6e3f/attachment.htm>

Reply by email

DougC
to Andrew Goh

Lazarus is a multi-platform development environment. Therefore, some features are implemented in modules that are not necessary in every environment. Those conditional compilation settings you seem to not like select the correct modules for the environment you are using.

I am curious why you do not consider code with those settings "unclean"?

DougC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20260211/06ad06e7/attachment.htm>

Reply by email

Martin Frb
to Andrew Goh: How do I code in Lazarus without the switches such as {IFDEF +/,,,,? ?} etc.? How do I…
Andrew Goh wrote 8 lines
Hi Lazarus Team, How do I code in Lazarus without the switches such as {IFDEF +/,,,,? ?} etc.? How do I disable it. I am unable to do clean FreePascal coding.as the environment demands that I use a set of those "switches"?? ?It is hence impossible to implement a simple "Hi welcome to FreePascal or Lazarus" program.

Can you give examples of the exact switches that you don't want?

A new default app, has

in the unit:
? ?{$mode objfpc}{$H+}

You can remove them, but then you MUST make sure to have the correct command-line switches passed to FPC when compiling. That is, the compiler has more than one dialect, so when compiling it must know which on your code uses.

And there also is (in the project)
? {$IFDEF UNIX}
? cthreads,
? {$ENDIF}
? {$IFDEF HASAMIGA}
? athreads,
? {$ENDIF}

- If you don't use threads, you can remove them. (including the _threads unit)
- if you don't use either of? those OS, then you can remove them (including the _threads unit)
- if you only use Linux, you can reduce that to just: uses cthreads

If you use several OS, and threads => then unfortunately you need that. (Or you create an empty "cthreads" unit on your Windows system, but not the Linux system)

There may again be option to pass those by command line... But I don't recall right now (and it would need diff commandline to compile on diff platform)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20260212/6c6b7a8a/attachment.htm>

Reply by email

Juha Manninen
to Andrew Goh: How do I code in Lazarus without the switches such as {IFDEF +/,,,,? ?} etc.? How do I…

On Thu, Feb 12, 2026 at 1:24?AM Andrew Goh via lazarus <

Show quoted text 5 lines
wrote: It is hence impossible to implement a simple "Hi welcome to FreePascal or Lazarus" program.

It is perfectly possible. Try this:

In the Lazarus default application design-window,
- drop an Edit there
- drop a Label there
- drop a Button there
- double-click the Button. Write "Label1.Caption := 'Hello ' + Edit1.Text;"
- click the Run (F9). The application is compiled and runs.
- save your new project if you want to continue it later.

You have now created a standalone executable which can be copied and runs in any similar platform (OS).
What more, the same source code can be compiled in other supported platforms and it runs using the system's native GUI controls. No IFDEFs. Amazing!
This Hello app does not use threads. You can delete those automatically added IFDEFs from the .lpr file if you want, as Martin mentioned.

Juha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20260212/c9c86bb4/attachment.htm>

Reply by email

Aruna Hewapathirane
to Andrew Goh: How do I code in Lazarus without the switches such as {IFDEF +/,,,,? ?} etc.? How do I…

On Wed, Feb 11, 2026 at 6:24?PM Andrew Goh via lazarus <

wrote: How do I code in Lazarus without the switches such as {IFDEF +/,,,, }

etc.

*SHORT ANSWER:*

You *can* comment out the {$IFDEF ...} lines using '//' or '{}'

// {$IFDEF UNIX}   or   {{$IFDEF UNIX}}    either or both will work.

Now please try compiling *after commenting* and you will see it compiles and runs. Great, So why have the {$IFDEF +/,,,} in the first place? We will address this in the long answer section.

Now try commenting out where it says Interfaces:
// Interfaces, // this includes the LCL widgetset

Try compiling again only this time pay careful attention to the message shown by Lazarus IDE.
Select cancel to get back to the IDE. The error message mentions LCL.

What is LCL and why do we need it?
The Lazarus Component Library (LCL) is a set of visual components to create *GUI* applications.

*LONG ANSWER:*

What you are seeing are *conditional compiler directives* *automatically generated and added* to make your program compile on different operating systems.
This is nothing new. Turbo Pascal had this.

Lazarus is a cross-platform, integrated development environment (IDE) for rapid application development (RAD) *using* the Free Pascal compiler. So Lazarus and FPC are two separate things.

- Free Pascal (FPC) is a mature, open-source compiler for the Pascal and Object Pascal programming languages, capable of creating console and GUI applications for many platforms.
- Lazarus IDE
<https://www.google.com/search?q=Lazarus+IDE&sca_esv=3d067c3d94f87471&sxsrf=ANbL-n5VgNIiuuveWRqwk9JIRw1yBptJ5w%3A1772584224760&ei=IH2naZmULrW80PEP8vCweA&ved=2ahUKEwjynOuC_4STAxWBLTQIHWJsIukQgK4QegQIARAB&uact=5&oq=what+is+free+pascal+and+what+is+lazarus+IDE+are+they+the+same+%3F&gs_lp=Egxnd3Mtd2l6LXNlcnAiP3doYXQgaXMgZnJlZSBwYXNjYWwgYW5kIHdoYXQgaXMgbGF6YXJ1cyBJREUgYXJlIHRoZXkgdGhlIHNhbWUgP0iFOFDdCFiJNHABeACQAQGYAa8BoAH_EaoBBDkuMTK4AQPIAQD4AQGYAhGgAtMPwgIKEAAYsAMY1gQYR8ICBRAhGJ8FwgIFECEYoAHCAgQQIRgVwgIHECEYoAEYCpgDAIgGAZAGCJIHBDMuMTSgB4dFsgcEMi4xNLgHww_CBwYyLTE1LjLIB2eACAA&sclient=gws-wiz-serp&mstk=AUtExfARjzi9o5XI8P_tM6QNymPg27SIUFAL_m3rhWU9XuJ_wRHKErSJJT0DQ0ZwwWiC39zBKhX2_LkQsvi6F__cx1-65-_SYmYl07aUUg26KastrCPwiIws791fZsbQC-hszo37yR3ji-jCLyA0ITpWHqnkgW3ha1lYZ9sx-RQKGBo7OIekPR4unRK41U4QOhLy1eos0FUEYqXY41s-_WRRB_MJIQqjt2sOPceHEi25uGLnBtMzU2p5Eb8200HPdf5GRAj2NrPkQyFELCZXJvpRxr17yLD3Y7oNI0-A70vCSF_B7A&csui=3> is the GUI-based Integrated Development Environment (IDE) that uses Free Pascal to develop applications, providing a rapid application development (RAD) environment similar to Delphi.

They are not the same; Free Pascal is the engine, while Lazarus is the steering wheel. Free Pascal (FPC) and the Lazarus Integrated Development Environment (IDE) are two distinct tools with a dependent relationship: FPC is the core compiler, while Lazarus is the graphical interface and development environment surrounding it.

FPC is the engine, Lazarus is the car. You can run the engine alone (console apps), but you cannot drive the car without the engine (GUI apps).

________________________________
First, let's understand what is happening.

Fire up your Lazarus IDE then select Project --> New Project- -> Application. Then *SAVE* it to disk.
When you create a *GUI *project in *Lazarus IDE*, and save it the IDE generates these files:

project1.ico
project1.lpi
project1.lpr
project1.lps
project1.res
unit1.lfm
unit1.pas

These are the standard files Lazarus IDE generates when you create a new project. Let?s break them down carefully, so you understand what each one is for:
________________________________
*1. project1.ico*
Type: Icon file
Purpose: This is the icon for your application (the one that shows in the taskbar, window title, or desktop shortcut).
Format: Standard Windows-style .ico, but Lazarus can also use it cross-platform.
Tip: You can replace this with your own .ico to customize your app?s icon. ________________________________

*2. project1.lpi*
Type: Lazarus Project Information
Purpose: This is the main project file for Lazarus IDE. It stores: Project settings
Compiler options
Linked units and forms
Format: XML (so you can open it in a text editor if you want to peek).

Tip: Think of this as the ?map? of your project for the IDE. Without it, Lazarus doesn?t know how your project is structured. ________________________________

*3. project1.lpr*
Type: Lazarus Project Source
Purpose: This is the main Pascal program file. It contains the program Project1; header and usually the code that:
Initializes the application
Creates the main form
Starts the Application.Run loop
Format: Pascal code (.pas)

Tip: This is the entry point of your program. It?s what the compiler actually turns into the executable.
_______________________________

*4. project1.lps*
Type: Lazarus Project Session file (Optional / IDE-specific) Purpose: Stores temporary IDE metadata, like:
Open forms and editors
Breakpoints
Tip: You usually don?t touch this; it?s like your IDE?s ?workspace memory.? Try putting a breakpoint in your hello world program. Run then afterwards check the *project1.lps* file.
________________________________

*5. unit1.lfm*
Type: Lazarus Form File
Purpose: Stores the design of your form (components, positions, properties, events).
Format: Text or binary (usually text in XML-like format) Tip: You rarely edit this manually; the Form Designer writes it for you. ________________________________

*6. unit1.pas*
Type: Pascal Unit File
Purpose: Contains the code behind the form (event handlers, methods, business logic).
Tip: This is where you write the code that makes buttons click, memos update, etc.
________________________________
Now...

If you want to do clean FreePascal programming, most of the time, people mean:

No GUI scaffolding
No Interfaces unit
No Forms
No { $IFDEF } platform switches

The Free Pascal project provides *TWO* primary Integrated Development Environments (IDEs) for development: the text-mode IDE (FP IDE) and the full graphical Lazarus IDE.

*1. The Text-Mode IDE (FP IDE)*
The "FP IDE" is a lightweight, text-based application designed to mimic the look and feel of the classic Turbo Pascal IDE.

Features: It includes an editor with syntax highlighting, a debugger, and a symbol browser. The compiler is built directly into the IDE executable itself.
Availability: It is available for multiple operating systems, including Windows, Linux, and DOS.

Usage: It can be started from the command line by simply typing fp. This IDE is functional and useful for console-based programs but does not have a graphical form designer.

*2. The Lazarus IDE*
Lazarus is the more feature-rich, cross-platform, graphical IDE for Free Pascal. It is designed for Rapid Application Development (RAD) and is a free, open-source alternative very similar to Delphi.

Features: It offers a visual form designer, a large collection of ready-to-use components, a powerful source editor, and a debugger. Availability: Lazarus runs on Windows, macOS, and Linux.

Usage: It is the recommended choice for most users, especially those wanting to create modern graphical user interface (GUI) applications, web services, and cross-platform projects. A project created on one platform can be recompiled on any other supported platform with little to no modification.

Lazarus is designed for: Cross-platform GUI applications. *That means the auto-generated code is defensive and portable.*

If you want clean minimalism, use: Console programsOr direct fpc Or a bare .pas without .lpi and in this case you would be better off using the text mode FP Ide
that comes with free pascal.

----------------------------------------------------------------------------------------------------------------------------------- But, If you *really want to write pure FreePascal code* in Lazarus, here?s the safest way:

1.

Go to *File ? New ? Project ? Simple Program*
2.

*DO NOT* save it as a full project?just save it as a simple *.pas file. 3.

When you?re done coding, compile it using *fpc*.

*(Actually? go ahead and save it as a project anyway. That way you?ll see why I said not to! ?)*
------------------------------
{$IFDEF} in Lazarus ? The ?Light Bulb & Outlets? Version

Think of your code like a light bulb:

- Windows code ? 120V bulb
- Linux/macOS code ? 220V bulb

The auto-generated {$IFDEF} is like the right plug for the right outlet:

{$IFDEF WINDOWS}
  // 120V socket
{$ENDIF}
{$IFDEF UNIX}
  // 220V socket
{$ENDIF}

If you remove the {$IFDEF}:

-

You might plug your 120V bulb into a 220V outlet ? boom! (compiler error or crash)

Why keep it?

- Protects your code from running where it doesn?t belong.
- Lets one source file work on all OSes.
- Compiler ignores the blocks you don?t need ? no slowdown.

I know this was a long read and touched on multiple things and one last word of advice: Do not remove {$IFDEF + ...} blindly in a GUI program.

Enjoy yourself! The more you explore and experiment, the more you'll come to appreciate the power and freedom that FPC and the Lazarus IDE offer. Aruna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20260303/4f58fad5/attachment-0001.htm>

Reply by email