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.

Order the book in electronic of printed format.

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

(Last update/ 07.2024)

1. Overview 3
Intended Audience 3
What is Delphi? 4
Book layout 4
Always focused on code-safety 5
How is this book written? 5
Environment-responsible 6
Who am I? 6
Pre-requisites for this book 7
Let’s start 7
2. Table of content 8
Symbols and conventions 17
3. What is Delphi? 19
Delphi is RAD 19
Delphi is general-purpose 19
Delphi has deep roots 20
Delphi = GUI 21
What is the VCL? 23
What is RAD Studio? 24
An IDE with multiple personalities. How does it work? 24
A complete IDE 26
Mature and polished 26
But, it must be expensive… right? 27
What can we build right out of the box, with Delphi? 29
Advantages of Delphi applications 31
Where can we use Delphi? 34
Where can’t we use Delphi? 34
Delphi’s productivity 34
Famous programs built with Delphi 35
Summary 36
4. Delphi today 37
Popularity 38
About Evil, Darth Vader and… Bill Gates 38
Availability of libraries 39
A brighter future 41
Tiobe Index 42
Summary 44
5. An overview of the Delphi language 45
Clarity 45
A strongly typed language 46
Well designed 46
One string to rule them all 46
Not open-source 47
Fastest compiler 48
Finally! A compiler that is not snarky 48
No more pointers 50
ASM in the mix 51
Damn fast 51
What kind of applications can we build with Delphi? 52
Why building apps is so easy with Delphi? 53
Delphi is WYSIWYG 53
Quick mockups 53
The VCL framework 53
Low code / no code 54
Portable code 55
Native look 55
Ready for the future 56
The never-ending story 56
Summary 57
6. The Pascal dynasty 58
Lazarus / FPC 59
Migrating to Lazarus 59
Unitary framework 60
Platforms 61
Compatibility with Delphi 62
Speed 62
C++, Delphi’s cousin 63
Delphi and C++ are binary “compatible” 63
Summary 63
The “Burning Monkey” 64
A bit of history 64
Firemoneky = VCL on steroids 65
Deploying our application on other platforms 67
7. Installing Delphi 70
Delphi version 70
Time 70
License key 70
ISO installer 70
The installation folder 71
Delphi version info 75
Updates 75
Delphi Silent Installer 76
We are done 76
8. Let’s get started 77
Anatomy of a Delphi Project 78
Loading a Delphi project into the IDE 78
The DPR file 79
The Project Manager 81
The anatomy of a Delphi unit 84
The “Unit” section 84
The “Interface” and “Implementation” section 85
The chicken and the egg 87
The {$R} section 88
The “Initialization” and the “Finalization” section 88
Project Options 93
Compiler configurations 94
The Manifest file 96
Themes 97
The DProj: DPR’s little brother 99
Project paths 100
9. IDE this… IDE that… 102
The main menu 104
File 104
Edit 104
Search 104
Refactor 105
Run 105
GExperts and CnPack 105
Project 106
The main panes of the IDE 107
The Project Manager 107
The Component Palette 108
The Object Inspector 108
The Messages window 109
Form designer 109
The Code Editor 109
The Form Designer 112
Common IDE shortcuts 114
Run 114
Run (debug mode) 114
Show (IDE panes) 114
Search 114
Code Editor useful keyboard shortcuts 115
Customizing the IDE 116
Dual monitor 117
IDE Layouts 117
Third party IDE plugins for Delphi 118
DDevExtensions 118
CnPack 119
GExperts 123
Building our own plugins 124
Plugin management 125
10. Our first Delphi application 126
Smallest Delphi application 127
Let’s start 129
Form = PAS + DFM 134
11. A crash course into the Delphi language 136
If you already know C++ 136
A typical piece of Delphi code 138
Comments 141
Variables 142
What is a variable? 142
What are data types? 142
Declaring variables 142
General naming conventions in Delphi 144
Naming variables 146
Global versus local variables 147
How do computers store numbers in their memory? 149
Assigning values to a variable 153
Variable initialization 155
Constants 160
Arithmetic operators 161
Data types 163
Primitive Data Types 163
Managed Data Types 173
Delphi is “strong typed” 197
Records 199
Assigning records 201
Field initialization 205
With 210
Displaying a message 212
If/Then/Else 214
Nesting conditions 214
Case 217
Casey’s Coding Conundrum 217
The Quest for Enumerations 217
For loops 220
While 226
Repeat/Until 227
Routines 228
Compartmentalizing your code 228
Reusing the code 229
Procedures 231
Functions 233
Good practice 239
Statement separator 239
How does a computer program work? 240
Nested routines 241
Function overloading 242
Parameters of a routine 243
Not all parameters are created equal 246
Code analysis 252
12. Classes and objects 257
Why objects? 258
An object 259
Objects vs classes 261
Naming conventions 261
Instantiation 262
Extensibility 262
Constructors 263
Let’s build our own class 264
Inherited 265
Destructors 266
Try/Finally 266
Super-duper important 268
Special cases 268
Fields 270
Properties 271
Read-only properties 274
Recap 274
Published properties 275
Default 276
Objects require manual memory management 277
Pointers 284
Typed vs untyped pointers 284
Dereferencing a pointer 285
Assigning pointers 287
References 291
Dangling references 293
Assigning an object to another object 298
Objects – A real world example 299
Inheritance, polymorphism, and typecasting 301
The inheritance chain 301
Typecasting 303
The hard typecast 306
The ‘as’ typecast 306
The ‘is’ operator 307
Invalid typecasts 308
More invalid typecasts 309
RTTI alternative 311
Methods 313
Method binding 313
Speed 314
Static methods 314
Overriding methods / Polymorphic behavior 316
Polymorphism 319
Hiding vs overriding 323
VMT 325
Overloading methods 326
Declaring multiple constructors with different parameters 331
Keywords recap 334
Recap for polymorphism 334
Methods – Advanced topics 335
Class methods 335
Concrete example 335
Let’s write a better example 337
Class fields 338
Putting class fields to a good use – Singleton class 340
Using it for real 341
Predefined class methods in TObject 342
Abstract methods 344
Abstract classes 348
Generics 349
Creating a generic class 351
13. Forms 354
PAS + DFM = Form 355
Auto-created forms 357
The main form 358
Secondary forms 359
Stay on top 363
An application without forms 364
The “Application” object 366
Showing a new created form 367
The owner of a form 368
Application as owner 368
Form as owner 368
Nil as owner (no owner) 368
Initialization of a program 369
Closing a form 374
Several ways to close a form 376
Release versus Close 379
Experimenting with Free, Close and Release 380
About GUI Applications 386
So, why do we need GUIs? 386
Let there be mockups! 395
Save GUI state to file 399
Summary 399
14. Visual components 400
Ownership 402
Parenting 403
Parenting and modularization 405
Ownership vs Parenting 406
Recap 407
Properties of a component 408
Events and event handlers 410
Understanding events 410
Some examples 412
Event handlers are just properties 415
The ubiquitous Sender parameter 416
Building our own visual components 419
Most used visual components 420
TLabel 420
TButton 420
TPanel 421
TRadioButton 421
TCheckBox 421
TImage 422
TEdit 422
TMemo 423
TRichEdit 423
TSpinEdit 424
TTimer 424
More visual components 425
TTrayIcon 425
TFlowPanel 429
TGridPanel 431
Actions / TActionList 434
TActionManager 445
Customizable toolbars 446
15. Databases 453
FireDAC 453
16. All good things must come to an end 456
What I have learned in the last 25 years of software development 457
Where do you go from here? 462
Delphi sample projects 462
Your next big project could be a game 463
About Stack Overflow 463
Ask the artificial intelligence 465
Video tutorials 469
Delphi books 469
My books 471
Already published books 471
Next books 471
Notes and credits 473
Appendix 474
Files generated by Delphi 474
Example of ASM code in PAS file: 475
Delphi releases 476
What’s new since Delphi 10.0? 477

Scroll to Top