Professional Documents
Culture Documents
BLAISE PASCAL
PASCAL MAGAZINE
MAGAZINE
27
27
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
What is polymorphism?
By Vsevolod Leonov
Creating and using kbmMW as an Ajax back-end server
By Benno Evers
1 / 2013
Publisher: Foundation for Supporting the Pascal Programming Language
in collaboration with the Dutch Pascal User Group (Pascal Gebruikers Groep)
Stichting Ondersteuning Programmeertaal Pascal
27
BLAISE
BLAISE PASCAL
PASCAL MAGAZINE
MAGAZINE 27
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 7,
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
Introduction to thread programming in
Lazarus
By Michal Van Canneyt
Page
Introduction to Databases Part 11:
DataSnap Filters and Security
By Cary Jensen
Page
Electronic document processing tools
for Delphi made by Gnostice
By Grish Patil
Page
Use of the "absolute" function abs(..)
By David Dirkse
Page
.iOS Development for lazarus
By Joost van der Sluis
Page
What is polymorphism?
By Vsevolod Leonov
Page
Creating and using kbmMW
as an Ajax back-end server
By Benno Evers
Page
13
23
36
41
48
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
Peter Bijlsma, W. (Wim) van Ingen Schenau,
Rik Smit
52
Correctors
Howard Page-Clark, James D. Duff
Copyright Page 118
Trademarks All trademarks used are
acknowledged as the property of their respective
owners.
Caveat Whilst we endeavour to ensure that what is
published in the magazine is correct, we cannot
accept responsibility for any errors or omissions.
If you notice something which may be incorrect,
please contact the Editor and we will publish a
correction where relevant.
Subscriptions ( 2013 prices )
1: Printed version: subscription 60.-(including code, programs and printed magazine,
6 issues per year including postage).
2: Non printed subscription 40.-Incl. VAT 21% (including code, programs and
download magazine)
Subscriptions can be taken out online at
Advertisers
www.blaisepascal.eu
Barnsten
BetterOffice
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
47
12
60
3
40
39 / 51
51
page 22
page 24
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.
LANGUAGES
COMPONENTS
DEVELOPERS
office@blaisepascal.eu
Subscriptions can start at any date. All issues
published in the calendar year of the subscription will
be sent as well.
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
Chicago, USA
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 1 / 2013 BLAISE PASCAL MAGAZINE
TThreadList
expert Lazarus 1
Abstract
1 Introduction
Recently, FPC received a substantial upgrade in its
threading code. It has been made compatible with the
Delphi XE3 threading possibilities. Time for a refreshment
on how to do threading in Lazarus/Free Pascal.
Threading means writing the code of an application so that
several parts of the code are executed simultaneously, in
parallel. Each part of the code forms a thread of execution.
Threading requires support by the hardware: several
processors or a processor with various cores. If the
hardware does not allow it, the operating system mimics
simultaneous execution by giving the various parts of the
program time to execute in an intertwined fashion,
much like it allows multiple programs to execute
simultaneously. The scheduling of threads and programs
by the operating system is a huge subject in itself, and is
done differently by each OS.
The difference between threads and multiple programs
is of course that all threads in a program all have access to
the same data and memory space. Programs can share
some memory by using shared memory and special
operating system calls. Access to the shared memory by the
various threads must be carefully designed, or strange
things may happen: As long as one thread only writes and
another thread only reads from a shared memory location,
things will usually progress without problems. However, if
threads will try to update the same memory location,
strange things may happen. To prevent
this, special programming is required. In this article, well
show how this is done.
TCriticalSection
FreeOnTerminate
This property is described in detail below.
Handle
An operating system handle for the thread.
ThreadID
An operating system ID for the thread.
ExternalThread
A boolean indicating whether this thread was started outside
the RTL.
Priority
An indicator of the threads priority.
Suspended
A Boolean indicating whether the thread is currently
executing or not.
Finished
A Boolean indicating whether the thread has finished
executing.
OnTerminate
An event handler that is calledwhen the thread has finished
executing.
FatalException
If an exception is raised during the execution of the thread,
but is not caught by user code, then it is caught and held here
for inspection.
COMPONENTS
DEVELOPERS
9 Conclusion
Threads can be very useful when performing lengthy
tasks in the background. The thread support in Free
Pascal makes it very easy to do. Having multiple threads
perform tasks in the background while accessing and
modyfing the same shared data is a bit more tricky, but
can be done as well with standard classes provided by
Free Pascal.
12
COMPONENTS
DEVELOPERS
expert
In the preceding article in this series I walked you through the creation of a
simple IP-based DataSnap Server, which Embarcadero refers to as a
DataSnap DBX Server (as opposed to DataSnap REST). In this article I am
going to go into greater depth, and discuss the use of server class lifecycle,
authorization, authentication, and filters. I will begin this discussion by
exploring the various classes that are involved in the creation of a DataSnap
server (these apply to both DBX and RESTful DataSnap servers).
COMPONENTS
DEVELOPERS
13
m
ra 0
g
o
Pr us 1.
o
n t ar
ar Laz
e
L g
in
us
Primo
A Smart Book Gabrijeli
Primo
Gabrijeli
Parallel Programming
with OmnithreadLibrary
Pa
SMART MOBILE
STUDIO
ar
ow
ar
Cl
ge
o i
im l
Prrije
ab
OO
B
RT
MA
AS
T
EN
PM
LO TH
VE L WI
E
B D CA
WE PAS
IN
IO
UD
T
ES
BI
O
TM
AR
SM
i
jel org
barmimer.
a
G r
rog
mortp
Pwrwi.sma
w
AL
SC
A
P
SE
AI
L
B
NE
ZI
A
G
MA
Parallel Programming
with Omnithread
Library,
and
COMPONENTS
DEVELOPERS
23
Delphi
Reporting
Tools
Your GDI or
TCanvas Drawing
code
Metafiles, RTF,
text, images
eDocEngine
Content-Creation
API (pages,
paragraph, tables,
headers, footers
from fields,
annotation, etc.)
eDocEngine VCL
Document - Creation
Components
RTF
HTML
XLS
CSV
BMP
PNG
JPG
SVG
EMF
WMF
Here's how:
1. Drop a format engine component (say PDFEngine)
TgtPDFEngine - to export to PDF
2. Drop the appropriate report export interface (say
FrExportInterface)
TgtFRExportInterface - to connect with FastReport
3. Wire the export interface to the format engine
Select PDFEngine as the value for FREExportInterface
object's Engine property
Now, when we run the application and preview the report,
the option to save to PDF magically appears in the report.
(See the next page top)
eDocEngine's document-creation engines are really mature
and include many of the advanced features that you
usually find only in specialized tools. For example, the PDF
engine includes support for on-the-fly digital signing
24
COMPONENTS
DEVELOPERS
We know from experience that the Delphi developer community is a great adopter of tools and components. However
we were still surprised at the overwhelmingly positive response to our new tools presentation at the 2012 Delphi Tage
conference in Germany. We are very excited about the future and the upcoming releases of next-generation documentprocessing toolsets both for Delphi and Delphi Prism developers.
COMPONENTS
DEVELOPERS
35
expert
Figure 2:
Figure 1:
36
COMPONENTS
DEVELOPERS
-y = 0.5(abs(x) -x) or
y = -0.5(abs(x) -x) or
y = 0.5(x - abs(x))
Now for x > 0 the upper limit is 0 and for x < 0
we get y = x.
The angle may now be shifted to any position.
The slope is adjusted to 1 by the factor 0.5
Figure 3:
or
y = 0.5(abs(x) + x)
Figure 5:
Figure 4:
Figure 6:
y = 0.5(abs(x) - x)
note : abs(-x) = abs(x)
The function returns 0 for x > 0 and abs(x) for x < 0,
which is not quite what we want.
Reflection again, now around the x- axis (replace y by -y):
COMPONENTS
DEVELOPERS
37
Figure 7:
b - (b-a)/2 = (a+b)/2 ,
a shift over the line y = x
so replace x by x-(a+b)/2 and y by y-(a+b)/2
so:
y = 0.5(abs(x+v) - abs(x-v))
which yields
y - (a+b)/2 = 0.5(abs(x-(a+b)/2
+ (b-a)/2) - abs(x-(a+b)/2 - (b-a)/2))
y - (a+b)/2 = 0.5(abs(x-a) - abs(x-b))
y = 0.5(abs(x-a) - abs(x-b) + a + b)
In this way a function can be constructed with any
arbitrary upper and lower limit, without the use of if
statements. The processor pipelines can stream
uninterruptedly.
My graphics program Graphics-Explorer may be used to
visualize the results.
Download the program from the web page
http://www.davdata.nl/math/grxpl.html
Type y = 0.5(abs(x-a) - abs(x-b) + a + b) and click "plot".
Select (right top) "replace" (not add) and "autoplot".
Now click (left or right) at the a and b windows to
increment or decrement constants a and b. The plot
immediately adjusts itself to the new values.
Below I summarize the results so far:
Variable x is assigned a
lower limit a using function
y = 0.5(abs(x - a) + x + a)
upper limit b using function
y = 0.5(x - abs(x - b) + b)
both limits a, b using function
y = 0.5(abs(x - a) - abs(x - b) + a + b)
Quite surprising, isn't it?
38
COMPONENTS
DEVELOPERS
Figure 8:
j : word;
h,v : word;
sx,sy : word;
bm : Tbitmap;
begin
.....
//creation of bitmap
//setting rectangle dimensions h and v
//setting position (sx,sy)
...
with bm.canvas do
begin
pen.color := 0;
pen.width := 1;
for j := 0 to h + v - 2
//from top to bottom of the rectangle
begin
y := sy + j;
x1 := ???;
x2 := ???;
moveto(x1,y);
lineto(x2,y)
//for j
end;
//with bm
end;
....
end;
8
2
x1 + 3 = abs(j - 3)
x1 = abs(j - 3) - 3
or
Figure 9:
x1 = abs(j+v-1) - (v-1)
For the final result, sx has to be added to the horizontal
position so,
x1 = sx + abs(j+v-1) - (v-1)
Similarly we calculate that
x2 = sx - abs(j-h+1) + (h-1)
Note:
moveto(0,0) followed by lineto(10,0) draws a line from (0,0)
to (9,0).
Pixel (10,0) is not included.
Therefore, 1 has to be added to x2.
This concludes my article about ways you can usefully
apply the abs( ) function.
Figure 10:
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.
NEW:
As Loose Leaf Book
35 plus postage 17,50
COMPONENTS
DEVELOPERS
39
.iOS Development
for lazarus
http://www.blaisepascal.eu/index.php?actie=./subs
cribers/UK_Book_Department
COMPONENTS
DEVELOPERS
41
Barnsten has selected the best tools for the best developers
and is already for 20 years the expert for the Embarcadero products.
Each day we have contact with a lot of Delphi Developers to give advise,
trainings, consultancy and the use of components.
Barnsten has collected by now more then 600 components.
Here is an overview of the most used and wanted Delphi- and C++Builder
components:
Fast Report
Reporting must be fast
A collection of over
180 VCL Controls
http://www.barnsten.com/default/components
Aurora Borealis
Perhaps a good explanation of a new concept should begin
with a definition.
Polymorphism is derived from a Greek term which literally
means many forms. In the field of programming
polymorphism means that the calling of a conceptual
operation is isolated from its actual implementation. In
fact, at runtime, the implementation may vary
considerably, depending on the type of object that
performs the operation.
There is no redundancy in this three-sentence definition. A
beginner trying to understand a shorter definition would
be short-changed. We should not imagine that a supremely
crisp, succinct definition is one of the hallmarks of
polymorphism.
Try to read the above definition as you would understand
a description of the Northern lights, since polymorphism
likewise shines in the north. You can easily understand
what the Northern lights are simply by looking at
photographs. We will try to make up for the unfortunate
fact that you cannot photograph polymorphism.
Esoteric knowledge
Ask (a friend, a teacher, Google) about polymorphism and
you realize it is considered esoteric knowledge. You will be
told You need to work on polymorphic constructs for a
year and then maybe you'll understand.
A textbook explanation will conclude with:
polymorphism is a way of dealing with two or more
similar but technically different tasks. In fact, however,
programming is an engineering science. Its wonders and
creativity arise from easily explained concepts, with
nothing esoteric at all.
Mouse around
The ability to effortlessly 'mouse around' in a RAD IDE
is ultimately unhelpful if it detaches novices from the
code they are generating
You have to understand that syntax development in
programming languages (such as adding the new paradigm of
encapsulation, inheritance and polymorphism) is designed for
very specific needs that developers have. For instance you
are not interested in the philosophy (or spirituality) of a
car's automatic transmission. It was introduced to meet a
specific need. Polymorphism likewise solves a specific
problem.
48
COMPONENTS
DEVELOPERS
http://www.barnsten.com/default/development-tools
LAZARUS
THE COMPLETE GUIDE
(ExtraPackage updated)
LINUX
LAZARUS V1
Pro Pascal Foundation
48
WINDOWS
WinXp/Vista/Win7
LAZARUS V1
Pro Pascal Foundation
MAC
LAZARUS V1
Pro Pascal Foundation
51
47
27
COMPONENTS
DEVELOPERS