Docsity

Delphi Succinctly, Notas de estudo de Matemática

Pré-visualização parcial do texto

Baixe Delphi Succinctly e outras Notas de estudo em PDF para Matemática, somente na Docsity!

Delphi Succinctly

By

Marco Breveglieri

Foreword by Daniel Jebaraj

Table of Contents

The Story behind the Succinctly Series

of Books

Daniel Jebaraj, Vice President Syncfusion, Inc.

taying on the cutting edge

As many of you may know, Syncfusion is a provider of software components for the Microsoft platform. This puts us in the exciting but challenging position of always being on the cutting edge.

Whenever platforms or tools are shipping out of Microsoft, which seems to be about every other week these days, we have to educate ourselves, quickly.

Information is plentiful but harder to digest

In reality, this translates into a lot of book orders, blog searches, and Twitter scans.

While more information is becoming available on the Internet and more and more books are being published, even on topics that are relatively new, one aspect that continues to inhibit us is the inability to find concise technology overview books.

We are usually faced with two options: read several 500+ page books or scour the web for relevant blog posts and other articles. Just as everyone else who has a job to do and customers to serve, we find this quite frustrating.

The Succinctly series

This frustration translated into a deep desire to produce a series of concise technical books that would be targeted at developers working on the Microsoft platform.

We firmly believe, given the background knowledge such developers have, that most topics can be translated into books that are between 50 and 100 pages.

This is exactly what we resolved to accomplish with the Succinctly series. Isn’t everything wonderful born out of a deep desire to change things for the better?

The best authors, the best content

Each author was carefully chosen from a pool of talented experts who shared our vision. The book you now hold in your hands, and the others available in this series, are a result of the authors’ tireless work. You will find original content that is guaranteed to get you up and running in about the time it takes to drink a few cups of coffee.

S

Free forever

Syncfusion will be working to produce books on several topics. The books will always be free. Any updates we publish will also be free.

Free? What is the catch?

There is no catch here. Syncfusion has a vested interest in this effort.

As a component vendor, our unique claim has always been that we offer deeper and broader frameworks than anyone else on the market. Developer education greatly helps us market and sell against competing vendors who promise to “enable AJAX support with one click,” or “turn the moon to cheese!”

Let us know what you think

If you have any topics of interest, thoughts, or feedback, please feel free to send them to us at [email protected].

We sincerely hope you enjoy reading this book and that it helps you better understand the topic of study. Thank you for reading.

Please follow us on Twitter and “Like” us on Facebook to help us spread the word about the Succinctly series!

Chapter 1 A First Glance at Delphi

Delphi was released in 1995 by Borland, the software company behind the well-known Turbo Pascal compilers.

The idea of Borland was to create an environment for rapid application development (RAD) based on components use, or better re-use, taking the well-known Turbo Pascal compiler a step forward.

At that time, Delphi was a direct competitor of Microsoft Visual Basic—at one point someone called it “VB-Killer.” Thanks to the full support for object-oriented programming (OOP), multi- threading and COM (Component Object Model) support, and many other exclusive features, Delphi could achieve more complex and well-structured projects than Visual Basic 6. VB developers had to await the advent of the .NET Framework technology in order to have a comparable tool with a high-level language and modern enterprise-class business qualities.

Today, Delphi is owned and maintained by Embarcadero Technologies, a company focused on high-class enterprise data management and development tools. Delphi is sold as a standalone product or inside RAD Studio, a broader suite where Delphi is bundled with C++Builder (a different flavor of the same technologies and libraries available for Delphi but based on C++ language and compilers).

In this book we will refer to Delphi 10 Seattle, which is the latest available version at the time of writing, but everything we’ll see should be fine for any older or newer versions.

The purpose of this book is to provide an overview of what you can do with Delphi and how, facing the working principles of its environment and the high potential of Object Pascal language to build native solutions for a wide number of heterogeneous devices and platforms.

A Look Inside the Box

Delphi is available either as a separate product or as part of RAD Studio, a more complete developer suite that includes a C++ language environment sharing the same libraries of Delphi.

Delphi includes:

 An Integrated Development Environment (IDE).

 A set of compilers for different target platforms.

 Core runtime and design-time libraries (RTL, VCL, FMX).

 Several third-party components and packages.

 Offline product documentation and API references.

 A lot of examples and demos with source code.

In the following chapters, we will be examining each of these parts in detail to see how you can build any kind of application with them.

Libraries and Frameworks

The development process in Delphi leverages three libraries for runtime and design-time purposes.

These libraries include full source code, so you can have a peek and get to know how some features are implemented, or sometimes put a workaround in place if there is a bug.

The Run Time Library (RTL) is a portable piece of software filled up with routines, types and classes for general purposes like string and date/time manipulation, memory and I/O management, lists and other containers and RTTI (known as Reflection in .NET and Java) just to name a few.

The Visual Component Library (VCL) leverages the RTL to provide a set of both visual controls and non-visual components aimed at creating applications and services for the Windows platform. VCL exists in the product since its inception in 1995 and after more than 20 years of improvements, it has grown up and became a solid and mature framework. It is actively maintained to embrace the most prominent features available on each version of Windows released by Microsoft.

FireMonkey is similar to the VCL, meaning that it provides components and visual controls, but it is different from the former in many aspects. First of all, it is a graphic library: the elements that make up the user interface are designed from scratch leveraging the GPU and using vectors. It is also fully cross-platform: every application created with it can be compiled to run on different operating systems, including Windows, Mac OSX, Android and iOS.

Delphi offers many other libraries to address common tasks like network and Internet communication, data access, and cloud support. To name a few, FireDAC is a library that lets you connect to a wide variety of data sources and databases in different formats, including NoSQL databases (like MongoDB). Indy is a set of classes and components that enable the creation of clients and servers for the most popular network protocols; HTTP Client Library provides tools and components to call and exchange data with RESTful APIs, Cloud API is an extensible framework to connect and consume cloud services with up-to-date components for Microsoft Azure and Amazon EC2 Services.

One Language, Many Projects

Delphi can create a wide range of projects. Here is a table that summarizes them all, but new kinds are added after each release based on the new platforms the product embraces.

  1. The Setup Personalities step lets you choose the programming languages (called “Personalities”) to install. You can elect to install both Delphi and C++Builder or only one of them; if you are going to start a trial period, you can evaluate both products, otherwise you should stick with the languages included in the license bought from Embarcadero.
  2. The Setup Languages step allows you to install different languages of the product (the default is English).
  3. The Select Features step lets you choose what features you would like to install with the product (i.e. libraries, help, samples, add-ons). You can select a feature and read a short description below the tree.

Figure 1: Feature Selection

  1. The Android SDK step lets you install the Android NDK/SDK with the product; if you already have them installed and want to develop for the Android platform, uncheck these and configure them later, following the detailed instructions in the official documentation.
  2. The Start Menu step is where you can edit the name of the Start Menu group and decide if you want to create it just for you or for all users of your machine.
  1. The Destination Folder step allows you to change the destination path of program files, demos, and common resources.
  2. The Update File Associations permits you to select which file extensions should be associated to Delphi; you can select all file types or deselect the ones that are also used by other programming tools and environments (like Visual Studio) as you wish.
  3. The Download File Location step requires you to enter a path where the installer can save the media packages that must be downloaded according to selected features; you can also order “media kits” (DVDs) or download a full ISO distribution if you have an active Update Subscription with Embarcadero.
  4. The final step is the installation itself. Wait for it to finish and then you are ready to start using Delphi.

Launching Delphi

Once the installation procedure is complete, you can launch Delphi by clicking the corresponding link in the Windows Start Menu.

If you see a registration window appearing, you can choose to create a new Embarcadero Developer Network (EDN) account or logging in if you already have one. You should also have received further instructions by e-mail when you have downloaded the installer.

A splash screen will appear to show information about the loading process of both core components and add-ons where available.

When everything has been loaded, the full-screen Delphi IDE main window will open.

At the center of the main window you can find the Welcome page , a useful resource to deepen your knowledge with tutorials, examples and how-to procedures you can look at once finished reading this book, surrounded by many dockable panels, and each of them has its own scope.

Summary

In this chapter we introduced the libraries available in Delphi: Visual Component Library (VCL) for Windows development, and FireMonkey (FMX) for multi-device, cross-platform applications. We will dig into these libraries in the rest of the book to see how you can use them successfully.

We also had a look at the installation process. We have just covered some broad information, but remember, you can always check the Installation Notes from the product’s official documentation for more details.

Adding Controls

From the Tool Palette window, expand the “Standard” category by clicking the plus (+) sign, then click the TEdit control and drag it to your form, drop it on the empty window area. Next, repeat the procedure selecting the TButton control.

If you want to change the text on the button you just added, left-click the control you placed inside the Form and point to the Object Inspector window. Scroll through the grid to find the Caption property and click on it to enter new text, replacing the default value (Button1) with a new label. Press Enter or click elsewhere outside the Object Inspector panel to complete the change.

Figure 3: Button Properties

You can do the same to clear the contents of the textbox TEdit : select the control and change the property Text to an empty value.

If you want to move a control, you can click and move it around by holding the left mouse button down, or use the blue dots to change its size. Our final Main Form should look like this:

Figure 4: “Hello World” Form

Responding to Events

If you double-click the TButton control, Delphi will switch to the Code Editor and create a routine that handles the event raised when the user clicks the button. Delphi takes care of writing lot of the boilerplate code, leaving the specific implementation up to you.

Suppose we want to say “hello” when the user inserts his (or her) name and clicks the button. You could write something like the following:

Code Listing 1: Hello World

procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('Hello, ' + Edit1.Text + '!'); end ;

Don’t pay too much attention to the syntax—we’ll spend a full chapter on Object Pascal.

Run Your Application

To run the application, select [Run|Run Without Debugging] (or press CTRL+F9) and Delphi will start building your project.

Figure 5: Build Progress Window

If no errors are detected during the building process, Delphi launches the application executable file (which has the “.exe” extension on Windows).

Note: Delphi is a native compiled language, so it always creates an executable file when you need to run your application and see if it works as you expect. You can’t avoid that. You can only choose to run the program without debugging so Delphi

Tip: Sometimes your application may need to use external files, resources or databases; in these cases, I recommend using an installer tool to ensure that all required files are copied to the destination machine. This lets the user customize the process, like the program target directory, the choice of optional components, the help manual, and samples. If you want a simple, easy-to-use tool, look at Inno Setup (which, by the way, was built with Delphi!)

Summary

Here we have only scratched the surface of what you can achieve with Delphi, and I think you can already get a clear idea of how much the Rapid Application Development (RAD) approach speeds up the development process.

Using Delphi, you can focus exclusively on the key parts of your application, such as the user interface and the business logic, without concentrating too much on the internal mechanisms.

I know this example may seem overly simple, but the next chapters will illustrate how to use Delphi to make applications that are far more complex. Before that, we should familiarize ourselves with the tools available in the IDE.

Chapter 3 Exploring the IDE

Before we delve into each kind of project you can build with Delphi, you should get in touch with the fundamental tools available in the IDE and see how they work on a concrete circumstance.

Figure 7: The Delphi IDE

The Tool Palette

The Tool Palette hosts all of the available components and visual controls.