“Delphi Libraries & Packages” is the third book in “Delphi in all its glory” series. It was released in April 2024.
Order the book in electronic of printed format.
Book details
Motto
Unit A: use unit B.
Unit B: use unit A.
Book Layout
This book is hands-on, pragmatic, and focused on solving real-world issues.
We’ll start by studying the anatomy of a Delphi package and its famous BPL/DCP files. You’ll learn how packages can help organize your code, break circular references, and will do some Zen, studding the four rules of packaging.
Next, we’ll dive into the inner workings of Delphi’s library system (VCL), including how to recompile parts of it — if necessary.
From there, we’ll explore practical techniques: how to design and set up your own library system, leverage precompiled code to dramatically boost compilation speed, and, of course, tackle the ever-important topic of managing library paths.
While building custom visual components isn’t the primary focus, we’ll dedicate a chapter to it with sample code, including discussions about design-time and runtime packages.
Finally, to become true professionals, we’ll venture neck-deep into the gritty details of packages: the linker, package initialization, constructors and destructors, component streaming, component states, debugging packages, and even the IDE itself.
As you can see, no stone was left unturned in this book!
The Trilogy
This is the third book in a trilogy focusing on code safety and proper architecture design.
This trilogy emphasizes building stable programs through reliable code, avoiding common programming pitfalls, transforming mundane Delphi features into an error-prevention system, and understanding why some programming concepts are inherently safer than others.
Writing Style
The tone is fast-paced, light, and often humorous. There’s no “just trust me” here—every claim is backed by evidence: links to white papers, scientific articles, proven concepts, code examples, and benchmark tests.
Table of content
1. Overview 3
Intended Audience 3
Always focused on code-safety 4
How is this book written? 4
Environment-responsible 5
Who am I? 6
Pre-requisites for this book 6
Let’s start 6
2. Table of content 7
Symbols and conventions 15
3. Introduction 16
Why do we need libraries? 16
You could survive without libraries… if you develop a single, small program 17
4. What is a library 18
5. About libraries and licenses 20
Meaning of the fields 21
Discussions 23
GPL 23
LGPL – Dynamic vs static linking 23
Apache 23
Mozilla Public License 24
CC, MIT, BSD 24
Conclusions 24
6. The four rules of packages 25
Rule #1: Always separate your business-logic code from the GUI code. 25
Rule #2: There should be no floating units. 25
Rule #3: A unit can belong to a project (dpr, dpk) and only one project. 25
Rule #4: The unit of a low-level library cannot access a unit in a higher-level library. 25
7. Library architecture 27
Circular references 30
It is all about aliens and pyramids 31
When to start being a pharaoh? 31
8. The anatomy of a Delphi package 32
DPK 33
The “Contains” section 33
The “Requires” section 34
A unit can be contained by only one package 36
How do we fix this? 38
BPL/DCP 40
Where are the DCU, DCP & BPL files needed? 40
Design time BPLs 40
Chained packages 41
Changing the BPL folder 42
Project groups 44
Compiler Directives 45
9. Delphi’s framework
The RTL library 46
The VCL library 47
10. Compiler paths
Path precedence 49
Paths are unique for each platform 50
Environment variables 51
$(BDS) 51
$(ProductVersion) 51
$(Platform) 51
$(Config) 52
$(Auto) 52
Library paths 55
1. Delphi libraries 55
2. Third party libraries 56
3. Our own libraries 58
Do we really need Library Paths? 58
Search Paths 60
Abusing the search paths in packages 60
Abusing the search paths in projects 60
Under-development libraries 61
Global vs local paths 62
Recap 62
Other paths 64
Browsing path 64
Release vs Debug DCUs 65
Project paths 67
11. RTL/VCL is precompiled
Precompiling our own files 71
When to precompile our files? 71
The “Package output directory” fields 72
12. How to install a library?
Installing a library manually 74
1. Open the package 74
2. Install the package 74
3. Let the compiler find the library 75
4. Confirm that the library was installed correctly 77
Installing a library delivered without PAS files 78
Single-file libraries 79
What to do when things go south? 80
Library folder structure 81
Installing libraries via Setup 82
Creating our own installer 82
IDE plugins 83
Trivia 83
Installing libraries via GetIt 84
How to uninstall a library 85
13. Runtime/Designtime libraries
Run-time libraries 87
Design time libraries 88
Design time vs Runtime 89
Including a library in our project 91
14. Linking with runtime packages
Drawbacks 93
15. How does the linker optimize unused code?
Experiment calibration 98
Proceedings 99
Experiment 1 99
Experiment 2 99
Experiment 3 100
Experiment 4 100
Experiment 5 103
Results 104
Extension to the experiment 105
The design time package 105
Some definitions and clarifications 106
16. Recompiling parts of the VCL
1. Class hack 107
2. Recompile the patched VCL file 107
17. Why libraries are mandatory for large projects?
Logic separation 111
Business logic 111
The GUI code 111
Code separation 111
Parentheses – Image recognition algorithm 113
Applicability 113
Reusability of the code 115
Avoiding circular references 115
18. The chaos of monolithic projects
The Breaking Point 117
The Refractory Ignition Spark 117
A Better Way: Modular Code via Libraries 118
Overcoming Preconceptions 118
19. Using C/++ libraries in Delphi
When you have the source code 120
When you have the DLL 120
20. Package initialization
The Register procedure 126
21. Popular libraries
FastMM4 127
Graphics32 127
Delphi LightSaber 127
Jedi 128
TMS 129
LightSaber 130
22. Proteus Licensing System
What is Proteus? 140
Trial license 140
Rent license (aka subscription) 141
Permanent license 141
Modules 141
Free Proteus license for you 141
What can Proteus do for you? 142
Automates the process of selling your app. 142
Prevents fraud 142
HardwareID-based keys 14
Proteus can even do marketing 143
How to use it? (Overview) 144
Typical usage scenario 144
Is it difficult to integrate Proteus into my app? 144
Definitions 146
Certificate 146
Unlock key 147
Library structure 152
Classes 153
TProteus 153
RCertificate 153
Support code 155
Self protection 156
Under the hood 156
Anti-tampering system 156
Stolen keys 156
How to add a ‘Stolen keys’ list to your project? 157
Amnesty key 157
Certificate ID 158
Entering the same key twice 158
Active certificate 160
Initialization 160
Setting up your app – Step by step guide 161
Demo program 163
23. Building a visual component
General steps for creating a visual component 164
Writing our first visual component 165
24. All good things must come to an end
Where do you go from here? 174
Delphi sample projects 174
Your next big project could be a game 175
Ask the artificial intelligence 175
Books 178
Notes and credits 180