Book Image

Delphi Cookbook - Third Edition

By : Daniele Spinetti, Daniele Teti
Book Image

Delphi Cookbook - Third Edition

By: Daniele Spinetti, Daniele Teti

Overview of this book

Delphi is a cross-platform integrated development environment (IDE) that supports rapid application development on different platforms, saving you the pain of wandering amid GUI widget details or having to tackle inter-platform incompatibilities. Delphi Cookbook begins with the basics of Delphi and gets you acquainted with JSON format strings, XSLT transformations, Unicode encodings, and various types of streams. You’ll then move on to more advanced topics such as developing higher-order functions and using enumerators and run-time type information (RTTI). As you make your way through the chapters, you’ll understand Delphi RTL functions, use FireMonkey in a VCL application, and cover topics such as multithreading, using aparallel programming library and deploying Delphi on a server. You’ll take a look at the new feature of WebBroker Apache modules, join the mobile revolution with FireMonkey, and learn to build data-driven mobile user interfaces using the FireDAC database access framework. This book will also show you how to integrate your apps with Internet of Things (IoT). By the end of the book, you will have become proficient in Delphi by exploring its different aspects such as building cross-platforms and mobile applications, designing server-side programs, and integrating these programs with IoT.
Table of Contents (12 chapters)

Using the Parallel Programming Library in the real world: Parallel For/Join

One of the first loops that any programmer becomes familiar with is the for loop. In this recipe, we'll see a particular type of for loop—the parallel one. To be clear, this parallel for loop is not a new language feature, but is kind of implemented as a static class method.

The parallel for loop is part of the Parallel Programming Library, and is implemented by the TParallel class. Here's one of its (overloaded) versions and a utilization example:

//declaration 
class method TParallel.&For(ALowInclusive, AHighInclusive:  
  Integer; const AIteratorEvent: TProc<Integer>): TLoopResult; 
 
//used as follows 
TParallel.&For(1,10, 
  procedure(Index: Integer) 
  begin 
    //executed 10 times with index 1..10 
  end); 

What is different about the classic for? The difference is...