Book Image

Mastering Delphi Programming: A Complete Reference Guide

By : Primož Gabrijelčič
Book Image

Mastering Delphi Programming: A Complete Reference Guide

By: Primož Gabrijelčič

Overview of this book

Delphi is a cross-platform Integrated Development Environment (IDE) that supports rapid application development for most operating systems, including Microsoft Windows, iOS, and now Linux with RAD Studio 10.2. If you know how to use the features of Delphi, you can easily create scalable applications in no time. This Learning Path begins by explaining how to find performance bottlenecks and apply the correct algorithm to fix them. You'll brush up on tricks, techniques, and best practices to solve common design and architectural challenges. Then, you'll see how to leverage external libraries to write better-performing programs. You'll also learn about the eight most important patterns that'll enable you to develop and improve the interface between items and harmonize shared memories within threads. As you progress, you'll also delve into improving the performance of your code and mastering cross-platform RTL improvements. By the end of this Learning Path, you'll be able to address common design problems and feel confident while building scalable projects. This Learning Path includes content from the following Packt products: Delphi High Performance by Primož Gabrijel?i? Hands-On Design Patterns with Delphi by Primož Gabrijel?i?
Table of Contents (19 chapters)

Speeding up SlowCode

For the last practical example, we can try speeding up Mr. Smith's SlowCode from Chapter 1, About Performance. Here, we immediately ran into a problem. To fix or change an algorithm we must understand what the code does. This happens a lot in practice, especially when you inherit some code. Reading and understanding code that you didn't write is an important skill.

Let's try to understand the first part of SlowCode. The for loop in SlowMethod starts counting with 2. Then it calls ElementInDataDivides, which does nothing as the data list is empty. Next, SlowMethod adds 2 to the list.

Next, i takes the value of 3. ElementInDataDivides checks if 3 is divisible by 2. It is not, so SlowMethod adds 3 to the list.

In the next step, i = 4, it is divisible by 2, and 4 is not added to the list. 5 is then added to the list (it is not divisible...