Lazarus IDE

Lazarus IDE

  • mdo  DigitalBox
  •   Dev
  •   April 15, 2025

The Lazarus IDE is available on Haiku, which lets you write Pascal programs on your favorite system.

Let's review how to install and use this IDE.

Installation

Before installing Lazarus IDE, you will need the Free Pascal Compiler (FPC).

Open HaikuDepot and search for "fpc" :

You can then install the "fpc" package.

Now search for "lazarus" :

Select "lazarus_bin" and proceed with the installation.

You can check the version of FPC available in a Terminal :

fpc

In the applications' menu Deskbar, click on the "Lazarus-IDE" shortcut to launch the application :

The first time it's launced, you will need to indicate the sources directory of the FPC package :

/boot/system/lib/fpc/3.2.2/src

Then in the Debugger section, select the "GNU debugger gdb)" :

Click on "Start IDE" to confirm.

Lazarus is not fully installed !

Live Clock example

Instead of reviewing all the possible features of Lazarus - which are numerous - let's review how to create a simple clock application.

Create a dedicated directory named "LiveClock" via the Terminal :

mkdir LiveClock

Open Lazarus IDE.

The below windows will appear with a default application and an empty Form :

Let's create from scratch the application.

Go to Project>New Project:

Select "Application" for the type of project:

Confirm with OK.

You will see the below default unit which contains a form named "Form1" :

Let's replace the code of this unit by our clock.

Copy paste the below code into the unit1 window corresponding to the "unit1.pas" file: 

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Timer1: TTimer;
    LabelTime: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure LabelTimeClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  Color := clBlack;

  Timer1.Interval := 1000;
  Timer1.Enabled := True;
  LabelTime.Font.Color := clLime;
  LabelTime.Alignment := taCenter;
  LabelTime.Layout := tlCenter;
  LabelTime.Width := Form1.ClientWidth;
  LabelTime.Height := Form1.ClientHeight;
end;

procedure TForm1.LabelTimeClick(Sender: TObject);
begin

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  LabelTime.Caption := 'Current time: ' + FormatDateTime('hh:nn:ss', Now);
end;

end.
                                          

Then select File>Save :

Save your project into the "LiveClock" folder created just before :

And save also the Unit under the name "unit1.pas" :

Now go into the Terminal and edit directly the source of your Form linked to the unit:

lpe unit1.lfm

Copy/Paste the below code into the file "unit1.lfm" : 

object Form1: TForm1
  Left = 327
  Height = 96
  Top = 333
  Width = 379
  Caption = 'Live Clock'
  ClientHeight = 96
  ClientWidth = 379
  DesignTimePPI = 72
  OnCreate = FormCreate
  LCLVersion = '3.8.0.0'
  object LabelTime: TLabel
    Left = 32
    Height = 31
    Top = 32
    Width = 269
    Caption = 'Current time: --:--:--'
    Font.Height = 27
    Font.Name = 'DejaVu Sans'
    ParentFont = False
    OnClick = LabelTimeClick
  end
  object Timer1: TTimer
    OnTimer = Timer1Timer
  end
end

Please note you don't need to edit the code of your project, because it has been defaulted as below which is OK :  

program LiveClock;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  {$IFDEF HASAMIGA}
  athreads,
  {$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, unit1;

{$R *.res}

begin
  RequireDerivedFormResource:=True;
  Application.Scaled:=True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
                        

This content should be the same than your ".lpr" file.

Now let's restart Lazarus to update the Form in the IDE :

Yes it's working fine!

As you can see, the Form corresponding to the clock has been updated above.

Let's run the program.

Click on the Run icon (or F9):

By default the Run is in debugging mode, so it takes a little bit of time before the program is displayed.

The below error message is not an issue :

If the arrow is greyed out, it's normal as the run is in progress :

A few seconds later, you will see the nice clock running on your system :

Nice isn't it  ?

If you need to launch the program quickly, you can deactivate the debugging by selecting the "Run without Debugging" :

If you check the details of your objects via the "Object Inspector", you will see that your Form is using a TLabel and a TTimer :

Now click on the "Project Inspector" :

You will see the structure of your project :

  • The main project file ".lpr" which will call the Form
  • The "unit1.pas" which is corresponding to the code attached to the Form

if you check the details of the files via the Terminal, you will see the "project1" which is corresponding to your executable :

One point I have noticed, sometimes Lazarus IDE is raising an "Access violation" error :

I'm not sure about the cause of this error, one workaround is to relaunch the IDE via the "restart" menu:

Compiling outside the IDE

It's possible to launch or compile your project outside the IDE.

To run your program, just type the name of the executable (project1 below).

./project1

It will launch the clock accordingly.

Now if you need to compile your whole project (including ".pas" and ".lpr" files), type the below command in a Terminal :

/bin/fpc \
-MObjFPC \
-Scghi \
-O1 \
-g \
-gl \
-l \
-vewnhibq \
-Fu/boot/system/lib/lazarus/lcl/units/x86_64-haiku/qt6 \
-Fu/boot/system/lib/lazarus/lcl/units/x86_64-haiku \
-Fu/boot/system/lib/lazarus/components/lazutils/lib/x86_64-haiku \
-Fu/boot/home/Documents/Pascal/LiveClock \
-FU/boot/home/Documents/Pascal/LiveClock/lib/x86_64-haiku/ \
-FE/boot/home/Documents/Pascal/LiveClock/ \
-o/boot/home/Documents/Pascal/LiveClock/LiveClock \
-dLCL \
-dLCLqt6 \
/boot/home/Documents/Pascal/LiveClock/unit1.pas \
/boot/home/Documents/Pascal/LiveClock/project1.lpr

Working as expected :)

Haiku API bindings

Unfortunately, Lazarus does not provide any bindings to the Haiku API.

But it doesn't mean you can't call the Haiku API from your Pascal program.

Below is a method on how to call a C++ library which is using the Haiku API.

In a Terminal create a HelloHaiku folder :

mkdir HelloHaiku
cd helloHaiku

Now edit the file named "hello.cpp":

lpe hello.cpp

Copy/Paste the below code inside the file :

#include <Application.h>
#include <Window.h>
#include <View.h>

extern "C" void run_app();

class MyWindow : public BWindow {
public:
    MyWindow() : BWindow(BRect(100, 100, 300, 200), "Hello Haiku!", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) {
        Show();
    }

    bool QuitRequested() override {
        be_app->PostMessage(B_QUIT_REQUESTED);
        return true;
    }
};

class MyApp : public BApplication {
public:
    MyApp() : BApplication("application/x-vnd.fpc-haiku") {}
    void ReadyToRun() override {
        new MyWindow();
    }
};

void run_app() {
    MyApp app;
    app.Run();
}

Save the file

In this code, we expose the method "run_app" to the rest of the world.

Compile the code into a shared library named "libhello.so" :

g++ -shared -fPIC -o libhello.so -lbe  hello.cpp

Then edit your Pascal program named "main.pas" :

lpe main.pas

Copy/Paste the below code :

program HelloHaikuApp;

{$linklib libhello} 
{$ifdef Haiku}
{$LINKLIB c}        
{$endif}

uses
  SysUtils;

procedure run_app; external;

begin
  run_app;  
end.

As you can see, this program is just calling the "run_app" method from the "libhello" library.

Compile the Pascal program into the "HelloHaikuApp" :

fpc -k-lhello -k-L/boot/system/lib -oHelloHaikuApp main.pas

The program is linked with the "libhello" library via the "-k-lhello" option.

Before launching the program, we must be sure the library is installed into the system.

For that copy it under the "/boot/home/config/non-packaged/lib" directory and call the program :

cp libhello.so /boot/home/config/non-packaged/lib/
./HelloHaikuApp

Yes !

As you can see, the Pascal program is now calling the library and thus is using the Haiku API :)

Please note the size of the file is quite huge for such a simple HelloHaiku program:

It's the price to pay to use the Pascal language.

Games

Let's conclude this article by presenting a few games written in Pascal.

The first one is a Tetris clone named "Petris" :  https://wiki.lazarus.freepascal.org/Petris

You can download the source code in the above link and launch the program directly from Lazarus IDE :

The second one is the "2048" game.

You can also download the source code at https://app.zdechov.net/2048

Launching the game is also possible via Lazarus :

The last one is Hedgewars : https://github.com/hedgewars/hw/

Various languages were used to write this game, however the game core is written in Pascal.

This is a good example that you can use the language you are more comfortable with to write your favorite programs :)

I hope you have found this article useful.

And you can put a comment below to share your experience with Lazarus IDE.


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider