Fearless Cross-Platform Development with Delphi - David Cornelius - E-Book

Fearless Cross-Platform Development with Delphi E-Book

David Cornelius

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Delphi is a strongly typed, event-driven programming language with a rich ecosystem of frameworks and support tools. It comes with an extensive set of web and database libraries for rapid application development on desktop, mobile, and internet-enabled devices. This book will help you keep up with the latest IDE features and provide a sound foundation of project management and recent language enhancements to take your productivity to the next level.
You’ll discover how simple it is to support popular mobile device features such as sensors, cameras, and GPS. The book will help you feel comfortable working with FireMonkey and styles and incorporating 3D user interfaces in new ways. As you advance, you’ll be able to build cross-platform solutions that not only look native but also take advantage of a wide array of device capabilities. You’ll also learn how to use embedded databases, such as SQLite and InterBase ToGo, synchronizing them with your own custom backend servers or modules using the powerful RAD Server engine. The book concludes by sharing tips for testing and deploying your end-to-end application suite for a smooth user experience.
By the end of this book, you’ll be able to deliver modern enterprise applications using Delphi confidently.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 605

Veröffentlichungsjahr: 2021

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Fearless Cross-Platform Development with Delphi

Expand your Delphi skills to build a new generation of Windows, web, mobile, and IoT applications

David Cornelius

BIRMINGHAM—MUMBAI

Fearless Cross-Platform Development with Delphi

Copyright © 2021 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Richa Tripathi

Publishing Product Manager: Alok Dhuri

Senior Editor: Rohit Singh

Content Development Editor: Kinnari Chohan

Technical Editor: Maran Fernandes

Copy Editor: Safis Editing

Project Coordinator: Deeksha Thakkar

Proofreader: Safis Editing

Indexer: Pratik Shirodkar

Production Designer: Joshua Misquitta

First published: September 2021

Production reference: 2151121

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80020-382-2

www.packt.com

To my wife, Terresa, for her incredible patience and support during the writing of this book.

– David

Contributors

About the author

David Cornelius is a software engineer in the Pacific Northwest of the US with over 30 years of experience writing applications for education, research, finance, inventory management, and retail. He has been the coordinator for the Oregon Delphi User Group for two decades and keeps active in various online forums. David is the founder and principal developer at Cornelius Concepts, LLC. and an Embarcadero MVP.

In his spare time, he likes to ride his motorcycle, escape the city with his RV, play the tuba or bass guitar, and play strategy board games with friends.

I would like to thank, first of all, my technical reviewers, Jonathan Eaton and Marco Breveglieri, and the editors at Packt Publishing who helped me see things from the perspective of the reader and caught project errors and omissions I submitted to GitHub (which I tried to pass off as challenges to the readers). They certainly saved me much embarrassment and helped ensure the book you have makes sense—and the sample programs actually compile!

I would also like to thank attendees of the Oregon Delphi User Group, a small but loyal band of awesome Delphi programmer friends, who have been cheerleaders for my writing efforts.

Finally, I very much appreciate the love and support that friends and family have given me even when they didn't fully understand what I was writing about. They helped more than they know.

About the reviewer

Jonathan Eaton is a Texan who loves living in Oregon. He has been an avid professional user of Delphi ever since he used it for a Y2K project way back in 1999. Since then, he has used Delphi to design, develop, and update software applications for a variety of industries, including chemical mixing, mineral asset accounting, insurance form processing, commercial real estate appraisal, and the development of software components of medical devices. In 2013, Jonathan became an ASQ Certified Software Quality Engineer and has been a strong proponent for the application of the principles of quality management to software development ever since. He's also written and self-published three novels and several collections of short stories.

Marco Breveglieri is a software and web developer. He started programming when he was 14 and got his first home personal computer, a beloved Commodore 16. Going forward—and getting serious—years later he attended secondary school focusing on computer science, continuing that learning path and taking his first steps from BASIC to Pascal and C++. Today, Marco continues to work for his own IT company using Delphi to create any kind of application. He also uses Visual Studio to build websites, using the Microsoft web stack based on the .NET Framework. He often takes part in technical conferences and holds training courses about programming with all these tools, especially Delphi, C#, and the web standards HTML5, JavaScript, and CSS3.

Table of Contents

Preface

Section 1: Programming Power

Chapter 1: Recent IDE Enhancements

Understanding the Delphi IDE

Delphi 10 Seattle

Delphi 10.1 Berlin

Delphi 10.2 Tokyo

Delphi 10.3 Rio

Delphi 10.4 Sydney

Summary

Questions

Further reading

Chapter 2: Delphi Project Management

Technical requirements

Creating a console application23

Building a Windows VCL application24

Starting a multi-device application25

Working with dynamic libraries29

Understanding packages30

Dealing with Android services30

Customizing your favorite project types31

Using build configurations effectively

Build events32

Working with related projects

Managing source modifications

Looking through your code history36

Integrating source repositories38

Using the command-line tools for build automation

Summary

Questions

Further reading

Chapter 3: A Modern-Day Language

Technical requirements

Remembering Delphi's Pascal roots

Reviewing the syntax48

Growing a language

Adding objects to Pascal50

Promising functionality with interfaces52

Handling unknown data types52

Supporting nested types53

Migrating to Unicode55

Applying strong type checking generically56

Adding anonymous methods for cleaner code60

Adding metadata to your classes with attributes62

Learning about the latest enhancements

Simplifying variable declaration72

Controlling initialization and the finalization of records73

Summary

Questions

Further reading

Section 2: Cross-Platform Power

Chapter 4: Multiple Platforms, One Code Base

Technical requirements

Moving to FireMonkey from the VCL

Starting a new Windows FireMonkey project83

Migrating an existing Windows VCL application to use FireMonkey86

Preparing other platforms

Preparing a Mac for cross-platform development88

Running your first cross-platform application90

Preparing for iOS development and deployment94

Preparing your PC to deploy to an Android device102

Working with various screen sizes

Exploring target views104

Writing code to support multiple platforms

Summary

Questions

Further reading

Chapter 5: Libraries, Packages, and Components

Technical requirements

Sharing code in libraries

Things to keep in mind for the Windows platform113

Loading libraries dynamically versus statically113

Things to keep in mind for non-Windows platforms116

Putting code into packages

Working with package filenames122

Turning a package into a component

Creating our first component124

Adding in the code to a component126

Adding design-time properties to a component128

Adding cross-platform support to components130

Summary

Questions

Further reading

Chapter 6: All About LiveBindings

Technical requirements

Using the LiveBindings designer to get started quickly

Using layers to group LiveBindings elements139

Revealing embedded component properties140

Creating magic with the LiveBindings Wizard

Pulling in fields from a database143

Adding more controls through the wizard145

Prototyping custom objects at design time147

Swapping out prototype data for your own custom data149

Applying custom formatting and parsing to your bound data

Getting to the BindingsList153

Customizing the display154

Parsing edited data156

Coding your own LiveBindings methods

Summary

Questions

Further reading

Chapter 7: FireMonkey Styles

Technical requirements

Understanding and using FireMonkey styles

Loading style sets165

Selecting between multiple StyleBooks167

Accessing substyle definitions169

Customizing FireMonkey styles with the Style Designer

Creating a default style for a control type171

Creating a custom style for a specific control172

Styling your applications with ease

Quickly setting a single, application-wide style174

Customizing styles per form175

Managing style resources with code176

Summary

Questions

Further reading

Chapter 8: Exploring the World of 3D

Technical requirements

Getting started with 3D in Delphi

Adding 2D controls to a 3D form189

Adding basic and extruded shapes

Showing lines for the axes190

Extruded shapes190

User-defined shapes192

Adding color, lighting, and movement

Adding a light source to colors and textures194

Coloring extruded objects197

Adding animation198

Animating color199

Importing 3D models

Changing the camera

Multiple cameras203

Satellite camera205

Testing on phones206

Let's write a game!

Implementing hidden clickable areas210

Activating and deactivating an object213

Mixing 2D and 3D controls for best use of each215

Working with layered objects at design time217

Deciding on the end game218

Summary

Questions

Further reading

Section 3: Mobile Power

Chapter 9: Mobile Data Storage

Technical requirements

Comparing different approaches

Learning about InterBase's editions225

Introducing SQLite226

Managing databases

Using the InterBase Server Manager and IBConsole228

Trying out SQLite Studio233

Setting up access to tables and queries

Utilizing FireDAC, Delphi's cross-platform Data Access Component236

Getting table and query records from InterBase238

Getting table and query records from SQLite245

Deploying your database

Deploying IBLite and IBToGo250

Updating data on a mobile device

Understanding touch-oriented interfaces252

Summary

Questions

Further reading

Chapter 10: Cameras, the GPS, and More

Technical requirements

Setting up258

Establishing a base

Getting permission

Setting up permissions for Android apps265

Using sensitive services on iOS268

Capturing your neighborhood

Saving an image to the database270

Loading previously taken images272

Expanding your use of the camera274

Marking your spot

Getting permission for location services275

Saving coordinates in the database278

Showing the location in the list view279

Mapping your way

Setting up a Google Maps API key for Android282

Setting up your Delphi project to use Google Maps284

Plotting park points284

Changing the map style287

Sharing your pictures

Summary

Questions

Further reading

Chapter 11: Extending Delphi with Bluetooth, IoT, and Raspberry Pi

Technical requirements

Starting with Bluetooth Classic

Configuring Classic Bluetooth295

Discovering and pairing devices298

Publishing Bluetooth services302

Connecting and communicating306

Learning about low-energy Bluetooth

Utilizing beacons

Setting up a beacon server app313

Finding and reacting to beacon messages317

Fencing your application321

Doing more with the Internet of Things

Discovering and managing your device323

Getting data from IoT devices323

Using a Raspberry Pi

Using Android to run your apps on a Raspberry Pi325

Summary

Questions

Further reading

Section 4: Server Power

Chapter 12: Console-Based Server Apps and Services

Technical requirements

Starting with console apps on Windows and Linux

Installing the Windows subsystem for Linux335

Running our first Linux app336

Adding a simple database lookup module337

Testing the data module with a console app340

Providing remote server connectivity for clients

Testing with a console client348

Logging activity

Sending logs in two directions354

Adding a custom logging mechanism356

Creating a Windows service

Logging to the Windows Event Log362

Adopting a Linux daemon

Exposing your server to the world

Modifying our client app to use the new server369

Summary

Questions

Further reading

Chapter 13: Web Modules for IIS and Apache

Technical requirements

Surveying website-building options in Delphi

Understanding the Web Server Application wizard376

Getting comfortable with the underlying framework

Templating your HTML380

Building an ISAPI web module for IIS on Windows

Logging from an ISAPI web module397

Getting started with the Apache HTTP server

Installing and starting Apache on Windows400

Installing and starting Apache on Linux402

Writing cross-platform Apache web modules

Deploying an Apache web module on Windows406

Deploying an Apache web module on Linux408

Summary

Questions

Further reading

Chapter 14: Using the RAD Server

Technical requirements

Establishing a use case for RAD Server

Considering an application's multi-user needs416

Enabling push notifications for registered devices417

Justifying the cost418

Getting familiar with what's included

Running RAD Server on a development environment419

Using the RAD Server Management Console426

Writing modules to extend your server

Using the wizard to create our first resource package428

Implementing MyParks for RAD Server432

Building a REST server without code436

Testing RAD Server with the REST Debugger439

Inserting, updating, and deleting data442

Modifying MyParks for use with RAD Server

Setting up RAD Server connection components446

Sending updates back to RAD Server452

Summary

Questions

Further reading

Chapter 15: Deploying an Application Suite

Technical requirements

Configuring for a wide audience

Getting settings in desktop applications460

Updating a web module with dynamic settings462

Updating a RAD Server package with dynamic settings465

Reviewing mobile data storage locations466

Securing data

Securing your server's data transmission468

Controlling access to resources468

Adding application security for RAD Server clients473

Protecting your hardware and operating system474

Adding a graphical touch

Iconifying desktop apps476

Iconifying mobile apps476

Setting splash screen options on iOS479

Creating splash screens for Android480

Establishing product identity

Including Windows version information481

Identifying your Apple product481

Identifying your Android product482

Testing for deployment

Using virtual machines 483

Testing the wide range of mobile devices484

Distributing the final product

Installing RAD Server modules to production486

Selecting deployment configuration487

Deploying macOS and iOS applications 488

Deploying an Android app 489

Summary

Questions

Further reading

Assessments

Chapter 1 – Recent IDE Enhancements

Chapter 2 – Delphi Project Management

Chapter 3 – A Modern-Day Language

Chapter 4 – Multiple Platforms, One Code Base

Chapter 5 – Libraries, Packages, and Components

Chapter 6 – All about LiveBindings

Chapter 7 – FireMonkey Styles

Chapter 8 – Exploring the World of 3D

Chapter 9 – Mobile Data Storage

Chapter 10 – Cameras, the GPS, and More

Chapter 11 – Extending Delphi with Bluetooth, IoT, and Raspberry Pi

Chapter 12 – Console-Based Server Apps and Services

Chapter 13 – Web Modules for IIS and Apache

Chapter 14 – Using RAD Server

Chapter 15 – Deploying an Application Suite

Why subscribe?

Other Books You May Enjoy

Preface

A favorite author once penned, "Resistance to change leads to catastrophic change." I fully believe that and, in this field, learning and growing and yes, changing, is good—anything else is career death.

Delphi has been around for over 25 years, but it is anything but old. The language, libraries, and toolset are not stagnant and applications built with this suite of compilers rival those of competing products. Continual updates, frequent webinars, lively forum debates, a recent explosion of books, and a myriad of blog sites are evidence of a rich and active developer community.

This book takes you on a journey. This journey will build upon and extend the hours you've invested in creating beautiful desktop applications and teach you how to craft new, globally usable mobile apps and backend servers that power today's interconnected platforms. Technology has exploded with ways to communicate and share data between apps, web services, and devices of all kinds. People demand choices—choice of operating system, choice of style, choice of screen size, and choice of location.

Companies everywhere have risen to the challenge of providing options to satisfy these customer demands with unique tools that market to a new generation of developers. Are you feeling left behind, wondering how to move forward?

Reading this book will expand your Delphi programming skill set in a step-by-step manner, explaining what you need to know to handle the variety of challenges addressing new platforms will bring. And we'll have fun along the way. We'll build database applications that have sample data built in to make prototyping easier than ever. We'll build a 3D game you can play on your smartphone. We'll create a full-featured mobile app you can extend for your own creative uses. We'll also build powerful backend REST servers with virtually no code.

Take this journey with me to multiple platforms—fearlessly!

Who this book is for

This book is written mostly for the Delphi programmer who is confident on the Windows platform with the VCL but unsure what mobile development will mean for them. If you're relatively new to Delphi programming, this book will be a quick jump start into the rich and wonderful integrated development environment we all love—you'll figure it out quickly!

The experienced cross-platform developer will likely seek me out on a forum and point out obvious things I missed. I'm sorry in advance—this was a journey for me as well!

What this book covers

Chapter 1, Recent IDE Enhancements, will help you get up to speed quickly, starting with an understanding of the many parts of the IDE, and then explaining "What's new?" in each of the last five major versions.

Chapter 2, Delphi Project Management, simplifies the bewildering choice of where to start! With so many platforms and project templates, deciding how to create a new app can itself be overwhelming. We'll explore build configurations, shortcuts to managing options and project groups, and show you how to use the command-line compiler for automation.

Chapter 3, A Modern-Day Language, clears up any misunderstanding that Delphi is not capable of building cross-platform apps. We'll showcase enhancements made through the years to the Pascal-based syntax that facilitated the flexible and powerful language it is today.

Chapter 4, Multiple Platforms, One Code Base, is where we'll really start diving into cross-platform topics. The first step in that direction is learning about FireMonkey—we will take you carefully through several differences compared with the VCL in some simple apps so you can get comfortable quickly. Then we introduce various form factors of mobile devices and show how to manage them in Delphi. Finally, we cover several conditional compilation constants you'll need to know in order to separate code for specific platforms.

Chapter 5, Libraries, Packages, and Components, is an important chapter as writing a simple DLL isn't so simple when you have to deploy to platforms other than Windows—we cover several gotchas that you need to know. After we build both a dynamic library and a package (and why you might need one over the other), we turn a package into a cross-platform component.

Chapter 6, All About LiveBindings, explains how this expression-based data connector technology is more than just a replacement for data-aware controls in Delphi. The LiveBindings Designer is explained with tips on organizing with layers. We demonstrate how the LiveBindings Wizard can create components for you already hooked up to your data. Finally, we use custom formatting and parsing—and end with code that creates custom LiveBinding methods installed in Delphi.

Chapter 7, FireMonkey Styles, uncovers the nuances of styling a FireMonkey application and how to use and customize FireMonkey styles effectively for a distinctive appearance. We will build a simple app with a variety of controls and four different styles that you can run on each of your devices to see the differences.

Chapter 8, Exploring the World of 3D, is a fun chapter that demonstrates how you can use your favorite programming tool to utilize popular GPU engine libraries with ease. We build a simple app with a variety of 3D shapes, textures, lighting, and cameras for a broad overview of the capabilities. We end the chapter by using some of these techniques and more to build an escape game you can play on your phone!

Chapter 9, Mobile Data Storage, shows how well FireDAC works with different database products on multiple platforms, comparing one application that uses InterBase ToGo and a similar one using SQLite. We'll answer questions on licensing, explore free management tools, and offer tips for working with touchscreen devices.

Chapter 10, Cameras, the GPS, and More, demonstrates the power of the FireMonkey library to encapsulate various platform capabilities in simple components that you can readily use in your apps. We'll also build a database-enabled mobile app that utilizes techniques learned in previous chapters but that will grow in functionality for the rest of this book.

Chapter 11, Extending Delphi with Bluetooth, IoT, and Raspberry Pi!, explores various types of Bluetooth technologies, including BLE, which is what beacons are based on. We dive further and show how BLE is the basis for all IoT components and explain how to use ThingConnect components you can get from GetIt. We conclude this chapter on small devices by demonstrating how to deploy a Delphi app to a Raspberry Pi.

Chapter 12, Console-Based Server Apps and Services, switches gears from small, mobile devices to server technologies. We create both Windows services and Linux daemons and also show how to take an open source project and modify it for our own needs when we need to implement custom logging.

Chapter 13, Web Modules for IIS and Apache, continues the server discussion by concentrating on web server modules for the two most popular web servers – IIS on Windows, and Apache for both Windows and Linux. We bring over the data module tested in our console-based server and use WebBroker to build a simple but nice-looking web page that displays data in a grid with very little code.

Chapter 14, Using the RAD Server, is a big chapter covering a big product available for Delphi Enterprise and up that serves as another type of platform, one that provides a REST server in a box where you only add your custom business methods. We teach what RAD Server brings to the table, why it can pay for itself, and how to write modules for it. Then we go one step further and modify our sample mobile app to use it.

Chapter 15, Deploying an Application Suite, culminates the application development process by covering important aspects of deploying to production with discussions about externally defined configuration files, various security concerns, application icons and identity, testing, the installation of server backends, and mobile app submission.

To get the most out of this book

You will need Embarcadero Delphi 10.4 Sydney Professional or Enterprise on Windows 64-bit with access to one or more mobile platforms on which you can deploy and test the sample applications:

You will need the Enterprise edition of Delphi to build Linux apps or RAD Server modules. Also, while the Community Edition may be used for many of the examples, you may be restricted from downloading from the GetIt portal.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Fearless-Cross-Platform-Development-with-Delphi. If there's an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781800203822_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Back in the form unit, uCardPanel.pas, it starts with the unit keyword and has both an interface and implementation section, each with a uses clause."

A block of code is set as follows:

procedure TfrmPeopleList.lbPeopleClick(Sender: TObject);

var

  APerson: TPerson;

begin

  if lbPeople.ItemIndex > -1 then begin

    APerson := lbPeople.Items.Objects[lbPeople.ItemIndex]

                  as TPerson;

    lblPersonName.Caption := APerson.FirstName + ' ' +

                             APerson.LastName;

    lblPersonDOB.Caption  := FormatDateTime('yyyy-mm-dd',

                                 APerson.DateOfBirth);

  end;

end;

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

constructor TfrmPeopleList.TPerson.Create(

                       NewFN, NewLN string; NewDOB: TDate);

begin

  FFirstName := NewFN;

  FLastName  := NewLN;

  FDateOfBirth := NewDOB;

end;

Bold: Indicates a new term, an important word, or words that you see on screen. For instance, words in menus or dialog boxes appear in bold. Here is an example:

"Under the Develop section of Delphi's default Welcome page, click the Open a sample project… link and drill down through the Object Pascal, VCL, and CardPanel folders, and then open the CardPanel project."

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you've read Fearless Cross-Platform Development with Delphi, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.

Section 1: Programming Power

This section introduces Delphi as a powerful programming tool for fully embracing cross-platform development, explains why it's so much more than just a legacy Windows compiler, and helps get you up to speed with the latest IDE and language enhancements that accelerate development and decrease the time to market. This foundational knowledge sets the stage for the rest of the book, helping you to navigate the IDE, write efficient code, drop to the command line if you need, and become familiar with new programming constructs.

This section comprises the following chapters:

Chapter 1, Recent IDE EnhancementsChapter 2, Delphi Project ManagementChapter 3, A Modern-Day Language

Chapter 2: Delphi Project Management

There are many types of projects that Delphi can build: standalone desktop applications for Windows and Mac, mobile apps for Android and iOS smartphones and tablets, Linux daemons, Android packages and services, and even plugin packages to add functionality within Delphi itself; all types are possible. If all you've ever built are Windows Visual Component Library (VCL) applications, it may be daunting to consider other platforms. But Delphi 10.4 is a very capable toolset, having simplified the steps you need to take, which allows you to concentrate on what you do best—building great software! Most of the heavy lifting is done for you when supporting other platforms, so it's time to extend your skills to these devices.

To help you down the right path, you need to know about the project types, target platforms, and starting templates available and how to best utilize them. After reading this chapter, you will have no difficulty knowing where to start. Additionally, you'll learn when to use debug and release configurations to separate testing and deployment scenarios, how to integrate version control right within the IDE, and how to set up automation both inside the IDE with build events and outside with command-line tools. These topics will be covered in the following sections:

Exploring project types and target platformsUsing build configurations effectivelyWorking with related projectsManaging source modifications Using the command-line tools for build automation

Technical requirements

This chapter simply requires using Delphi on a Windows 10 machine to explore different project types. There will be screenshots of short example applications running on different platforms but they will be brief and only exist to showcase what lies ahead. The code for a couple of small Windows projects, including a batch script for compiling several projects is on GitHub at: https://github.com/PacktPublishing/Fearless-Cross-Platform-Development-with-Delphi/tree/master/Chapter02

Exploring project types and target platforms

As we look at each project type in this section, there will be different target platforms available. For example, a Windows VCL application can only be built on Windows platforms (either 32-bit or 64-bit), but a multi-device application can have several different target platforms. This is shown in the Projects window as the second sub-item under the project name and can be expanded to show the currently supported platforms added for that project. To add support for other platforms, right-click on Target Platforms and select from the list available. For example, a new multi-device application comes supporting six targets by default, but you can also add iOS Simulator:

Figure 2.1 – Adding and selecting a target platform

As we talk about the different project types and what platforms are available for each, this is how you add support for platforms that are not initially added to your project. You can only compile for one target at a time; the currently selected target is shown in parentheses next to the Target Platforms header.

Creating a console application

If you don't need a rich interface with complex graphical controls, you may need nothing more than a console application. This is the simplest project type and is often used for small utility programs, automated unit testing, and prototyping Windows services or IIS modules. It can write output to the console using Writeln and pause for input using Readln but does not include any graphical libraries. Console applications can be built on Windows, Linux (Enterprise or Architect edition), or Mac OS X—and even though you can add platforms for Android and iOS, there seems to be no documentation or support on how to run console apps on mobile platforms.

To create a console application, select File | New | Other from the menu and select Console Application. A single source file is created with the program keyword and a compiler directive of {$APPTYPE CONSOLE}. All the sources can be contained in this one file and the program flow is simple and contained within the begin-end block created for you. The compiled application on Windows will be .EXE.

Running this will bring up a console window, typically with a black background and white text, and any output you've added to the application is displayed in a scrolling window within this box. You can add code to read text entered from the keyboard using Readln—which, if you're running it from the IDE, you will need to do in order to keep it from finishing and closing so quickly that you miss seeing any output.

Here's what a simple console application looks like when running:

Figure 2.2 – Windows 64-bit console application

We will use console apps to demonstrate language concepts and to test Windows services in later chapters.

Building a Windows VCL application

A Windows VCL application has been the most common project type since the first version of Delphi. In fact, the main reason Delphi was created was to make it easier to develop Windows applications by replacing the Object Windows Library (OWL) framework used in Borland Pascal as wrappers around the Windows API. The VCL hides a lot of complexity and yet provides an extensible hierarchy of object-oriented components to ease the development of any type of Windows application.

To start one of these project types, select File | New | Other and select Windows VCL Application. A project source file is created with the program keyword and a "form" unit is added, which comprises two physical files: a .DFM, or Delphi, form, and .PAS, the source for this form with the unit keyword at the top of the file. The extension of the compiled application will be .EXE, for "executable."

Without doing anything else, simply building and running this project immediately launches a Windows application with one form that can be moved around the screen and closed like any other Windows application.