Part V: GUI Programming with Lazarus

In which PennyWise gets a face, we discover the power of Rapid Application Development, and we prove that native desktop applications — fast, responsive, and free of browser engines — are not a thing of the past.


For twenty-six chapters, every program you have written has lived in the console. Text in, text out. Black screen, white characters, the austere beauty of a command-line interface. You have built sophisticated software in that environment — PennyWise tracks expenses, Crypts of Pascalia generates dungeons, GradeBook Pro manages student records — all without a single button, window, or mouse click.

Part V changes everything.

Over the next six chapters, you will learn to build graphical desktop applications using Lazarus, the open-source Rapid Application Development (RAD) IDE for Free Pascal. Lazarus is the spiritual descendant of Delphi — the environment that, in the 1990s, redefined what it meant to build Windows applications. Where Visual Basic was limited and MFC was punishing, Delphi offered something remarkable: a fast native compiler, a visual form designer, a component library of extraordinary depth, and an object-oriented language (Object Pascal) that made it all comprehensible. Delphi developers built applications in hours that took C++ teams weeks.

Lazarus inherits that legacy and extends it. It is cross-platform: the same code, the same forms, the same components compile and run on Windows, macOS, and Linux. It produces native executables — not Electron apps bundled with a 200-megabyte copy of Chromium, not Java applications that require a JVM, not Python scripts that depend on an interpreter. Native. Fast. Small. When Rosa's PennyWise compiles to a GUI application in Chapter 32, the resulting executable will be a few megabytes, launch in under a second, and consume a fraction of the memory that a comparable web-based finance tracker would demand.

This is not nostalgia for the desktop era. This is the recognition that for many categories of software — personal tools, business utilities, data entry systems, kiosk applications, embedded interfaces — a native desktop application is still the best solution. And Lazarus makes building one remarkably pleasant.

What These Chapters Cover

Chapter 27 introduces the Lazarus IDE and the LCL (Lazarus Component Library). You will create your first GUI application: a window with a button that does something when you click it. This sounds trivial. It is not. Behind that button click lies an entire event-driven programming model — a fundamentally different way of thinking about program flow, where your code does not run from top to bottom but instead responds to events: mouse clicks, key presses, timer ticks, window resizes. You will understand the message loop, the event handler, and the component model that makes it all work.

Chapter 28 dives into forms, controls, and layout. You will learn to use labels, text boxes, combo boxes, list views, panels, splitters, and the layout managers that arrange them. PennyWise gets its first visual mockup: an expense entry form with fields for date, description, amount, and category, plus a list view that displays the transaction history. Rosa designs the form herself, dragging and dropping components in the Lazarus visual designer, and is startled by how much it resembles the graphic design tools she already knows.

Chapter 29 covers menus, toolbars, dialogs, and the standard UI patterns that users expect. File-Open, File-Save, Edit-Undo, Help-About — these are not just conventions; they are a language that users already speak. PennyWise gains a menu bar, a toolbar with icons, and standard dialogs for opening and saving budget files. Tomás adds an "Export to CSV" option that lets him send his spending data to a spreadsheet.

Chapter 30 introduces graphics and custom drawing using the TCanvas object. You will draw lines, rectangles, circles, and text; you will handle colors, fonts, and coordinate systems; and you will build custom components that draw themselves. PennyWise gets spending charts — a pie chart of expenses by category and a bar chart of monthly totals. These are not imported from a charting library. You draw them yourself, pixel by pixel, and in doing so you understand exactly how data visualization works at the lowest level.

Chapter 31 connects your GUI to data. You will learn Lazarus's database components — TSQLite3Connection, TSQLQuery, TDataSource, TDBGrid — and build a data-driven application that reads from and writes to a SQLite database. PennyWise migrates from flat-file storage to a proper database, and the benefits are immediate: queries that took custom code now take a single SQL statement, and the transaction list can be sorted, filtered, and searched without loading everything into memory.

Chapter 32 covers deployment, packaging, and polish. You will learn to compile release builds, create installers, handle DPI scaling, add application icons, and test on multiple platforms. PennyWise becomes a distributable application — something Rosa can put on a USB drive and hand to a friend, or Tomás can install on his roommate's laptop. The chapter also covers accessibility basics: keyboard navigation, screen-reader compatibility, and high-contrast support.

The RAD Experience

RAD — Rapid Application Development — is not just a marketing term. It describes a genuinely different workflow. In a typical programming environment, you write code that creates UI elements, positions them, and connects them to logic. In a RAD environment, you design the UI visually and write code only for the logic. The result is not just faster development; it is a tighter feedback loop. You see what your application looks like as you build it, and you can adjust the design and test the behavior in seconds.

Lazarus's RAD experience is among the best available in any language. The form designer is mature and intuitive. The component palette is vast. The Object Inspector lets you set properties and bind events without writing boilerplate. And because it all compiles to native code through Free Pascal, there is no performance penalty for the visual convenience.

PennyWise Gets a Face

The PennyWise that emerges from Part V is, from the user's perspective, an entirely different application. The console version, for all its algorithmic sophistication, looked like a 1985 DOS program. The GUI version looks like a professional desktop application — because it is one.

But here is what matters: the business logic has not changed. The TExpense class, the TBudget aggregator, the quicksort routine, the tree-based category hierarchy, the exception handlers — all of it carries forward. The GUI is a new presentation layer over the same well-designed core. This is not an accident. This is the payoff of the clean architecture you have been building since Part I. When your logic is separated from your interface, you can change the interface without rewriting the logic.

Rosa appreciates this separation more than Tomás does. She has seen too many freelance projects where the UI and the logic are tangled together so tightly that changing a button's position breaks a calculation. PennyWise does not have that problem, because Pascal — and the discipline it encourages — does not allow it.

Native Applications in a Web-First World

We live in an era where "application" increasingly means "website pretending to be an application." Electron, Tauri, Progressive Web Apps — the industry's momentum pushes everything toward the browser engine. There are good reasons for this: cross-platform compatibility, easier deployment, familiar web technologies.

But there are costs. An Electron app ships an entire copy of Chromium. A simple note-taking application consumes 500 megabytes of RAM. Startup times are measured in seconds, not milliseconds. And on older hardware — the hardware that many people in the world actually use — these bloated applications are barely functional.

Lazarus applications have none of these problems. They are native. They are small. They are fast. They respect the user's hardware. Part V teaches you to build software that works this way — not because it is fashionable, but because it is right.

Let us open the Lazarus IDE and build something you can see.

Chapters in This Part