The “Delphi in all its glory” book [1]

“Delphi in all its glory – Delphi for more than mere programmers” was released in 2022.

This is the first book in the series.

You can find the printed book on your local Amazon (Amazon.com, Amazon.de, etc) or in electronic format.

The first book in the “Delphi in all its glory” trilogy concentrates on the exploration of the Delphi language. Whether you're a curious novice venturing into the world of coding for the first time or already the user of a different programming language, this book is your gateway to Delphi coding. Even if you are a Delphi programmer, you could still learn a few tricks (especially things related to code-safety) from the that book. The book is also perfect for old-school Pascal programmers that were always afraid to switch to objects. The second book addresses the more seasoned developers aiming to enhance their craft. It focuses on the more advanced topics, such as 64-bit code upgrade, compiler and debugger inner working, speed improvements, memory management, proper exception handling, architecture design and code-safety in general. This third book goes deep into the inner working of Delphi’s library system. I will concentrate more on how libraries are useful to organize your code, how to set up your own library system and how libraries can dramatically increase your compilation speed. Building custom visual components will not be in focus, even though we will have a chapter and some code about that. I intend to expand the book to cover more of that. There will also be a chapter about how I turned a personal library called Proteus into a successful commercial product. By purchasing that book, you will get access to the code of that library. If you have never worked with Delphi, the second and third book is NOT for you! Please read the first book, then return to this one to complete your skills.

ISBN:9798387412141


The source code for the example used in the book can be found on GitHub.

Use the comments section below if you have any comments about the book. They are MORE THAN WELCOME!

 


1.            Overview

Welcome to a journey that will transform you into a masterful creator of well-designed, high-performance, rock-solid applications, visually appealing applications.

Intended Audience

The first book in the “Delphi in all its glory” trilogy concentrates on the exploration of the Delphi language. Whether you’re a curious novice venturing into the world of coding for the first time or already the user of a different programming language, this book is your gateway to Delphi coding.

 

Even if you are a Delphi programmer, you could still learn a few tricks (especially things related to code-safety) from the that book. The book is also perfect for old-school Pascal programmers that were always afraid to switch to objects.

 

The second book addresses the more seasoned developers aiming to enhance their craft. It focuses on the more advanced topics, such as 64-bit code upgrade, compiler and debugger inner working, speed improvements, memory management, proper exception handling, architecture design and code-safety in general.

 

This third book goes deep into the inner working of Delphi’s library system. I will concentrate more on how libraries are useful to organize your code, how to set up your own library system and how libraries can dramatically increase your compilation speed. Building custom visual components will not be in focus, even though we will have a chapter and some code about that. I intend to expand the book to cover more of that.

There will also be a chapter about how I turned a personal library called Proteus into a successful commercial product. By purchasing that book, you will get access to the code of that library.

 

If you have never worked with Delphi, the second and third book is NOT for you! Please read the first book, then return to this one to complete your skills.

What is Delphi?

Delphi is a modern multi-purpose, safety-oriented, programming language. With Delphi we can create cool looking graphic applications for Windows, Mac, Linux, and Android, with very little code.

Delphi is safe, Delphi is fast, Delphi is friendly, Delphi is free.

Book layout

In the first chapter we will see what kind of applications we can do with Delphi – spoiler alert: you can do any kind of application you want. 😊

Then we will install Delphi and study the anatomy of a Delphi project in order to create our first application.

After that, we take a quick look at the IDE, then, we finally dive into the Delphi language. After we learn the basics, we will see what is safe to do in Delphi and what is not, and most important, why. After that, we move to object-oriented programming and then we will learn about visual components.

 

A second purpose of this book is also to demonstrate that Delphi is the best tool if you want to develop:

  • Good looking GUI applications
  • Cross-platform applications
  • Fast applications (for example data-processing, games)
  • Business and scientific applications

Always focused on code-safety

This trilogy is not the regular “programmer’s manual” kind of book where I show you the basics of programming and keep circling around simple code examples. The main purpose of this book is to take you to the “meta” level of programming and beyond that.

 

The “safety first” concept starts in the first book, and it is strengthened in the next books.

We will learn in the background to achieve code modularization thorough libraries, how to avoid circular references, how to build stable programs through reliable code, how to avoid typical programming pitfalls, how to turn mondain Delphi features into an error-prevention system, and why some programming concepts are safer than others.

Oh boy… we will have fun!

 

In parallel with all the above, we will compare Delphi with other languages (mostly C++, C#, R, Java, and Python) to see their merits and pitfalls and to reassure you that Delphi is THE language for you.

How is this book written?

The pace of this book is allegro, because there are many things to learn and only a limited amount of paper to write them down.

The tone will be non-conformist, light and funny, with jokes here and there and quite some colorful language.

 

Most important, in my books I will never ask you to just believe me. I hate the “because I said so” mentality. Instead, I will back up my statements with hard evidence: links to white papers, scientific articles, proved concepts, code examples, benchmark tests.

 

I spent six years writing the “Delphi in all its glory” series. I hope I did it right. I am a self-taught English speaker, so my English is not perfect, but I don’t care much about this. What I truly care about is the correctitude of information provided in this book.

 

If you have feedback about this book, or you’re as geek and passionate about programming as I am, I invite you to not only to explore the contents of this book but also to actively discuss with me. I am always open to exchange of ideas.

So, find me at  www.GabrielMoraru.com.

Environment-responsible

In order to reduce the amount of paper used, I tried to increase the information density. Even though it might not look as aesthetic as other books which waste 25% of the page with headers and footers and 2-line spacings, I feel good because I know I did my best to preserve our forests. I love the planet that I live on, and I want to keep it green.

Part of the paper used in this book is recycled paper.

 

Most books are read once, then placed onto a book shelve and kept there until the pages turn yellow. Once you are done with this book, please consider lending it to your friends, donating it to a library or even reselling it.

Who am I?

Embark on a journey through Delphi programming with me, Gabriel Moraru, a senior software architect with almost three decades of experience in programming. I’ve been immersed in the world of Pascal and Delphi since 1995 but I actually started as a Z80 programmer, back in the day when the all 8-bit magic started. My academic background in applied electronics and computer science has laid the foundation for crafting innovative software and hardware solutions.

My expertise spans medical, big data, e-commerce, bioinformatics, and robotics domains, reflecting a passion for versatile creation.

Active member in the Stack Overflow community, I enjoy sharing knowledge and am contributing to the Pascal ecosystem with free and commercial Delphi libraries.

 

This is my second book, with two more on the horizon.

Pre-requisites for this book

  1. Delphi 10.4 (or 11 or 12) Community edition, which is free.

Older Delphi versions will also do it, but you will have to make tiny-tiny changes to the code since in this book I use the new inline var declarations (introduced in Delphi 10.4).

  1. The first book did not require any Delphi programming skills. However, is book is written with the supposition that you have some basic Delphi skills or that you already read the first book!

TOC

 

1. Overview 3
For whom is this book for? 3
What is Delphi? 4
What will you learn from this book? 4
Book layout 5
Who am I? 5
How is this book written? 6
Environment-responsible 7
Pre-requisites for this book 7
Let’s start 7
2. Table of content 8
3. What is Delphi? 18
Delphi is RAD 18
Delphi is general-purpose 18
Delphi has deep roots 18
Delphi = GUI 20
What is the VCL? 21
What is RAD Studio? 22
An IDE with multiple personalities. How does it work? 22
A complete IDE 24
Mature and polished 24
But, it must be expensive… right? 25
What can we build right out of the box, with Delphi? 27
Advantages of Delphi applications 29
Where can we use Delphi? 32
Where can’t we use Delphi? 32
Delphi’s productivity 32
Famous programs built with Delphi 33
Summary 34
4. Delphi today 35
Popularity 36
About Evil, Darth Vader and… Bill Gates 36
Availability of libraries 37
A brighter future 38
Tiobe Index 39
Summary 40
5. An overview of the Delphi language
Clarity 41
A strongly typed language 41
Well designed 42
One string to rule them all 42
Not open-source 42
Fastest compiler 43
Finally! A compiler that is not snarky 43
No more pointers 45
ASM in the mix 46
Damn fast 46
What kind of applications can we build with Delphi? 47
Why building apps is so easy with Delphi? 48
Delphi is WYSIWYG 48
Quick mockups 48
The VCL framework 49
Low code / no code 49
Portable code 50
Native look 50
Ready for the future 51
The never-ending story 51
Summary 52
6. The Pascal dynasty
Lazarus / FPC 54
Migrating to Lazarus 54
Unitary framework 55
Platforms 56
Compatibility with Delphi 57
Delphi’s cousin 58
Delphi and C++ are binary “compatible” 58
Summary 58
The “Burning Monkey” 59
A bit of history 59
Firemoneky = VCL on steroids 60
7. Installing Delphi
Delphi version 62
Time 62
License key 62
ISO installer 62
The installation folder 63
Delphi version info 67
Updates 67
We are done 68
8. Let’s get started
Anatomy of a Delphi Project 70
The Project Manager 70
Project Options 73
The DProj: DPR’s little brother 78
The anatomy of a Delphi unit 80
The “Unit” section 80
The “Interface” and “Implementation” section 81
The Chicken and the egg 84
The {$R} section 84
The “Initialization” and the “Finalization” section 85
9. IDE this… IDE that…
The main menu 89
File 89
Edit 89
Search 89
Refactor 90
Run 90
GExperts and CnPack 90
Project 91
The main panes of the IDE 93
The Project Manager 93
The Component Palette 94
The Object Inspector 94
The Messages window 95
Form designer 95
The Code Editor 96
The Form Designer 98
Common IDE shortcuts 100
Run 100
Run (debug mode) 100
Show (IDE panes) 100
Search 101
Code Editor useful keyboard shortcuts 101
Customizing the IDE 103
Dual monitor 104
IDE Layouts 104
Third party IDE plugins for Delphi 105
DDevExtensions 105
CnPack 106
GExperts 110
Building our own plugins 111
Plugin management 112
10. Our first Delphi application
Smallest Delphi application 114
Let’s start 116
Form = PAS + DFM 121
11. A crash course in the Delphi language
If you already know C++ 123
A typical piece of Delphi code 125
Comments 127
Variables 128
What is a variable? 128
What are data types? 128
Declaring variables 128
General naming conventions in Delphi 130
Naming variables 132
Global versus local variables 133
How do computers store numbers in their memory? 134
Assigning values to a variable 138
Variable initialization 141
Constants 146
Arithmetic operators 147
Data types 148
Primitive Data Types 148
Managed Data Types 159
Delphi is “strong typed” 181
Records 184
Assigning records 186
Field initialization 190
With 196
Displaying a message 198
If/Then/Else 200
Crafting Conditions 200
Nesting for Precision 201
Case 204
FOR loops 206
While 211
Repeat/Until 212
Routines 213
Compartmentalizing your code 213
Reusing the code 214
Procedures 215
Functions 217
Good practice 224
Statement separator 224
How does a computer program work? 225
Nested routines 226
Function overloading 227
Parameters of a routine 228
Not all parameters are created equal 231
Code analysis 237
12. Classes and objects
Why objects? 243
An object 244
Objects vs classes 246
Naming conventions 246
Instantiation 246
Extensibility 247
Constructors 248
Let’s build our own class 249
Inherited 250
Destructors 251
Try/Finally 251
Super-duper important 252
Special cases 253
Fields 255
Properties 256
Read-only properties 259
Recap 259
Published properties 260
Default 261
Manual memory management for objects 263
Pointers 271
Typed vs untyped pointers 271
Dereferencing a pointer 272
Assigning pointers 275
References 279
Dangling references 281
Assigning an object to another object 286
Objects – A real world example 287
Inheritance, polymorphism, and typecasting 289
The inheritance chain 289
Typecasting 291
The hard typecast 293
The ‘as’ typecast 294
The ‘is’ operator 295
Invalid typecasts 296
More invalid typecasts 296
RTTI alternative 298
Methods 299
Method binding 299
Speed 300
Static methods 300
Overriding methods / Polymorphic behavior 302
Polymorphism 305
Hiding vs overriding 308
VMT 311
Overloading methods 312
Declaring multiple constructors with different parameters 316
Keywords recap 321
Recap for polymorphism 321
Methods – Advanced topics 322
Class methods 322
Concrete example 322
Let’s write a better example 324
Class fields 325
Putting class fields to a good use – Singleton class 326
Using it for real 328
Predefined class methods in TObject 329
Abstract methods 330
Abstract classes 334
Generics 335
Creating a generic class 337
13. Forms
PAS + DFM = Form 341
Auto-created forms 343
The main form 344
Secondary forms 345
Stay on top 350
An application without forms 351
The “Application” object 352
Showing a new created form 353
The owner of a form 354
Application as owner 354
Form as owner 354
Nil as owner (no owner) 354
Initialization of a program 355
Closing a form 360
Several ways to close a form 361
Release versus Close 365
Experimenting with Free, Close and Release 366
About GUI Applications 372
So, why do we need GUIs? 372
Let there be mockups! 380
Save GUI state to file 385
Summary 385
14. Visual components
Ownership 387
Parenting 388
Parenting and modularization 391
Ownership vs Parenting 392
Properties of a component 394
Events and event handlers 396
Understanding events 396
Some examples 398
Event handlers are just properties 402
The ubiquitous Sender parameter 403
Building our own visual components 406
Most used visual components 407
TLabel 407
TButton 407
TPanel 407
TRadioButton 408
TCheckBox 408
TImage 408
TEdit 409
TMemo 409
TRichEdit 410
TSpinEdit 410
TTimer 410
More visual components 412
TTrayIcon 412
TFlowPanel 416
TGridPanel 418
Actions / TActionList 421
TActionManager 432
Customizable toolbars 432
15. Databases
FireDAC 442
16. What’s next
17. Appendix
Files generated by Delphi 446
Example of ASM code in PAS file: 447
Delphi releases 448
What’s new since Delphi 10.0? 450
18. Notes and credits
Contact me! 454
Disclaimer 454
Source code 454
Credits 454

Scroll to Top