You are currently viewing the United Kingdom version of the site.
Would you like to switch to your local site?
14 MIN READ TIME

Write GUI apps in Pascal with Lazarus

David Bolton explains how to get started with Lazarus and Free Pascal to develop GUI applications running on Linux.

LAZARUS

Credit: www.lazarus-ide.org

OUR EXPERT

David Bolton has 30 years of Pascal programming experience under his belt, so knows a thing or two about developing GUI programming applications on Linux and other platforms.

The source code for this example is zipped up in the file Lazarusexample.zip at https://github.com/David-H-Bolton/Projects. Just open the link in Firefox, click on the file, then the three dots on the right, and download it.

Creating GUI apps in Linux is more complex than making simple apps that run in a terminal. C There are several ways that are mostly GTK-based with C or C++, such as GTK+/C, Qt/C++, FLTK/C++ and WxWidgets/C++. You can also use the Python library PyGObject.

There is another, easier way if you don’t mind learning Pascal. Install Lazarus (see boxout opposite), an IDE that also installs the cross-platform opensource programming language Free Pascal. This lets you create GUI apps visually by dropping icons on a form, setting their properties, then compiling and running the program.

After installing it, you can start Lazarus with the command startlazarus in a terminal. That opens the Lazarus editor. You should see five different windows:

1. The top one is the main window, with the menu and all components and their icons.

2. To the left is the Object Inspector. This shows the properties for the selected component on the Visual form (see 4).

3. The source editor is where you edit the source code of your Pascal application.

4. The gridded window with the title Form1 is the Visual form.

5. A Messages window at the bottom. This shows the compile results.

GUI applications in Free Pascal are made up of several file types. There’s the main program file, which has an LPR extension (short for Lazarus PRoject). It’s not visible initially but click the Project menu and then click View Project Source (at the bottom of the menu that appears), and it opens in the source editor.

Anything with a $ inside comment braces {$ } is a compiler directive. The first directive {$mode objfpc} tells it to compile in objfpc mode (see the online documentation). The {$H+} tells it to use long strings.

The uses block is a list of units that are needed to provide functions and procedures. In Pascal, a unit is a module that is linked in to your application at compile time. It’s a handy way of splitting your application into smaller parts. Free Pascal comes with many standard units, such as forms, classes, sysutils and interfaces. You can also create your own units.

Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for 99p
SUBSCRIBE NOW
30 day trial, then just £9.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
November 2023
VIEW IN STORE

Other Articles in this Issue


LINUX FORMAT
LINUX FORMAT
The #1 open source mag
WELCOME
MEET THE TEAM
This issue, we’re setting up a Jellyfin media server – that was Neil’s first ever Linux-based project. What first got you installing Linux back in the day?
At your service
I recently expanded my home server’s RAID to
REGULARS AT A GLANCE
Free Software Foundation celebrates GNU at 40
Since 1983, GNU has formed the backbone of key computer systems. The FSF reflects on all that’s great about copyleft and free software.
Gnome 45 is coming
Gnome 45 ‘Rīga’ focuses on improved performance plus overhauling windows and file management.
From Terraform to OpenTofu
OpenTofu is now overseen by the Linux Foundation.
TOFU FOR ALL!
Joe Brockmeier is head of community, Percona. “
CODEC COUP
Benjamin Gaignard is a senior software engineer at
Download manager was trojaned
Team issues script to check if Linux systems have been compromised.
Millions of LibreOffice!
The LibreOffice suite soars in popularity.
AV1 decoder
Kernel support for AV1 uAPI and stateless video decoders.
Distro watch
What’s behind the free software sofa?
SECURITY FIRST
Italo Vignoli is one of the LibreOffice and
MAC MAGIC
Jon Masters is a kernel hacker who’s been
Kernel Watch
Jon Masters keeps up with all the latest happenings in the Linux kernel, so you don’t have to.
ONGOING DEVELOPMENT
RISC-V patches include an updated (version 9) series
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
WRITE TO US Do you have a burning
LETTER OF THE MONTH
FOCAL point
Xournal++
HANDWRITTEN NOTES
Parallel Disk Usage
Version: 0.9.0 Web: https://crates.io/crates/parallel-disk-usage Linux has
Mission Center
Version: 0.3.1 Web: https://missioncenter.io System admins go
Floorp
Version: 11.1.2 Web: https://floorp.app F irefox
Ferdium
Version: 6.4.1 Web: https://ferdium.org The idea
HopToDesk
Version: 1.40.5 Web: www.hoptodesk.com There are
Touché
Version: 2.0.9 Web: https://github . com/JoseExposito/touche If
Sonic Robo Blast 2
SRB2 lets you relive the original, and playing
Fheroes2
Version: 1.0.7 Web: https://ihhub.github.io/fheroes2 Another classic
Ulauncher
Version: 5.15.3 Web: https://ulauncher.io The search
AlbumEasy
Version: 4.5.0 Web: www.thestampweb.com/albumeasy If you
REVIEWS
Seagate FireCuda 540
Chris Szewczyk finds high performance and peace of mind. At a price.
AMD Radeon RX 7800 XT
Introducing a multi-chip RX 6800 XT for less – and Dave James thinks that it’s actually the best £500 GPU around.
Qubes 4.1.2
Nate Drake explores the apex of Linux security: an OS that divides all your apps into colour-coded, isolated virtual machines.
Mageia 9
Nate Drake visits the spiritual successor to Mandriva Linux and comes away enchanted.
Ubuntu 23.10
Nate Drake dives into the labyrinth and finds Canonical has released another solid offering with its Mantic Minotaur iteration of Ubuntu.
Old World
A 4X (Explore, Expand, Exploit and Exterminate) game? Management is all ears and demands Fraser Brown plays it.
Fediverse servers
Looking to create your own online community? The fediverse is for you. David Rutland tests the best self-hosted fediverse servers available.
Ease of deployment
How quickly can you set up a server?
Hardware requirements
Will it run on your old box?
Customising and special features
What is it that makes these fediverse server types stand out above the rest?
Customisation options
Make your instance truly unique.
Fediverse to go
Social media lives in the palm of your hand.
Moderation and safety
No one wants a server full of filth.
Holding a conversation
Talking is the best way to be social.
The Verdict
Fediverse servers
STREAMING MADE EASY!
Bring together all your film, TV, music, audiobook and photo streaming needs under one roof. Nick Peers shows you how.
Install Jellyfin
Get set up and ensure your media files are organised correctly.
Stream films, TV and music
Jellyfin can cover almost all of your media streaming needs…
Back up and view photos and videos
Ditch the expensive subscription and back up (and stream) photos locally.
Stream audiobooks from your server
Why pay for Audible when you can host your own collection?
Pi USER
Astro Pi Mission Zero blasts off into 2024!
Go out of this world and enter the new competition for young coders that’s now on!
Pi-almOS PDA
Alive once more!
The Pi Beret!
Adafruit EYESPI Pi.
RASPBERRY PI STILL RULES
Les Pounder works with groups such as the
Raspberry Pi 5
The first new flagship in four years has Les Pounder and Avram Piltch fighting over who gets first dibs on the latest SBC.
Play Steam games on your Raspberry Pi
Les Pounder has just had his living room redecorated after a nasty flood – what better way to celebrate than by shooting aliens?
IN DEPTH
A BIG BANG!
Matt Holder discovers what System76’s Cosmic desktop and Pop!_OS distribution have to offer.
TUTORIALS
Fast file management
Shashank Sharma may be a gamophobe but he has no fear in admitting his commitment to the CLI thanks to the many wonderful tools on offer.
Take command of your photo collection
Nick Peers reveals how to organise your photos, plus improve, repair and enhance them – all with a single tool.
Twenty years of WordPress websites!
In the first part of this new series, Michael Reed takes a look at what the content management system WordPress can serve up.
How to enjoy free streaming TV
Perfect your media server install by adding your own bespoke collection of streaming TV channels. Neil Mohr is your channel-hopping guide.
COBOL: still going after all these years
It might have appeared back in 1959 and look odd compared to today’s languages, but COBOL is still fuelling business, Mike Bedford reports.
Reviving the BBC Domesday Project
Matt Holder discovers how the BBC’s Domesday Project was nearly lost to recent history and how a group of volunteers are bringing it back to life.
ADMINISTERIA
ORANGE VS RED
Stuart Burns is a Linux administrator for a
Red Hat says no more Screen time for you!
With the end of Screen in sight, it’s time to use Tmux. Our man in the bowels of the server room explains.
Beware of geeks bearing gifts
We’re still trying to work out why you need a download manager anyway…
Seek and ye shall locate
How to find files in Linux using Find, Locate and Grep…
NordVPN
Mike Williams puts one of the big-name VPNs under his microscope.
Cargo
A website builder with a user-friendly interface and customisable features – Ruby P Jane is suitably impressed.
Seventh level of networking
Understanding networking needn’t be hell. Darien Graham-Smith takes us through the ISO OSI model that runs it all!
CODING ACADEMY
Visualise smart- home sensor data
Matt Holder investigates how to take data from an API and display it in a home-built interface.
Chat
X
Pocketmags Support