• No results found

BlaisePascalMagazine 44 UK

N/A
N/A
Protected

Academic year: 2021

Share "BlaisePascalMagazine 44 UK"

Copied!
48
0
0

Loading.... (view fulltext now)

Full text

(1)

P R I N

P R I NT E D I S S U E P R I C E € T E D I S S U E P R I C E € 1 5 . 0 01 5 . 0 0 D O W

D O WN L O AN L O AD D I S SI S SU E U E P R IP R IC E € C E € 7 . 5 07 . 5 0

BLAISE PASCAL MAGAZINE

BLAISE PASCAL MAGAZINE

BLAISE PASCAL MAGAZINE

BLAISE PASCAL MAGAZINE

BLAISE PASCAL MAGAZINE

BLAISE PASCAL MAGAZINE

44

44

44

44

44

44

O V E R O V E RV I E W O F V I E W O F D E L PD E L PH I T O H I T O D E L PD E L PH I H I S T O RH I H I S T O RYY E U C L I D E S E U C L I D E S A N A G E A N A G E P U Z ZP U Z ZL EL E B Y D A V I D B Y D A V I D D I R K SD I R K SE  E   A R D U A R D UI N O : T H E V I S U II N O : T H E V I S U IN O P R O J E C T - P A R T 4N O P R O J E C T - P A R T 4 I N T E I N T ER N E T O F R N E T O F T H I NT H I NG S - G S - W I TW I TH H A R D UA R D UI N O A N D I N O A N D D E L PD E L PH IH I U S E E T H E R N U S E E T H E R NE T S H I E L D , P R O G R AE T S H I E L D , P R O G R AM I T M I T W I T H V I S U I N OW I T H V I S U I N O,, C O N N C O N NE C T F R O M A E C T F R O M A D E L P HD E L P HI I A P P LA P P LI C A T I O NI C A T I O N O V E R T H E L O C A L N E T W O R K O R I N T E R N E T O V E R T H E L O C A L N E T W O R K O R I N T E R N E T B Y B O I A N M I T O V B Y B O I A N M I T O V D A T A D A T AB A S E W O R K B EB A S E W O R K B EN C H 5N C H 5

THE SWISS ARMY KNIFE FOR DATABASES

THE SWISS ARMY KNIFE FOR DATABASES

B Y P E T B Y P E TE R V A N D E R S M A NE R V A N D E R S M A N T I P S A N D T I P S A N D T R IT R IC K S W I T H K B M M E M T A BC K S W I T H K B M M E M T A BL EL E B Y K I M B Y K I M M A D SM A D SE N  E N  

(2)

CONTENTS

CONTENTS

Articles

Articles

F F O O R R A N A N D D R R O O I I D, D, I I O O S, S, M M A A C, C, W W I I N D O N D O W W S S & L I & L I N U XN U X Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

O V E R O V E RV I E W O F V I E W O F D E L P HD E L P HI I T O D E L P H I H I S T OT O D E L P H I H I S T OR YR Y PAGE 6PAGE 6 E U C L I D E S E U C L I D E S PAGE 7PAGE 7 A N A G E A N A G E P U Z ZP U Z ZL EL E PAGPAGE E 88 B Y D A V I D B Y D A V I D D I R K SD I R K SE  E   A R D U A R D UI N O : T H E V I S U II N O : T H E V I S U IN O P R O J E C T - P A R T 4N O P R O J E C T - P A R T 4 I N T I N TE R N E T O F T H I N G S - E R N E T O F T H I N G S - W I TW I TH H A R D UA R D UI N O A N D I N O A N D D E L PD E L PH IH I U S E E T H E R N E U S E E T H E R N ET S H I E L D , P R O G R A M I T W I T H T S H I E L D , P R O G R A M I T W I T H V I S U IV I S U IN O ,N O , C O N N C O N NE C T F R O M A E C T F R O M A D E L PD E L PH I A P P L I C A T I O NH I A P P L I C A T I O N O V E R T H E L O C A L N E T W O R K O R I N T E R N E T O V E R T H E L O C A L N E T W O R K O R I N T E R N E T B Y B O I A N M I T O V B Y B O I A N M I T O V PAGE 12PAGE 12 D A T A D A T AB A S E W O R K B EB A S E W O R K B EN C H 5N C H 5

THE SWISS ARMY KNIFE FOR DATABASES

THE SWISS ARMY KNIFE FOR DATABASES

B Y P E T B Y P E TE R V A N D E R S M A NE R V A N D E R S M A N P A G E 2 8P A G E 2 8 T I P T I PS S A N D T R I C K S W I T H K B M M E M T AA N D T R I C K S W I T H K B M M E M T AB L EB L E B Y K I M B Y K I M M A D S EM A D S EN  N   PAGPAGE E 3939 Advertisers Advertisers BETTER OFFICE BETTER OFFICE COMPONENTS

COMPONENTS 4 4 DEVELOPERS DEVELOPERS 4848 COMPUTER MA

COMPUTER MATH & TH & GAMES GAMES 4/54/5 DANIEL TETI DELPHI COOKBOOK 11 DANIEL TETI DELPHI COOKBOOK 11 EVERS 36

EVERS 36

NEW BLAISE LIBRARY 38 NEW BLAISE LIBRARY 38 PASCON DELPHI 37 PASCON DELPHI 37 UPSCENE 35 UPSCENE 35 VISUINO MITOV 27 VISUINO MITOV 27

Publisher: Foundation for Supporting the Pascal Programming Language Publisher: Foundation for Supporting the Pascal Programming Language in collaboration with the Dutch Pascal User Group (Pascal Gebruikers Groep) in collaboration with the Dutch Pascal User Group (Pascal Gebruikers Groep) © Stichting Ondersteuning Programmeertaal Pascal © Stichting Ondersteuning Programmeertaal Pascal

2

(3)

All material published in Blaise Pascal

All material published in Blaise Pascal is copyright © SOPP is copyright © SOPP Stichting Ondersteuning ProgrameertaaStichting Ondersteuning Programeertaal Pascal unless otherwise noted and l Pascal unless otherwise noted and maymay

not be copied, distributed

not be copied, distributed or republished without written permission. Authors agree that code associated with or republished without written permission. Authors agree that code associated with their articles will be madetheir articles will be made

available to subscribers after publication by placing it on the

available to subscribers after publication by placing it on the website of the PGG for download, and website of the PGG for download, and that articles and code will be that articles and code will be placed onplaced on

distributable data storage media. Use of program listings by subscribers for research and study purposes is allowed, but not for commercial

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

purposes. Commercial use of program listings and code is prohibited without the code is prohibited without the written permission of the author.written permission of the author. Copyright notice

Copyright notice

Editors Editors

Peter Bijlsma, W. (Wim) van Ingen Schenau, Rik Smit, Peter Bijlsma, W. (Wim) van Ingen Schenau, Rik Smit, Correctors

Correctors

Howard Page-Clark, James D. Duff  Howard Page-Clark, James D. Duff  Trademarks

Trademarks

All trademarks used are acknowledged as the

All trademarks used are acknowledged as the property of their respective owners.property of their respective owners. Caveat

CaveatWhilst we endeavour to ensure that what Whilst we endeavour to ensure that what is published in the magazine is correct, we cannot accept responsibility for any errors or omissions.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

If you notice something which may be incorrect, please contact the Editor and we will publish a correction where relevant.will publish a correction where relevant. Subscriptions

Subscriptions( 2013( 2013prices )prices ) 1:

1: Printed versiPrinted version: subscription: subscription on € 65.-- € 65.-- Incl. VAIncl. VAT 6 % (includT 6 % (including code, ping code, programs rograms and printed and printed magazine,magazine, 10 issues per

10 issues per year excluding postage).year excluding postage). 2:

2: Electronic - non prElectronic - non printed subscriptiinted subscription on € 45.-- Incl. VA€ 45.-- Incl. VAT 21% (including coT 21% (including code, programde, programs and download ms and download magazine)agazine)

Subscriptions can be taken out online at

Subscriptions can be taken out online atwww.blaisepascal.euwww.blaisepascal.eu or by written order, or by sending an email toor by written order, or by sending an email to [email protected]@blaisepascal.eu Subscriptions can start at any date. All issues published in the calendar year of the subscription will be sent as

Subscriptions can start at any date. All issues published in the calendar year of the subscription will be sent as well.well. Subscriptions run 365 days.

Subscriptions run 365 days.Subscriptions Subscriptions will not be prolonged without notice. Rwill not be prolonged without notice. Receipt of payment will be sent by email.eceipt of payment will be sent by email. Subscriptions can be paid by sending the payment to:

Subscriptions can be paid by sending the payment to: ABN AMRO Bank Account no. 44 19

ABN AMRO Bank Account no. 44 19 60 86360 863  or   or by credit card: by credit card: PaypalPaypal Name: Pro

Name: Pro Pascal Foundation-FounPascal Foundation-Foundation for dation for Supporting the Supporting the Pascal ProgrammPascal Programming Language (Stichting ing Language (Stichting Ondersteuning ProgrameertaaOndersteuning Programeertaal Pascal)l Pascal) IBAN:

IBAN:NL82 ABNA 0441960863 BIC ABNANL2A VAT no.: 81 42 54 147NL82 ABNA 0441960863 BIC ABNANL2A VAT no.: 81 42 54 147 (Stichting Programmeertaal Pascal)(Stichting Programmeertaal Pascal) Subscription department

Subscription departmentEdelstenenbaan 21 Edelstenenbaan 21 / 3402 XA IJsselstein, The Netherlands / Tel.: + 31 (0) 30 890.66.44 / Mobile: + 31 (0) 6 21.23.62.68/ 3402 XA IJsselstein, The Netherlands / Tel.: + 31 (0) 30 890.66.44 / Mobile: + 31 (0) 6 21.23.62.68 [email protected]

[email protected] Editor - in - chief  Editor - in - chief 

Detlef D. Overbeek, Netherlands Tel.: +31 (0)30 890.66.44 / Mobile: +31 (0)6 21.23.62.68 Detlef D. Overbeek, Netherlands Tel.: +31 (0)30 890.66.44 / Mobile: +31 (0)6 21.23.62.68 News and Press Releases

News and Press Releasesemail only toemail only [email protected]@blaisepascal.eu Authors

-Authors - Christian nameChristian name in alphabethical orderin alphabethical order

A

A Andrea Andrea Raimondi Raimondi ,,

B

B Stephen Ball,Stephen Ball,Peter Peter Bijlsma, Bijlsma, Dmitry Dmitry BoyarintsevBoyarintsev

C

C Michaël Van Canneyt,Michaël Van Canneyt,Marco Marco Cantù,Cantù,

D

D David David Dirkse, Daniele Dirkse, Daniele TTetieti

F

F Bruno Bruno FierensFierens

G

G Primož Primož Gabrijelčič, Gabrijelčič, Mattias Mattias GaertnerGaertner

H

H Fikret Fikret HasovicHasovic

J

J Cary Cary JensenJensen

L

L Wagner Wagner R. R. Landgraf,Landgraf, Sergey LyubeznyySergey Lyubeznyy

K

K Max Max KleinerKleiner

M

M Kim Kim Madsen, Felipe Madsen, Felipe Monteiro de Monteiro de CavalhoCavalho

N

N Jeremy Jeremy North,North,

O

O Inoussa Inoussa OuedraogoOuedraogo

P

P Howard Howard Page-ClaPage-Clark,rk,

S

S Rik Rik Smit, Smit, Bob Bob Swart,Swart,

Z

Z Siegfried Siegfried ZuhrZuhr

Marco Cantù

Marco Cantù

www.marcocantu.com 

www.marcocantu.com 

 marco.can

 marco.cantu @ gmailtu @ gmail.com .com 

David Dirkse

David Dirkse

www.davdata.nl

www.davdata.nl

E-mail: David @ davdata.nl

E-mail: David @ davdata.nl

Bruno Fierens

Bruno Fierens

www.tmssoftware.com 

www.tmssoftware.com 

 bruno.fie

 bruno.fierens @ tmsrens @ tmssoftware.software.coco m  m 

Primož Gabrijelčič

Primož Gabrijelčič

www.

www.

 primoz @

 primoz @ gabrijelcigabrijelcic.orgc.org

Cary Jensen Cary Jensen www.jensendatasystems.com  www.jensendatasystems.com  http://caryjensen.blogspot.nl http://caryjensen.blogspot.nl Wagner R. Landgraf  Wagner R. Landgraf  wagner @ tmssoftware.com  wagner @ tmssoftware.com  Kim Madsen Kim Madsen www.component4developers www.component4developers

Peter van der Sman

Peter van der Sman

[email protected]

[email protected] Jeremy NorthJeremy Northjeremy.north @ gmail.com jeremy.north @ gmail.com 

Benno Evers Benno Evers  b.evers  b.evers @everscustomtechnology.nl @everscustomtechnology.nl

Detlef Overbeek - Editor

Detlef Overbeek - Editor in Chief in Chief 

www.blaisepascal.eu

www.blaisepascal.eu

editor @ blaisepascal.eu

editor @ blaisepascal.eu

Howard Page Clark

Howard Page Clark

E-mail: hdpc @ talktalk.net E-mail: hdpc @ talktalk.net Rik Smit Rik Smit rik @ blaisepascal.eu rik @ blaisepascal.eu Bob Swart Bob Swart www.eBob42.com www.eBob42.com Bob @ eBob42.com Bob @ eBob42.com Max Kleiner Max Kleiner www.softwareschule.ch www.softwareschule.ch  max@kleine

 [email protected] r.com 

Please note: extra space characters have been deliberately added around the @ symbol in

Please note: extra space characters have been deliberately added around the @ symbol in

these email addresses, which need to be removed if you use them.

these email addresses, which need to be removed if you use them.

editor @

editor @

blaisepascal.e

blaisepascal.e

u

u

Issue

Issue Nr Nr 5 5 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

Daniele Teti Daniele Teti www.danieleteti.it www.danieleteti.it [email protected] [email protected] Andrea Raimondi Andrea Raimondi John Kuiper John Kuiper [email protected] [email protected]

Wim Van Ingen Schenau

Wim Van Ingen Schenau

-Editor -Editor wisone @ xs4all.nl wisone @ xs4all.nl 3 3

(4)

BLAISE PASCAL MAGAZINE

BLAISE PASCAL MAGAZINE

is proud to announce the first

is proud to announce the first

edition of David

edition of David

Dirkse’

Dirkse’

s book:

s book:

COMPUTER

&

COMPUTER

MATH

MATH

&

I

I

N

N

GAMES

GAMES

PASCAL

PASCAL

DAVID DIRKSE

DAVID DIRKSE

presales at

presales at

www.blaisepascal.eu/DavidDirkse/ComputerMath_Games.html

www.blaisepascal.eu/DavidDirkse/ComputerMath_Games.html

 procedure

 procedure

 ;

 ;

 var

 var

 begin

 begin

:=

:=

f

f

o

o

r

r

i

i

1

1

t

t

o

o

9

9

d

d

o

o

 begin

 begin

;

;

end 

end 

end 

end 

;

;

(5)

DAVID DIRKSE’s

DAVID DIRKSE’s

A book printed in full col

A book printed in full col

or, sewn back bound with a hard

or, sewn back bound with a hard

cover. Quality first. A fully indexed PDF file is included.

cover. Quality first. A fully indexed PDF file is included.

The book contains 87 chapters

The book contains 87 chapters

, 53 projects with source

, 53 projects with source

code and compiled programs (exe).

code and compiled programs (exe).

All of these projects you can download at our special

All of these projects you can download at our special

website www.blaisepascal.eu

website www.blaisepascal.eu

The book is highly educational and suitabl

The book is highly educational and suitabl

e for

e for

beginner

beginner

s

s

as well as for professionals.

as well as for professionals.

Play board games, solve puzzles, operate a vintage

Play board games, solve puzzles, operate a vintage

mechanical calculator, Produce 3-dimensional computer

mechanical calculator, Produce 3-dimensional computer

art, generate lists of prime numbers, expl

art, generate lists of prime numbers, expl

ore and draw

ore and draw

any mathematical function.

any mathematical function.

Solve systems of equatio

Solve systems of equatio

ns, calcula

ns, calcula

te the area of

te the area of

complex

complex

polygons.

polygons.

Draw lines, circles and ellipses.

Draw lines, circles and ellipses.

Resize, rotate, compress digital images.

Resize, rotate, compress digital images.

Design your own font, generate and reduce Truth Tables

Design your own font, generate and reduce Truth Tables

from Boolean algebra.

from Boolean algebra.

And more important: underst

And more important: underst

and how it all works!

and how it all works!

For the games, winning strategies are explained.

For the games, winning strategies are explained.

For puzzles the search algorithm.

For puzzles the search algorithm.

For all projects: the math behind is thoroughly discussed.

For all projects: the math behind is thoroughly discussed.

The Delphi 3 – 7 (or later) source code is avai

The Delphi 3 – 7 (or later) source code is avai

lable

lable

together with

together with

full explanation.

full explanation.

Most of

Most of

the

the

projects can

projects can

be done with FPC Lazarus as well.

be done with FPC Lazarus as well.

Pascal is the most educative

Pascal is the most educative

, easy to learn and only

, easy to learn and only

language available for several operating systems like

language available for several operating systems like

Windows, Linux, Mac and Android.

Windows, Linux, Mac and Android.

It is a great programming language…

It is a great programming language…

COMPUTER

&

COMPUTER

MATH

MATH

&

I

I

N

N

GAMES

(6)

Page 9 Page 9

WATER CLOCK - CHINA - BEGINNING OF TIME (BC 4000) WATER CLOCK - CHINA - BEGINNING OF TIME (BC 4000) Some authors claim that water clocks appeared in China Some authors claim that water clocks appeared in China as early as 4000 BC

as early as 4000 BC

DELPHI

DELPHI

The cult of Apollo at

The cult of Apollo at

Delphi probably Delphi probably dates back to dates back to the 700s B . C the 700s B . C .,.,

Plato in Classical Attic;

Plato in Classical Attic;

428/427 or 424/423 – 348/347 BC)

428/427 or 424/423 – 348/347 BC)

was a philosopher, as well as

was a philosopher, as well as mathematician,mathematician,

in Classical Greece.

in Classical Greece.

Pythagoras

PythagorasPhilosopherPhilosopher Pythagoras of Samos was an Pythagoras of Samos was an Ionian Greek

Ionian Greek philosopherphilosopher, mathematician,, mathematician, and founder of the religious movement and founder of the religious movement called Pythagoreanism.

called Pythagoreanism. Born: 571

Born: 571 - 495 - 495 BC,BC, Archimedes

ArchimedesMathematicianMathematician

Archimedes of Syracuse was an Ancient

Archimedes of Syracuse was an Ancient

Greek mathematician, physicist,

Greek mathematician, physicist, engineerengineer,,

inventor, and astronomer.

inventor, and astronomer.

He is regarded as one of the leading scientists

He is regarded as one of the leading scientists

in classical antiquity. Wikipedia

in classical antiquity. Wikipedia

Born: 287 - 212 BC, Syracuse, Italy

Born: 287 - 212 BC, Syracuse, Italy

Thales

Thales Philosopher Philosopher

Thales of Miletus was a pre-Socratic Greek philosopher

Thales of Miletus was a pre-Socratic Greek philosopher

from Miletus in Asia Minor and one of the

from Miletus in Asia Minor and one of the

Seven Sages of Greece.

Seven Sages of Greece. Many, most notably Aristotle,Many, most notably Aristotle,

regard him as the first philosopher in the Greek tradition.

regard him as the first philosopher in the Greek tradition.

Born: 624

Born: 624 BC - BC - 546546

Euclid

EuclidMathematicianMathematician

Born Mid-4th century BC - 3rd century BC Born Mid-4th century BC - 3rd century BC Residence Alexandria, Hellenistic Egypt Residence Alexandria, Hellenistic Egypt Fields Mathematics Known for Fields Mathematics Known for Euclidean geometry / Euclid's Elements Euclidean geometry / Euclid's Elements Euclidean algorithm

Euclidean algorithm

Roman Empire 700 BC Roman Empire 700 BC

Decay of the Roman Empire 500 Decay of the Roman Empire 500 Building of Europe

Building of Europe

Babbage Difference Engine No. 2

Babbage Difference Engine No. 2 Building of France 58–52 BC

Building of France 58–52 BC

Building of Spain 912 and Portugal 800 Building of Spain 912 and Portugal 800

Discovery of Amerca by the Vikings 990 - 1050

Discovery of Amerca by the Vikings 990 - 1050

Discovery of America by Columbus

Discovery of America by Columbus

Columbus led his three ships

Columbus led his three ships--the Nina,the Nina,

the Pinta and the Santa Maria

the Pinta and the Santa Maria -

-out of the Spanish port of Palos on August 3, 1492.

out of the Spanish port of Palos on August 3, 1492.

Blaise Pascal (

Blaise Pascal (19 June 1623 – 19 August 1662)19 June 1623 – 19 August 1662) was a French

was a French mathematician,mathematician, physicist, inventor, writer and

physicist, inventor, writer and Christian philosopherChristian philosopher..

creates the first calculators

creates the first calculators

Blaise Pascal starts to gamble - result first s

Blaise Pascal starts to gamble - result first statisticstatistics

Niklaus Wirth

Niklaus Wirth

born February 15, 1934 He is a Swiss

born February 15, 1934 He is a Swiss

computer scientist, best known for

computer scientist, best known for

designing several programming languages,

designing several programming languages,

including Pascal, and for

including Pascal, and for pioneering severalpioneering several

classic topics in

classic topics in software engineering.software engineering.

Windows

Windows

Lisa - Pascal

Lisa - Pascal was a Pascal implementation for the Apple Lisa workstation.was a Pascal implementation for the Apple Lisa workstation.

It was an extension of the earlier Apple Pascal for Apple II machines,

It was an extension of the earlier Apple Pascal for Apple II machines,

but generated object code for 68000 processors that had to be linked

but generated object code for 68000 processors that had to be linked

against the required libraries in the

against the required libraries in the Lisa OS workshop.Lisa OS workshop.

Lisa Pascal laid the foundation for the development of

Lisa Pascal laid the foundation for the development of Clascal and Mac PascalClascal and Mac Pascal

the first implementations of Object Pascal.

the first implementations of Object Pascal.

Turbo Pascal

Turbo Pascal

Developer(s

Developer(s) Anders ) Anders Hejlsberg whileHejlsberg while

working at Borland

working at Borland

Operating system CP/M, CP/M-86, DOS,

Operating system CP/M, CP/M-86, DOS,

Windows 3.x, Macintosh

Windows 3.x, Macintosh

Platform 8080/Z80, 8085, x86

Platform 8080/Z80, 8085, x86

DELPHI 7 released in August 2002

DELPHI 7 released in August 2002

DELPHI

DELPHI

released February 14, 1995 released February 14, 1995 Embarcadero Technologies in 2008. Embarcadero Technologies in 2008. Codegear Delphi 2007. Codegear Delphi 2007.

Charles Babbage

Charles Babbage

 -  - mathematicianmathematician

conceived of the first programmable computer in the

conceived of the first programmable computer in the 1830s1830s

Babbage never built his Difference Engine

Babbage never built his Difference Engine

a mechanical calculator with thousands of parts

a mechanical calculator with thousands of parts

-because of cost overruns and political disagreements,

because of cost overruns and political disagreements,

but the inventor passed on plans

but the inventor passed on plans for its completion, for its completion,

and in 1991, the Science Museum in London actually

and in 1991, the Science Museum in London actually

built it (the printing component was finished in 2000).

built it (the printing component was finished in 2000).

As suspected, it actually works.

As suspected, it actually works.

The roots of Turbo Pascal v1.0

The roots of Turbo Pascal v1.0started in Destarted in Denmark. nmark. The first sThe first step,tep,

in 1981, was the

in 1981, was the Blue Label Software Pascal Compiler - BLS PascalBlue Label Software Pascal Compiler - BLS Pascal

Compiler v1.2, copyright 1981

Compiler v1.2, copyright 1981 by Poly-Data microcenter ApS,by Poly-Data microcenter ApS,

Strandboulv

Strandboulvarden 63, DK arden 63, DK 2100 Copenhagen - written by2100 Copenhagen - written byAndersAnders

Hejlsberg

Hejlsberg for the NASCOM kit computer. for the NASCOM kit computer.

including Delphi, to concentrate on its ALM line.

including Delphi, to concentrate on its ALM line. On NovemberOn November

14, 2006 Borland transferred the development tools group to

14, 2006 Borland transferred the development tools group to

an independent

an independent subsidiary company named subsidiary company named CodeGearCodeGear,,

instead of selling it. Borland sold

instead of selling it. Borland sold CodeGear to EmbarcaderoCodeGear to Embarcadero

T

Technologies in 2008. Embarcadero retained echnologies in 2008. Embarcadero retained the CodeGearthe CodeGear

division created by Borland to identify its tool

division created by Borland to identify its tool and databaseand database

offerings, but identified its own database tools

offerings, but identified its own database tools under theunder the

DatabaseGear name.

DatabaseGear name.

Difference Engine No. 1, portion,1832

Difference Engine No. 1, portion,1832

ISSUE 40

ISSUE 40

IN THIS ISSUE (43)

(7)

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE 77

Euclid of Alexandria to distinguish him

Euclid of Alexandria to distinguish him

from Euclid of Megara, was a Greek

from Euclid of Megara, was a Greek

mathematician, often referred to as the

mathematician, often referred to as the

"Father of Geometry". He was active in

"Father of Geometry". He was active in

Alexandria during the reign of Ptolemy

Alexandria during the reign of Ptolemy

I (323–283 BC). His Elements is one of

I (323–283 BC). His Elements is one of

the most influential works in the history

the most influential works in the history

of mathematics, serving as the main

of mathematics, serving as the main

textbook for teaching mathematics

textbook for teaching mathematics

(especially geometry) from the time of 

(especially geometry) from the time of 

Very few original references to Euclid survive, so little

Very few original references to Euclid survive, so little

is known about his life. The date

is known about his life. The date, place and, place and

circumstances of both his birth and death are unknown

circumstances of both his birth and death are unknown

and may only be estimated roughly relative to other

and may only be estimated roughly relative to other

figures mentioned alongside him. He is rarely

figures mentioned alongside him. He is rarely

mentioned by name by other Greek mathematicians

mentioned by name by other Greek mathematicians

from Archimedes onward, who usually call him "the

from Archimedes onward, who usually call him "the

author of Elements".The few historical references to

author of Elements".The few historical references to

Euclid were written centuries after he lived, by Proclus

Euclid were written centuries after he lived, by Proclus

c. 450 AD and Pappus of Alexandria c. 320 AD

c. 450 AD and Pappus of Alexandria c. 320 AD

Proclus introduces Euclid only briefly in his

Proclus introduces Euclid only briefly in his

Commentary on the Elements. According to Proclus,

Commentary on the Elements. According to Proclus,

Euclid belonged to Plato's "persuasion" and brought

Euclid belonged to Plato's "persuasion" and brought

together the Elements, drawing on prior work by

together the Elements, drawing on prior work by

several pupils of Plato. Proclus believes that Euclid is

several pupils of Plato. Proclus believes that Euclid is

not much younger than these, and that he must have

not much younger than these, and that he must have

lived during the time of Ptolemy I because he was

lived during the time of Ptolemy I because he was

mentioned by Archimedes (287–212 BC). Although the

mentioned by Archimedes (287–212 BC). Although the

apparent citation of Euclid by Archimedes has been

apparent citation of Euclid by Archimedes has been

 judg

 judged to be aed to be an inten interpolrpolatioation by latn by later edier editors otors of hisf his

works, it is still believed that Euclid wrote his works

works, it is still believed that Euclid wrote his works

before those of Archimedes.

before those of Archimedes.

Proclus later retells a story that, when Ptolemy I asked

Proclus later retells a story that, when Ptolemy I asked

if there was a shorter path to learning geometry than

if there was a shorter path to learning geometry than

Euclid's Elements, "Euclid replied there is no royal

Euclid's Elements, "Euclid replied there is no royal

road to geometry. In the only other key reference to

road to geometry. In the only other key reference to

Euclid, Pappus briefly mentioned in the fourth century

Euclid, Pappus briefly mentioned in the fourth century

that Apollonius "spent a very long time with the pupils

that Apollonius "spent a very long time with the pupils

of Euclid at Alexandria 247–222 BC.

of Euclid at Alexandria 247–222 BC.

Euclidean geometry is a mathematical system

Euclidean geometry is a mathematical system

attributed to the Alexandrian Greek mathematician

attributed to the Alexandrian Greek mathematician

Euclid, which he described in his textbook on

Euclid, which he described in his textbook on

geometry: the Elements. Euclid's method consists in

geometry: the Elements. Euclid's method consists in

assuming a small set of intuitively appealing axioms,

assuming a small set of intuitively appealing axioms,

and deducing many other propositions (theorems)

and deducing many other propositions (theorems)

from these. Although many of Euclid's results had

from these. Although many of Euclid's results had

been stated by earlier mathematicians, Euclid was the

been stated by earlier mathematicians, Euclid was the

first to show how these propositions could fit into a

first to show how these propositions could fit into a

comprehensive deductive and logical system. The

comprehensive deductive and logical system. The

Elements begins with plane geometry, still taught in

Elements begins with plane geometry, still taught in

secondary school as the first axiomatic system and the

secondary school as the first axiomatic system and the

first examples of formal proof. It goes on to the solid

first examples of formal proof. It goes on to the solid

geometry of three dimensions. Much of the Elements

geometry of three dimensions. Much of the Elements

states results of what are now called algebra and

states results of what are now called algebra and

number theory, explained in geometrical language.

number theory, explained in geometrical language.

For more than two thousand years, the adjective

For more than two thousand years, the adjective

"Euclidean" was unnecessary because no other sort of

"Euclidean" was unnecessary because no other sort of

geometry had been conceived. Euclid's axioms

geometry had been conceived. Euclid's axioms

seemed so intuitively obvious (with the possible

seemed so intuitively obvious (with the possible

exception of the parallel postulate) that any theorem

exception of the parallel postulate) that any theorem

proved from them was deemed true in an absolute,

proved from them was deemed true in an absolute,

often metaphysical, sense. Today, however, many

often metaphysical, sense. Today, however, many

other self-consistent non-Euclidean geometries are

other self-consistent non-Euclidean geometries are

known, the first ones having been discovered in the

known, the first ones having been discovered in the

early 19th century. An implication of Albert Einstein's

early 19th century. An implication of Albert Einstein's

theory of general relativity is that physical space itself

theory of general relativity is that physical space itself

is not Euclidean, and Euclidean space is a good

is not Euclidean, and Euclidean space is a good

approximation for it only where the gravitational field

approximation for it only where the gravitational field

is weak.

is weak.

Euclidean geometry is an example of synthetic

Euclidean geometry is an example of synthetic

geometry, in that it proceeds logically from axioms to

geometry, in that it proceeds logically from axioms to

propositions without the use of coordinates. This is in

propositions without the use of coordinates. This is in

contrast to analytic geometry, which uses coordinates.

contrast to analytic geometry, which uses coordinates.

its publication until the late

its publication until the late 19th or early 19th or early 20th century.20th century.

In the Elements, Euclid deduced the

In the Elements, Euclid deduced the principles of what isprinciples of what is

now called Euclidean geometry from a small set of

now called Euclidean geometry from a small set of

axioms. Euclid also wrote works on perspective, conic

axioms. Euclid also wrote works on perspective, conic

sections, spherical geometry, number theory

sections, spherical geometry, number theory and rigorand rigor..

Because the lack of biographical information

Because the lack of biographical information

is unusual for the period (extensive

is unusual for the period (extensive

biographies are available for most significant

biographies are available for most significant

Greek mathematicians for several centuries

Greek mathematicians for several centuries

before and after Euclid), some researchers

before and after Euclid), some researchers

have proposed that Euclid was not, in fact, a

have proposed that Euclid was not, in fact, a

historical character and that his works were

historical character and that his works were

written by a team of mathematicians who took

written by a team of mathematicians who took

the name Euclid from the historical character

the name Euclid from the historical character

Euclid of Megara.

(8)

Issue Nr 6 2015

Issue Nr 6 2015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

×

×

8

8

On new year of the year 1997 mr. Black, a math

On new year of the year 1997 mr. Black, a math

teacher

teacher, meets his form, meets his former student White. Wer student White. Whitehite

remembers Black’s fascination for number

remembers Black’s fascination for numbers ands and

greets him with: “my age is equal to the sum o

greets him with: “my age is equal to the sum of thef the

digits of my year of birth”.

digits of my year of birth”.

Black thinks for a while and then a

Black thinks for a while and then answers:nswers:

 “co

 “congrngratuatulatlationions on yos on your biur birthrthdayday”.”.

QUESTIONS:

QUESTIONS:

1. How

1. HowBlackBlack may know that it is may know that it is White'sWhite's

birthday?

birthday?

2.

2. What What is is White's White's age?age? SOLUTION

SOLUTION

If Peter was born in 2000 and we live in

If Peter was born in 2000 and we live in

the year 2015 there are two possibilities:

the year 2015 there are two possibilities:

Peter is

Peter is 14 years old 14 years old and his and his birthdabirthdayy

still has to come or Peter 15 years old

still has to come or Peter 15 years old

and his

and his birthday is birthday is passed.passed.

The solution may be found by checking

The solution may be found by checking

all possible years and calculating the

all possible years and calculating the

sum of the birthyear digits. Test for

sum of the birthyear digits. Test for

digits

digitsum um = = current year current year – – birth year birth year ...(-

...(-1 if anniversary still has to come)

1 if anniversary still has to come)

This means a lot of work, so better we

This means a lot of work, so better we

write a program to do the job.

write a program to do the job. THE PROGRAM

THE PROGRAM

There may be more solutions. We choose

There may be more solutions. We choose

to calculate them all and store them in a

to calculate them all and store them in a

list. Thereafter the solutions are

list. Thereafter the solutions are

displayed on the screen.

displayed on the screen.

For a solution we define the data type:

For a solution we define the data type:

The solutions are displayed in a paintbox, see

The solutions are displayed in a paintbox, see

picture.

picture.

We notice columns for the solution number, the

We notice columns for the solution number, the

year of birth, the

year of birth, the age and the age and the answer of answer of thethe

question “anniversary passed?”.

question “anniversary passed?”.

Pressing the

Pressing thesearch buttonsearch button starts the search starts the search

process.

process.

Also pressing the

Also pressing thereturn keyreturn key after the current after the current

year starts the search.

year starts the search.

The text on the form is placed in

The text on the form is placed in TlabelTlabel

components.

components.

On the bottom of the form at full width there is

On the bottom of the form at full width there is

a

a statictextstatictext comp component onent for for messages.messages.

The picture below shows : “4 solutions found”.

The picture below shows : “4 solutions found”.

There are three reasons to make a function or a

There are three reasons to make a function or a

procedure. First is the case of common code that

procedure. First is the case of common code that

is needed at multiple places of the main program.

is needed at multiple places of the main program.

This reduces the total code.

This reduces the total code.

The second reason is clearity. We place specific

The second reason is clearity. We place specific

code apart for readability.

code apart for readability.

For this reason we made a function to sum the

For this reason we made a function to sum the

birthyear digits.

birthyear digits.

And these global variables:

And these global variables:

Thisyear

Thisyear comes from a TEdit component comes from a TEdit component

(“this year”)

(“this year”) where the current where the current year was typed.year was typed.

Solutions

Solutions is an arra is an array[1..maxsolution] of y[1..maxsolution] of typetype

TSolution.

TSolution. SolutionNr

SolutionNr is the number of stored solutions. is the number of stored solutions.

This value is 0 if no solution exists.

This value is 0 if no solution exists.

 Ma

 Maxsxsololututioionn is a constant set at 20. is a constant set at 20.

Tsolution

Tsolution = = record record 

: : ;; bi birtrthyhyeaear r wowordrd : : ;; a agge e bbyyttee : : ;; bi

birthrthdadaypaypassessed d booboolealeann

; ; end  end   var  var tthhiissyyeeaar r : : wwoorrdd;; : : [[ ]] ;; s soolluuttiioonns s aarrrraayy 1..1..mmaaxxssoolluuttiioon n ooff TTssoolluuttiioonn : : ;; so solulutitiononNr Nr bybytete

(9)

9

9 MaxSolution

MaxSolution is a constant set to 20, the space in is a constant set to 20, the space in

the solutions array.

the solutions array.

Which saves typing. Otherwise we had to add

Which saves typing. Otherwise we had to add

solutions[solutionNr].

solutions[solutionNr]. before before

birthyear,

birthyear, age. Now this is done by Delphi. age. Now this is done by Delphi.

The

The procedure procedure ShowSolutions:ShowSolutions:

function

function ssumumddigigiits ts ( ( yeyeaar r : : woword rd ) ) : : bbyytete;;

 var

 var ss :  : stringstring;; : : ;; i i bbyyttee  begin  begin : := = (( ));; s s iintntttososttr r yyeaearr := := ;; result result 00 : := = (( ) ) ::= = ++ (( [ ][ ]))-- (( ));; f foorr i i 11 ttoo lleennggtth h s s ddoo rreessuullt t rreessuullt t oorrd d s s i i oorrdd '0''0' end  end ;; Ord('0') is

Ord('0') is 48, 48, the the ASCII code ASCII code of of digit digit 0.0.

So ord('8') – ord('0') = 8.

So ord('8') – ord('0') = 8.

Without

Without -ord('0-ord('0') ') we we would get would get 56.56. THE SEARCH PROCESS

THE SEARCH PROCESS

In procedure searchBrtClick, called by the

In procedure searchBrtClick, called by the searchsearch

button, we notice following local variables:

button, we notice following local variables:

 va  varr didigigitstsum um : : bybytete;; : : ;; bi birthrthyeyear ar worwordd variabele

variabelebirthyearbirthyear runs from runs from

startyear...thisyear

startyear...thisyear..

startyear

startyear is a constant set to 1900. is a constant set to 1900.

Digitsum

Digitsum is the sum of the digits of is the sum of the digits of

birthyear.

birthyear.

Before the search starts two checks are made:

Before the search starts two checks are made:

1. the current year must be defined

1. the current year must be defined

2. the current year must be equal or bigger than

2. the current year must be equal or bigger than

startyear.

startyear.

Then

ThensolutionNrsolutionNr is set to zero.is set to zero.

All values of birthyear are checked.

All values of birthyear are checked.

If the test yields true, age (=digitsum) and

If the test yields true, age (=digitsum) and

anniversary passed is added

anniversary passed is added to the solutionsto the solutions

array. This program loop looks like:

array. This program loop looks like:

f foorr bibirtrthyhyeaear r  := := ststarartytyeaear r ttoo ththisisyeyearar ddoo  begin  begin : :== (( ));; dig

digitsitsum um sumsumdigdigits its birbirthythyeaearr

= = - -i iff didigigitstsum um ththisisyeyear ar bibirtrthyhyeaearr tthheenn ( ( ,, ,, ));; savesolut

savesolution ion digitsum digitsum birthyear birthyear truetrue

=

= - - -

-i

iff didigigitstsum um ththisisyeyear ar bibirtrthyhyeaearr 11 tthheenn

  (

  savesolutsavesolution ion (digitsum birthyear falsedigitsum birthyear false,, ,, ));;

; ;

end 

end   //for  //for 

The procedure SaveSolution:

The procedure SaveSolution:

 procedure

 procedure SaveSaveSoluSolution tion ((ag by wag by w,, :: ord ord ;; bp bobp bo:: oleaoleann));;  //ag:age; by:birthyear; bp:birthday passed 

 //ag:age; by:birthyear; bp:birthday passed 

 begin  begin ( ( );); inc solutionNr inc solutionNr <= <= i iff sosolulutitiononNr Nr mamaxsxsololututioionn tthheenn [ [ ]] w

wiitthh solutions solutionNrsolutions solutionNr ddoo

 begin  begin := := ;; b biirrtthhyyeeaar r bbyy := := ;; a agge e aagg := := ;; bi birtrthdhdayaypapassssed ed bpbp ; ; end  end  end  end ;; Third is

Third is to to concentrconcentrate ate specifspecific ic operationoperations s forfor

maintainability. If the calculation of an area is

maintainability. If the calculation of an area is

performed by one function, in case of a change

performed by one function, in case of a change

only one place in the program needs to be

only one place in the program needs to be

changed.

changed.

 procedure

 procedure showSolutionsshowSolutions;;  //display solutions in paintbox1  //display solutions in paintbox1

 var  var i i , , n n : : bbyyttee;; : : ;; s s stringstring , , : : ;; x x y y wwoorrdd  begin  begin ; ; clearpaintbox clearpaintbox . . .. w

wiitthh form1 PaintBox1 Canvasform1 PaintBox1 Canvas ddoo

 begin  begin . . ::= = ;; br brusush h ststylyle e bsbsClCleaearr . . ::= = ;; fo font nt CoCololor r fofontntcocololorr . . ::= = ;; fo font nt NaName me fofontntnanameme . . ::== ;; fo font nt HeHeigight ht fofontntheheigightht := := f foorr n n 11 ttoo ssoolluuttiioonnNNrr ddoo <= <= i iff n n sosolulutitiononspspererdidispsplalayy tthheenn  begin  begin : := = (( -- ))* * + + ;; y y n n 11 ffoonntthheeiigghht t yymmaarrggee := := f foorr ii 00 ttoo 33 ddoo  begin  begin : := = [[ ]];; x x ccoolluummnns s ii c caassee ii ooff : : ::= = (( ));; 0 0 s s iinnttttoossttr r nn : : ::== (( [[ ]].. ));; 1 1 s s ininttttosostr tr sosolulutitionons s n n bibirtrthyhyeaearr : : ::= = (( [[ ]].. ));; 2 2 s s ininttttosostr tr sosolulutitionons s n n agagee : : [[ ]].. 3

3 ifif solutions solutions n n birthdaypbirthdaypassedassed

  then

  then ss :=:= 'yes''yes'

:= := ;;

else

else s s 'no''no' ;

;

end 

end  //case //case

  (   textout x y stextout x y s( ,, ,, ));; ; ; end  end  ; ; end 

end  //for..if  //for..if  ;

;

end 

end  //width //width

end 

end ;;

n adresses all solutions.

n adresses all solutions.

Fontcolor,

Fontcolor, fontname, fontname, fontheightfontheight are are

preset constants.

preset constants.

Y is the vertical position of the text on paintbox1.

Y is the vertical position of the text on paintbox1.

X is the horizontal position.

X is the horizontal position.

Per solution, so per line of text, a variable i counts

Per solution, so per line of text, a variable i counts

0..3 for the

0..3 for thecolumncolumns . s . ColumnColumns[i]s[i] holds theholds the

x where the text is to start, also a preset constant.

x where the text is to start, also a preset constant.

Per case of i the text s is prepared.

Per case of i the text s is prepared.

Textout(...)

Textout(...) prints s.prints s.

Issue

(10)

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

10

10

Why all this preset constants? Why not using the

Why all this preset constants? Why not using the

values directly? Sure we could. But using

values directly? Sure we could. But using

constants is smarter because they make future

constants is smarter because they make future

changes much more easy. Say we want to change

changes much more easy. Say we want to change

the startyear. Without the constant definition we

the startyear. Without the constant definition we

would have to change all places where the

would have to change all places where the

constant (1900) was used. But defined as a

constant (1900) was used. But defined as a

constant we only need to change the constant

constant we only need to change the constant

value once to be effective in all places in the

value once to be effective in all places in the

program.

program.

PROCEDURE BEFORE CALLED

PROCEDURE BEFORE CALLED

CLEARPAINTBOX.

CLEARPAINTBOX.

This procedure erases the

This procedure erases the paintbox by paintingpaintbox by painting

the canvas white. (

the canvas white. ( for th for this colis color we couor we could hald have useve used ad a

constant as well

constant as well))

 procedure

 procedure clearpaintboxclearpaintbox;;

 begin

 begin

. .

w

wiitthh form1 PaintBox1form1 PaintBox1 ddoo

w wiitthh canvascanvas ddoo  begin  begin . . ::= = ;; br brusush h StStylyle e bsbsSoSolilidd . . ::= = ;; brush color brush color $ffffff$ffffff   (   fifillllrerect ct (rerect ct ((00,,00,,wiwidtdth h ,,heheigightht))));; ; ; end  end  end  end ;;

The paintbox has properties width, height

The paintbox has properties width, height andand

canvas. By not using with

canvas. By not using with

form1.paintbox1.canvas

form1.paintbox1.canvas but the separation but the separation

with form1.paintbox1 do with canvas do, we may

with form1.paintbox1 do with canvas do, we may

use both the canvas and the paintbox properties

use both the canvas and the paintbox properties

without the name prefixes. Canvas

without the name prefixes. Canvas propertyproperty

brush takes care of background coloring.

brush takes care of background coloring.

Style is a property of the brush. If we write

Style is a property of the brush. If we write

brush.style := bsClear the fillrect

brush.style := bsClear the fillrect does nothing,does nothing,

the brush is turned off. Fillrect( r ) paints

the brush is turned off. Fillrect( r ) paints

rectangle r of the paintbox in the color

rectangle r of the paintbox in the color

brush.color. r is of type Trect. Function rect

brush.color. r is of type Trect. Function rect

(defined inside Delphi) makes a

(defined inside Delphi) makes a Trect fromTrect from

coordinates.

coordinates.

See picture:

See picture:

We notice that the width occupies

We notice that the width occupies left ...left ...

right-1

right-1 and the height is from top to and the height is from top to

bottom

bottom-1. Width = right – left.-1. Width = right – left.

Height = bottom – top.

Height = bottom – top.

SETTINGS

SETTINGS

In the

In theTEditTEdit component componentYearEditYearEdit we enter we enter

the current year. Property

the current year. Propertymaxlengthmaxlength of of

YearEdit

YearEdit is set to 4. This prevents entering is set to 4. This prevents entering

more than four digits.

more than four digits.

The event YearEditKeyPress points to a

The event YearEditKeyPress points to a

procedure of this name. Reason is to allow only

procedure of this name. Reason is to allow only

the digits 0..9 together with backspace for

the digits 0..9 together with backspace for

 procedure

 procedure TForm1 TForm1 ..yeareditKeyeareditKeyPress yPress ((Sender Sender :: TObjectTObject;;

 var  var KeKey y : : ChCharar););  begin  begin ( ( [[ .... ,, ]]) ) ::= = ;; i iff nnoott kkeeyy iinn ''00'' ''99'' ##0088 tthheenn kkeeyy ##00 end  end ;; 8 is

8 is the ASCII code the ASCII code of of thethe ba backckspspacace kee key.y.

Prefix #

Prefix # denotes a following character code.denotes a following character code.

The data between

The data between […][…] is of the is of the SESETT datatype. datatype.

We want to start the search as well by pressing

We want to start the search as well by pressing

the return key after the current year.

the return key after the current year.

The return code is catched before it reaches the

The return code is catched before it reaches the

Tedit. This is done by setting the

Tedit. This is done by setting the TformTform property

property KeyPreviewKeyPreview to true and defining the to true and defining the

event FormKeyDown.

event FormKeyDown.

 procedure

 procedure TForm1 TForm1 ..FormKeyDoFormKeyDown wn ((Sender Sender :: TObjectTObject;;

 var

 var Key Key : : WorWord d ;;ShShift ift : : TShTShififtSttStateate));;  //<return> starts search

 //<return> starts search

 begin  begin = = i iff kekey y VKVK_R_RETETURURNN tthheenn  begin  begin := := ;; key key 00 ( ( );); searchBtnClick self searchBtnClick self ; ; end  end  end  end ;;  VK

 VK_R_RETETURURNN is a predifined  is a predifined Delphi constantDelphi constant

representing the return key.

representing the return key. NOTE:

NOTE:kekeyy now is of the type word, not char. now is of the type word, not char.

Procedure searchBtnClick

Procedure searchBtnClick is calledis called

with

with Form1 Form1 (self) (self) as as sendersender..

For more details please refer to the source code.

For more details please refer to the source code. FINALLY

FINALLY

With the help of this program the reader may

With the help of this program the reader may

solve the puzzle without doing the arithemetic

solve the puzzle without doing the arithemetic

himself. Now it becomes clear why Black is sure

himself. Now it becomes clear why Black is sure

today is White's birthday.

today is White's birthday.

Other, more difficult, questions would be birth

Other, more difficult, questions would be birth

years that have zero or multiple solutions.

years that have zero or multiple solutions.

This would

This would require some require some extensextensions of ions of thethe

program.

program.

Have fun! 

(11)

50 hands-on recipes to master the power of Delphi for

50 hands-on recipes to master the power of Delphi for

cross-platform and mobile development on Windows,

cross-platform and mobile development on Windows,

Mac OS X, Android, and iOS

Mac OS X, Android, and iOS

Daniele Teti

Daniele Teti

Quick answers to common problems

Quick answers to common problems

Delphi Cookbook

Delphi Cookbook

See our special offer:

See our special offer:

if you take out a subscription

if you take out a subscription

for two years the book

for two years the book

will cost you only € 10,00

will cost you only € 10,00

http://www.blaisepascal.eu/daniele_teti_book/DanieleTeti.html

http://www.blaisepascal.eu/daniele_teti_book/DanieleTeti.html

€ 39

€ 39

including

including

the

the

printed

printed

book,

book,

ebook

ebook

and shipping

and shipping

BL ISE

BL ISE

P SC L

P SC L

M G ZINE

M G ZINE

(12)

Issue Nr 6 2015

Issue Nr 6 2015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

12

12

BY BOIAN MITOV

BY BOIAN MITOV

In the previous articles

In the previous articles, you learned how to, you learned how to

program Arduino using Visuino, and ho

program Arduino using Visuino, and how tow to

communicate with it usin

communicate with it using USB simulated serialg USB simulated serial

port from your Delphi co

port from your Delphi code. This opens a lot ofde. This opens a lot of

interesting possibilities for collecting an

interesting possibilities for collecting andd

processing live data, but the direct USB

processing live data, but the direct USB

connection imposes some limitations. Wha

connection imposes some limitations. What if yout if you

want to collect data from many

want to collect data from many sensors spreadsensors spread

over large area? Or what if you want to

over large area? Or what if you want to

communicate with remote sensors over Internet?

communicate with remote sensors over Internet?

The basic Arduino UNO does not have built in

The basic Arduino UNO does not have built in

network adapter, but there is Ethernet shield

network adapter, but there is Ethernet shield

available for it. In addition many of the m

available for it. In addition many of the moreore

advanced Arduino boards and their clones co

advanced Arduino boards and their clones comeme

with WiFi or wired Ethernet built in.

with WiFi or wired Ethernet built in.

There are also cheap and simple ESP82

There are also cheap and simple ESP8266 WiFi66 WiFi

modules that can be connected to the Ardu

modules that can be connected to the Arduino, soino, so

networking Arduinos is routinely done.

networking Arduinos is routinely done.

In this article you will learn how to setu

In this article you will learn how to setup Arduinop Arduino

to use Ethernet Shield, how to pro

to use Ethernet Shield, how to program it withgram it with

Visuino, and how to connect to it fr

Visuino, and how to connect to it from a Delphiom a Delphi

application over the local network or Internet.

application over the local network or Internet.

Before you start, you will need to in

Before you start, you will need to install Ethernetstall Ethernet

Shield on the Arduin

Shield on the Arduino. This is fairly eao. This is fairly easysy. Just. Just

snap it on top of the board as shown in the

snap it on top of the board as shown in the

picture.

picture.

Add Ethernet Shield:

Add Ethernet Shield:

Next you need to specify the MAC address for

Next you need to specify the MAC address for

the shield. You can use a

the shield. You can use a MAC address generatorMAC address generator,,

 or one of the MAC addresses from the Arduino

 or one of the MAC addresses from the Arduino

tutorials. Here I use DE-AD-BE-EF-FE-ED:

tutorials. Here I use DE-AD-BE-EF-FE-ED:

You also will need to install CommunicationLab,

You also will need to install CommunicationLab,

PlotLab and InstrumentLab from Mitov

PlotLab and InstrumentLab from Mitov

Software. CommunicationLab is not officially

Software. CommunicationLab is not officially

released yet, but prerelease builds are available

released yet, but prerelease builds are available

on request. You can also easily modify the

on request. You can also easily modify the

examples in this article not to use PlotLab or

examples in this article not to use PlotLab or

InstrumentLab.

InstrumentLab.

First you will create a simple Arduino server.

First you will create a simple Arduino server.

Start Visuino. Click on the Down arrow button in

Start Visuino. Click on the Down arrow button in

the top right corner of the Arduino component,

the top right corner of the Arduino component,

and from the menu select “Add Shields...” :

(13)

13

13

Set the IP address for the Arduino

Set the IP address for the Arduino

as example 192.168.0.55:

as example 192.168.0.55:

And set the Enabled property of the IPAddress

And set the Enabled property of the IPAddress

to True so the IP address will be used when

to True so the IP address will be used when

Arduino starts:

Arduino starts:

Once the Ethernet Shield is configured, yo

Once the Ethernet Shield is configured, you canu can

add one or more TCP/IP Client, TCP/IP Server,

add one or more TCP/IP Client, TCP/IP Server,

or UDP sockets to it. Click on the “...” button

or UDP sockets to it. Click on the “...” button

after the Sockets to add a socket:

after the Sockets to add a socket:

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

Add TCP/IP Server socket:

Add TCP/IP Server socket:

Set the “UseDHCP” to false, so Arduino will

Set the “UseDHCP” to false, so Arduino will

work with a fixed IP address:

(14)

6

6 Issue Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

14

14

Set the Socket Port property to 8080:

Set the Socket Port property to 8080:

T

To generate some test o generate some test data from Arduino, data from Arduino, youyou

can use a Sine Generator as shown here, or

can use a Sine Generator as shown here, or

you can use any other source o

you can use any other source of Analog data,f Analog data,

or one of the Analog channels:

(15)

Issue Nr 6 2015

Issue Nr 6 2015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE 1515

Connect the data source to the Input Pin of the

Connect the data source to the Input Pin of the

Server Socket:

Server Socket:

Press F9 to generate the Arduino

Press F9 to generate the Arduino

Sketch and open the Arduino IDE:

(16)

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

16

16

Click on the Upload button to compile and

Click on the Upload button to compile and

upload the sketch:

upload the sketch:

The simplest way to see if the Arduino project is

The simplest way to see if the Arduino project is

working is to open a web browser and enter

working is to open a web browser and enter thethe

Arduino IP address, and socket number –

Arduino IP address, and socket number –

192.168.0

192.168.0.55:8080 . You should see the data.55:8080 . You should see the data

appearing in the bro

(17)

17

17

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE Next it’s time to receive the data in Delphi.

Next it’s time to receive the data in Delphi.

Start RAD Studio, create a VCL Form project,

Start RAD Studio, create a VCL Form project,

and drop a TCLClientSocket from

and drop a TCLClientSocket from

CommunicationLab on the form:

CommunicationLab on the form:

Set the IP Address to the same used in the

Set the IP Address to the same used in the

Visuino project 192.168.0.55:

(18)

18

18 Issue Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE Switch to the “

Switch to the “OpenWireOpenWire” tab, and connect the” tab, and connect the

Output Pin of the Socket to the Input Pin of the

Output Pin of the Socket to the Input Pin of the

Terminal:

Terminal:

Compile and run the application. You will see

Compile and run the application. You will see

the data arriving in the terminal:

the data arriving in the terminal:

Drop TCLTerminal on the form:

(19)

19

19

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE If you need to access the data in your code,

If you need to access the data in your code,

the Socket component has OnReceive event:

the Socket component has OnReceive event:

Now you can receive data from Ardu

Now you can receive data from Arduino over theino over the

network, however the data ar

network, however the data arrives from a singlerives from a single

sensor, and in text form. This makes it difficult

sensor, and in text form. This makes it difficult

to work with, and limits the data cha

to work with, and limits the data channels thatnnels that

we can get.

we can get.

As shown in the previous article, Visuino

As shown in the previous article, Visuino andand

CommunicationLa

CommunicationLab have support for packetb have support for packet

data. You can use it with sockets the same way

data. You can use it with sockets the same way

you did with the serial port.

you did with the serial port.

Start a new Visuino project, add and con

Start a new Visuino project, add and configurefigure

the shield and the socket as you did in the

the shield and the socket as you did in the

previous project.

(20)

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

20

20

Connect the Output Pin of the Packet component

Connect the Output Pin of the Packet component

to the Input Pin of the Socket:

to the Input Pin of the Socket:

Double click on the packet component to open

Double click on the packet component to open

the elements editor. In the editor add 2 Analog

the elements editor. In the editor add 2 Analog

and 2 Digital elements:

and 2 Digital elements:

Next, add a Packet component:

(21)

21

21

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE Connect the Input Pins of the An

Connect the Input Pins of the Analog Channelsalog Channels

to the Output Pins of “Analog Input Channel[ 0

to the Output Pins of “Analog Input Channel[ 0

]” and “Analog Input Channel[ 1 ]”, and the

]” and “Analog Input Channel[ 1 ]”, and the

Input Pins of the Digital Channels to t

Input Pins of the Digital Channels to the Outputhe Output

Pins of Digital Channel 0 and 1 of th

Pins of Digital Channel 0 and 1 of the Arduinoe Arduino

Board component:

Board component:

Expand the HeadMarker and for the Bytes click

Expand the HeadMarker and for the Bytes click

on the “...” button:

(22)

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE

22

22

In the Bytes editor enter 55 55, then click OK:

In the Bytes editor enter 55 55, then click OK:

This will enure that the packet has unique

This will enure that the packet has unique

header and its starting point can be identified in

header and its starting point can be identified in

the data stream. Visuino uses special algorit

the data stream. Visuino uses special algorithmhm

to ensure that the header mar

to ensure that the header marker will not appearker will not appear

in the packet itself.

in the packet itself.

Press F9 to generate, then compile and uplo

Press F9 to generate, then compile and uploadad

the sketch in the Arduino IDE as you did in the

the sketch in the Arduino IDE as you did in the

previous project.

previous project.

Now that the Ar

Now that the Arduino is ready, lets switch toduino is ready, lets switch to

Delphi.

Delphi.

Start a new VCL Form project, add the

Start a new VCL Form project, add the

TCLClientSocket, and set the IP

TCLClientSocket, and set the IP Address and PortAddress and Port

as in the previous project:

(23)

23

23

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE Next add a TCLUnpacket, TSLScope,

Next add a TCLUnpacket, TSLScope,

TILAngularGauge and 2 TILLed components:

TILAngularGauge and 2 TILLed components:

Switch to the OpenWire tab, and double click on

Switch to the OpenWire tab, and double click on thethe

CLUnpacket1:

(24)

24

24

Add 2 Float and 2 Boolean channels:

Add 2 Float and 2 Boolean channels:

Expand the HeaderMarker and for the bytes click

Expand the HeaderMarker and for the bytes click

on the

on the “...” (called ellipsis)“...” (called ellipsis)

Issue

(25)

25

25

Issue

Issue Nr Nr 6 6 20152015 BLAISE PASCAL MAGAZINEBLAISE PASCAL MAGAZINE In the Bytes editor enter 55 55, then click OK:

In the Bytes editor enter 55 55, then click OK:

Connect the components as shown in the picture:

References

Related documents

In this Delphi survey, 30 physical therapists reached consensus on the majority of items relating to the def- inition and application of Pilates exercise in people with CLBP

In particular, we aim at finding out how many indexes HAIL can create for a given dataset in the same time standard Hadoop needs to upload the same dataset with the default

Tax issues are also considerations, as inter vivos (during life) transfers of property can result in substantial capital gains taxes. At the same time, nursing home residents,

Unlike the traditional model, the Acumera AirGap Architecture does not create a linear, persistent connection between in-store devices and third parties, keeping the store network

Home health care $100 co-pay/day 50% co-insurance Coverage is limited to 28 hours per week Rehabilitation services $60 co-pay/visit 50% co-insurance Coverage is limited to

[r]

If you choose a colocation package and you need to get access to your servers, ask your potential data centre host about what access you have to your equipment?. Is it

Email filtering is a process of monitoring incoming email and then taking the appropriate action to protect against Spam and viruses. Certain criteria are set to determine if an