Professional Documents
Culture Documents
BLAISE PASCAL
PASCAL MAGAZINE
MAGAZINE
28
28
D E L P H I,
L A Z A R U S,
OXYGEN
(P R I S M), A N D
PASCAL
RELATED
LANGUAGES
2 / 2013
Publisher: Foundation for Supporting the Pascal Programming Language
in collaboration with the Dutch Pascal User Group (Pascal Gebruikers Groep)
Stichting Ondersteuning Programmeertaal Pascal
28
BLAISE
BLAISE PASCAL
PASCAL MAGAZINE
MAGAZINE 28
D E L P H I,
L A Z A R U S,
OXYGEN
(P R I S M), A N D
PASCAL
RELATED
CONTENTS
V O L U M E 2 8,
I S S N 1 8 7 6-0 5 8 9
Editor - in - chief
Detlef D. Overbeek, Netherlands
Tel.: +31 (0)30 890.66.44 / Mobile: +31 (0)6
21.23.62.68
Articles
NEW AND ENHANCED FEATURES
IN DELPHI XE4
Alternative datastreams (ADS)
By Jean Pierre Hoefnagel
alternative and a far better inifile
page
page 14
page 16
page 18
Page 34
Alexander Alexeev
Peter Bijlsma,
Michal Van Canneyt, Marco Cant,
David Dirkse, Daniele Teti
Bruno Fierens
Primo Gabrijeli,
Fikret Hasovic
Cary Jensen
Wagner R. Landgraf, Sergey Lyubeznyy
KIm Madsen, Felipe Monteiro de Cavalho
Jeremy North,
Tim Opsteeg, Inoussa Ouedraogo
Howard Page-Clark,
Henk Schreij, Rik Smit, Bob Swart,
Editors
Page 42
Page 46
Page 48
Correctors
Page 52
Page 57
DUTCH PASCON
LANGUAGES
7 SEPTEMBER 2013
I N T E R N A T I O N A L
PASCAL & DELPHI SESSIONS
CONFERENCE
IN
ENGLISH
www.blaisepascal.eu
or by written order, or by sending an email to
office@blaisepascal.eu
Advertisers
Barnsten
BetterOffice
Bod Swart
Components 4 Developers
Delphi Developer Days
FastReport
Learn to program using Lazarus
Lazarus the complete guide
Parallel Programming
with Omnithread Library
Smart Mobile Studio
Page
Page
Page
Page
Page
Page
Page
Page
13
45
51
60
3
40
41
56
Page 22
Page 33
Copyright notice
All material published in Blaise Pascal is copyright SOPP Stichting
Ondersteuning Programeertaal Pascal unless otherwise noted and may
not be copied, distributed or republished without written permission.
Authors agree that code associated with their articles will be made
available to subscribers after publication by placing it on the website of
the PGG for download, and that articles and code will be placed on
distributable data storage media. Use of program listings by subscribers
for research and study purposes is allowed, but not for commercial
purposes. Commercial use of program listings and code is prohibited
without the written permission of the author.
COMPONENTS
DEVELOPERS
Subscription department
Edelstenenbaan 21 / 3402 XA IJsselstein,
The Netherlands / Tel.: + 31 (0) 30 890.66.44 /
Mobile: + 31 (0) 6 21.23.62.68
office@blaisepascal.eu
www.DelphiDeveloperDays.com
City
Location
Frankfurt, Germany
Amsterdam, NL
Attendees Receive:
An extensive course book (several hundred pages) written by Bob and Cary
that includes material covered in their joint and individual sessions
Source code examples from all of their sessions
A chance to win valuable prizes from our sponsors
Lunch on both days
Register early for an additional discount. Previous attendee and group discounts are available.
www.DelphiDeveloperDays.com
Nr 2 / 2013 BLAISE PASCAL MAGAZINE
COMPONENTS
DEVELOPERS
Rapid prototyping
RAD Studio XE4 delivers an enhanced and optimized
developer workflow for mobile development that
automates deployment and debugging on both the
simulator and device. Rapidly prototype your apps with
layouts for each device type and quickly go from
prototype to production. Integrate feedback quickly by
deploying your prototype directly onto your target device
using actual framework objects and code. Learn more >
COMPONENTS
DEVELOPERS
As the target platform for the next build, you can select:
iOS Device (for an iOS device connected to your Mac),
which is any of the following:
Debug (for development cycles)
Ad-hoc (for private distribution)
App Store (for submitting your app to the App Store)
iOS Simulator (for the iOS simulator running on
Mac OS X; the default iOS app),
which is any of the following:
iPad
iPhone (the default)
iPhone 5
You can add iOS Device and iOS Simulator to your custom
run-time packages, and build them for those platforms, so
your components can be used in those platforms as well.
COMPONENTS
DEVELOPERS
In the pdf:
click to see
the video
In the pdf:
click to see
the video
In the pdf:
click to see
the video
iOS Location
iOS DatePicker
In the pdf:
click to see
the video
In the pdf:
click to see
the video
In the pdf:
click to see
the video
iOS AudioRecPlay
In the pdf:
click to see
the video
In the pdf:
click to see
the video
In the pdf:
click to see
the video
This code snippet (available inside the This code snippet (available inside
Delphi IDE) shows you how to pinch
the Delphi IDE) shows you how to
and zoom an image on an iOS device. use tap and hold to display a
message
iOS SendCancelNotifications
This code snippet (available inside the
Delphi IDE) you how to use the
Notification API in order to send a
notification immediately or with a 10
second delay and how to cancel a
scheduled notification or all notifications.
COMPONENTS
DEVELOPERS
In the pdf:
click to see
the video
iOS Accelerometer
iOS Gyroscope
iOS Location
iOS OrientationSensor
iOS DeviceInfo
iOS MessageAlerts
This code snippet (available inside the This code snippet (available inside the
Delphi IDE) shows you how to use the Delphi IDE) shows you how to use
TOrientationSensor component in order obtain device information that
includes OS version, OS name, and
to get various compass related
device type.
information such as three axis tilt,
distance and heading, heading relative
to magnetic north compensated and
uncompensated and heading relative
to true north compensated and
In the pdf:
click to see
the video
iOS ShareSheet
iOS
Notifications
(Set/Reset
Badge Number)
This code snippet (available inside the
Delphi IDE) shows you how to use the
Notification API in order to set the
badge number on the application icon
to a specified value or to reset the
badge number to 0.
COMPONENTS
DEVELOPERS
iOS PhoneDialer
This application (available inside the
Delphi IDE) shows how to use the
PhoneDialer API in order to make a
phone call and to obtain the carrier
This snippet
(available inside
the Delphi IDE)
shows you how to
use standard
actions to open the
Camera Application
on your
iOS device to take a photo and display it
on your FireMonkey form. Then, with
another standard action, you will open
the Share Sheet to share your image via
email, post to Facebook and Twitter, print
via AirPrint and more.
In the pdf:
click to see
the video
iOS TabSliding
iOS SQLite
iOS CustomPicker
iOS IBLite
This snippet (available inside the Delphi
IDE) shows you how to populate a
listview from an IBLite database using
LiveBindings.
To deploy this snippet you need to use
the IBLite license, following the
instructions that were emailed along
with the RAD Studio license (or trial
license).
iOS HorizontalScroll
iOS CameraComponent
iOS CameraRoll
iOS
AccessCamera
App
This snippet shows (available inside
the Delphi IDE) you how to use
standard actions in order to open the
Camera Application on your iOS
device, take a picture and retrieve the
taken image for displaying on your
FireMonkey form.
This code snippet (available inside the This snippet shows (available inside
the Delphi IDE) you how to use
Delphi IDE) shows you how to
standard actions in order to open the
manipulate the Camera on your iOS
Photo Library on your iOS device and
device. The snippet allows you to
retrieve an image from the library for
select either the front facing camera
displaying on your FireMonkey form.
or the back facing camera. Also you
can select whether to use the flash
(always on or automatic) or not.
COMPONENTS
MAGAZINE
DEVELOPERS
In the pdf:
click to see
the video
iOS SendCancelNotifications
iOS DatePicker
In the pdf:
click to see
the video
In the pdf:
click to see
the video
In the pdf:
click to see
the video
In the pdf:
click to see
the video
iOS AudioRecPlay
iOS PlayAudioFile
This code snippet shows (available
inside the Delphi IDE) you how to
include an audio file for playback in
your iOS application.
10
COMPONENTS
DEVELOPERS
Archit.
Ultim.
Optional
Optional
X
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
X
X
X
X
X
X
X
Optional
Optional
X
Optional
Optional
Optional
Optional
X
Optional
X
X
X
X
Archit.
Ultim.
10
X
Optional
Optional
Optional
Optional
X
X
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional
Optional1
Archit.
Ultim.
Optional
Optional
http://www.barnsten.com/smashing-deal
Nr 2 / 2013 BLAISE PASCAL MAGAZINE
13
Alternative datastreams:
..
freeandnil(AppIni);
end;
Thats all you need to start using inifiles, but how do you
use them? That too is surprisingly simple.
The TInifile class has lots of methods to read or write data.
An example: we place an edit box named edUser on the
form for a user name, but we do not want to fill it in every
time the program is started..
In the FormDestroy (or OnChange of the edit box) we save
the user name into the inifile :
procedure TfrmADSExample.FormDestroy(Sender: TObject);
begin
..
AppIni.WriteString('MainForm', 'edUser',
edUser.Text);
FreeAndNil(AppIni);
end;
This part takes care of storing the data, but without loading
it back that is not very useful. Loading can be done in
many ways like for instance overriding the Loaded()
method of the form.
To keep this example as simple as possible we assign an
event handler to the form's OnActivate event.
procedure TfrmADSExample.FormActivate(Sender: TObject);
begin
edUser.Text := AppIni.ReadString(
'MainForm', 'edUser', '');
end;
This loads the data into the edit box when the form is
activated. Of course the TInifile class can do a lot more,
please check the help if you want to know more about this.
There are lots of moments data can be stored and loaded,
this is just an example.
For now we do not even use the inifile as an inifile to store
settings data; we only created it as a carrier for ADS files.
ADS files can be addressed by using any normal file name
followed by a colon and another name.
Example: MyApplication.ini:cache1.bin.
We add another string variable ADSFileName to the
form that is initialized in the FormCreate.
procedure TfrmADSExample.FormCreate(Sender: TObject);
14
COMPONENTS
DEVELOPERS
expert
16
COMPONENTS
DEVELOPERS
expert
Separating UI
In the specific scenario, the application retrieves an XML
data structure. I could have passed that data structure to
the user interface processing code, populating the visual
controls. In this way, however, the code used to parse the
XML would have been written multiple times.
The anonymous method in question, instead, receives
as parameter an individual XML node, from which it can
extract the information for the user interface.
I guess things will be clearer as we start looking to the
actual code.
Here comes a Data Module
The first version I wrote was a little different from what
I'm showing here, but after some refactoring to make it
more portable became the following.
At the core of the family of programs there is a data
module with two components:
object IdHTTP1: TIdHTTP
HandleRedirects = True
COMPONENTS
DEVELOPERS
procedure TTweetsDataModule.GetData(
const strTopic: string;
processEntry: TProcessEntry);
end
18
By Marco Cant
CONFERENCE IN ENGLISH
DUTCH
PASCON
UTRECHT - NETHERLANDS
I N T E R N A T I O N A L
PASCAL & DELPHI SESSIONS
RAY KONOPKA - RAIZE COMPONENTS / DMITRY AREFIEV - FIREDAC
BRUNO FIERENS - TMS SOFTWARE / BOB SWART TRAINING & CONSULTANCY
RAYMOND HORSTEN - ER/STUDIO / DANNY WIND - THE DELPHI COMPANY
GIRISH PATIL - PDF COMPONENTS - GNOSTICE
KIM MADSEN - COMPONENTS4DEVELOPERS
GWAN TAN - BETTER OFFICE - JEROEN PLUIMERS
MATTHIAS GRTNER - LAZARUS / JOOST VAN DER SLUIS - LAZARUS IOS
MICHAEL PHILIPPENKO - FASTREPORT / MICHAEL VAN CANNEYT - FREE PASCAL
DANNY WIND - THE DELPHI COMPANY / MARIO VERMEULEN - 3D OFFICE
SEPTEMBER 7 2013
In the preceding article in this series I discussed a DataSnap server that implemented authorization
and authentication. In addition, that server employed filters for encryption. In this article I introduce
a Delphi client that communicates with that DataSnap server.
Before I continue, however, I want to clarify a term that I have been using in this series. I have
repeatedly referred to the type of DataSnap server that I described in the past two articles in this
series as IP-based DataSnap servers.
While it is true that this type of server use TCP (Transmission Control Protocol) over IP (Internet
Protocol), it has been brought to my attention that Embarcadero's documentation refers to these
types of servers as DBX DataSnap servers.
The original DataSnap server used COM (Component Object Model) to communicate, and the
new style, introduced in Delphi 2009, uses TCP/IP. Since the COM style of DataSnap server is limited
to Windows installations, and should generally be considered deprecated (though Embarcadero has
not officially deprecated COM-based DataSnap servers), from this point on I am going to refer to IPbased DBX DataSnap servers simple as DBX DataSnap servers.
COMPONENTS
DEVELOPERS
23
smartmobilestudio.com
Structured code
The ToDoList v3 has been split into several units. I tried to
separate view and data models from each other but I didn't
follow any design pattern, such as MVC, MVP or MVVM.
On the model side, we have two units. ToDoModel stores a
data model while ToDoModelSerializer knows how to
serialize and deserialize this model into a textual
representation. Persistence layer is implemented in the
ToDoStorage unit.
The view (GUI) part contains forms ToDoMain and
ToDoAbout, frame ToDoCategoryFrame and a modal
dialog ToDoTaskDlg. In Smart, frames and dialogs are not
natively supported but we can design them as normal
forms which are then used in a special way.
Connecting the view and the model is a view-model unit
ToDoListTemplate which represents one to-do item.
Model
Let's start our walk through the program with the data
model. At the moment it is (intentionally) very simple.
A model class contains a reference to a category list and an
item list. A category list contains just an array of strings
(category names) and an item list contains an array of item
34
COMPONENTS
DEVELOPERS
COMBINED PACKAGE
http://www.blaisepascal.eu
LEARNING
TO PROGRAM USING LAZARUS
LAZARUS
THE COMPLETE GUIDE
The complete Package 60,00 (Paperback) includes a download subscription of BLAISE PASCAL
MAGAZINE and the book LEARNING TO PROGRAM USING LAZARUS as pdf
Windows installer for Lazarus / Linux for Lazarus / Mac for Lazarus / Lazarus Portable, including a
prenstalled Lazarus on an 8 GB USB stick (Click and Go) / 60 additional sample projects / additional
prenstalled component suites on USB Stick / LEARNING TO PROGRAM USING LAZARUS as pdf
Blaise Pascal Magazine Library (LIB STICK) - Completed up to all 26 issues / ALL ON USB STICK
.iOS Development
type
NSTableViewDelegate = objcclass(NSObject,
starter
expert Lazarus 1.1 or higher
UITableViewDataSourceProtocol)
public
The first article in this iOS series explained how to use
function tableView_numberOfRowsInSection(
native iOS controls in Lazarus, using the form designer
tableView: UITableView;
to create the layouts (see the previous Blaise issue).
section: NSInteger): NSInteger;
That article also included a short introduction to
message 'tableView:numberOfRowsInSection:';
FPC's Objective-Pascal language extensions and the
function tableView_cellForRowAtIndexPath(
Objective-C classes. To exploit the full potential of
tableView: UITableView;
native iOS controls you should use the design patterns
indexPath: NSIndexPath): UITableViewCell;
that Apple advocates and on which Apple bases the
message 'tableView:cellForRowAtIndexPath:';
entire iOS developer kit.
end;
This second tutorial article illustrates some of those
design patterns by showing you how to create a simple
application with a tableview.
Note that the class name does not start with a 'T'.
function NSTableViewDelegate.
tableView_cellForRowAtIndexPath(
tableView: UITableView;
indexPath: NSIndexPath): UITableViewCell;
var
s: string;
begin
result := tableview.
dequeueReusableCellWithIdentifier(
NSSTR('DefTableItem'));
if not assigned(result) then
begin
result := UITableViewCell.alloc.
initWithStyle_reuseIdentifier(
So how do we add data to a tableview? To do this you
UITableViewStylePlain,NSSTR(
have to create a datasource and bind it to the UITableView.
'DefTableItem'));
This datasource is not the datasource you might know
result.setAccessoryType(
from working with default database controls, but an
UITableViewCellAccessoryDisclosureIndicator);
Objective-C class that implements the
end;
if odd(indexPath.Row) then
UITableViewDataSourceProtocol. As explained in the
result.textLabel.setText(nsstr('Item 1'))
previous article, a protocol is part of the Objective-Pascal
else
extensions, and is something like an interface with optional
result.textLabel.setText(nsstr('Item 2'));
methods. Thus to create a datasource we have to define our end;
42
COMPONENTS
DEVELOPERS
46
COMPONENTS
DEVELOPERS
Book Review
This is a quotation of the book's introductory paragraph:
Introduction
This book is written for programmers who want to learn
the Object Pascal Language. It is also suitable as a first
programming book for new students and nonprogrammers. It illustrates programming techniques in
general in addition to the Object Pascal Language."
The above opening paragraph is a relevantly short and
accurate description of what this book is all about: short
and accurate, as the idea behind the book is to get
newcomers straight into Pascal programming via minimal
initial documentation, plus a very quick and easy
generation of their first program.
The first set of instructions in the Contents section
"Environment for book examples" says: "We will use
Lazarus and Free Pascal for all the examples in this book.
You can get the Lazarus IDE, including the Free Pascal
compiler, from this site: http://lazarus.freepascal.org." A
few other points are raised regarding usage of Linux,
Ubuntu or Fedora, but for my purposes to follow the
instructions I merely had to click on the Lazarus link,
download and install it under Windows 7. Hopefully, the
average newcomer in this day and age would be able to
follow such instruction easily and get through in a very
short time without any problems. Step one of two to get
started completed.
In many books or demonstrations of Pascal systems
containing a productive GUI, updates or other
enhancements, the first sample is usually a GUI based
"Hello World". However, in this book, the first part is
explained and demonstrated via console applications in
text mode/command lines, while the GUI and Object
Oriented sections come in as the second part.
Once past the Introduction and table of Contents, the
starting part of the first page of Chapter One contains this
sample:
48
COMPONENTS
DEVELOPERS
Special announcement:
Bob Swart in collaboration with BLAISE PASCAL MAGAZINE:
subscribers having a magazine download subscription will be given a 10 euro discount
on their order. Subscribers having a printed magazine subscription will be given a 20
euro discount. This discount is offered per subscriber (not per book), so irrespective of the
number of Courseware books ordered, each subscriber will given a single 10 or 20 discount for
the one order only. To order via Blaise Pascal Magazine you can contact Detlef Overbeek at
office@blaisepascal.eu for delivery within 48 hours.
42
eBob42
.com
expert
Delphi XE4 and later Select a VCL Forms Application, in the next page make
sure to select TCP/IP (and use the default port 211,
although I would recommend to change that port number
Delphi XE4 was released a little while ago, and
to a different number when you want to deploy the
contained one big feature compared with Delphi
application). Select a Server Method Class with Sample
XE3: the support for iOS development.
Methods, and change the TComponent ancestor type to
Technically, this feature is only available in the
TDSServerModule (so we can call ApplyUpdates when
Enterprise edition (or when you purchase the
needed).
Mobile Development AddOn package), so this
Save the project, using the generated filenames (although
article will be of less "use" for people who only
you can save the main form in MainForm.pas instead of
have the Professional edition of Delphi.
UnitXXX.pas).
On the Server Methods unit, we will now place some data
DBX Clients
access components to connect to a database. In this
Delphi XE2 with Update #4 offered the ability to use the
example, I'll use InterBase, but we can also use any other
Mobile Connectors to write DataSnap Clients for mobile
database of course. Place a TSQLConnection component on
devices using the REST protocol (because many of the
the ServerMethodsUnit1. Set the Driver property to
clients were written in other languages like Java, C# or
InterBase Server (or another value, if you want to use
Objective-C). We could also use FireMonkey for iOS in
another database). Set the LoginPrompt to False, and the
combination with the FreePascal Compiler to write
Database to C:\Users\Public\Documents\RAD
DataSnap clients for iOS using REST. But this technique is
Studio\11.0\Samples\Data\EMPLOYEE.GDB (or the
now outdated.
location of the EMPLOYEE database on your machine).
With Delphi XE4, we are no longer limited to REST and
Now, in order to validate the settings, we can set
HTTP, but can also communicate using DBX and TCP/IP.
Connected to True. If this works (without errors), make
This is great news, since DataSnap DBX is a more powerful sure to set it back to False again.
architecture than the DataSnap REST capabilities (as
explained in more detail in my DataSnap Development
Next, place a TSQLDataSet next to the TSQLConnection.
courseware manual).
Point the SQLConnection property to the TSQLConnection
52
COMPONENTS
DEVELOPERS
procedure THeaderFooterForm.btnOpenClick(Sender:
TObject);
begin
ShowMessage('test');
end;
After you've set Active back to False, make sure to set the
Connected property ot the TSQLConnection component
also back to False again. This will ensure that the iOS
DataSnap Client does not make a connection when you
open the project (or when you run the app itself). We will
add some code to connect to the DataSnap Server and
retrieve the data in a minute.
54
COMPONENTS
DEVELOPERS
LEARN TO PROGRAM
USING LAZARUS 1.0
Learn to Program
using Lazarus 1.0,
and is written by Howard Page-Clark,
our editor, corrector
and writer of many articles
Among the many topics introduced are:
Pascal types, the Lazarus IDE,
Coding discipline,
GUI editing components,
Pascal files and streams,
Object oriented principles,
debugging techniques.
As Loose Leaf Book
35 plus postage 17,50
As PDF File
25 no postage
50
expert
APACHE FLEX
VIA kbmMW
SPIDER/FLEX
JAVA
VIA kbmMW
SPIDER/JAVA
By Fikret Hasovic
C/OBJ.C
VIA kbmMW
SPIDER/C
PHP
VIA kbmMW
SPIDER/PHP
.NET
VIA kbmMW
SPIDER/.NET
HTTP
SERVER
KBMMW
APP
SERVER
HTTP
VIA kbmMW
AJAX
TRANSPORT
PC
SOAP
VIA kbmMW
SOAP
TRANSPORT
DATABASE
SERVER
DATABASE
SERVER
DATABASE
SERVER
XML
VIA kbmMW
AJAX
TRANSPORT
COMPONENTS
DEVELOPERS
57
COMPONENTS
DEVELOPERS