BlaisePascalMagazine 53 UK

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

D E L P H I, L A Z A R U S, O X Y G E N E, S M A R T M O B I L E,

A N D P A S C AL R E L A T E D L A N G U A G E S
A N D R O I D, I O S, M A C, W I N D O W S & L I N U X

BLAISE PASCAL MAGAZINE 53

INTERVIEW WITH ATANAS POPOV


CEO OF EMBARCADEO ABOUT DELPHI AND ITS FUTURE
BY DETLEF OVERBEEK / PHOTOGRPHY RIK SMIT

ARTIFICIAL INTELLIGENCE
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
BOIAN MITOV

HOW TO BUILD AN APP IN XML AND


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR WITH CODE AND WORKING APK
BY DETLEF OVERBEEK

PRINTED ISSUE PRICE 15,00


DOWNLOAD ISSUE PRICE 5,00
BLAISE PASCAL MAGAZINE 53
D E L P H I, L A Z A R U S, S M A R T M O B I L E S T U D I O,
A N D P A S C A L R E L A T E D L A N G U A G E S
F O R A N D R O I D, I O S, M A C, W I N D O W S & L I N U X

CONTENTS
INTERVIEW WITH ATANAS POPOV
CEO OF EMBARCADEO ABOUT DELPHI AND ITS FUTURE PAGE 5
BY DETLEF OVERBEEK, PHOTGRAPHY BY RIK SMIT

WHO!? ME!?
HUMOR BY KIM MADSEN PAGE 14

ARTIFICIAL INTELLIGENCE PAGE 18


CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
BOIAN MITOV

HOW TO BUILD AN APP IN XML AND


CREATE AN ANDROID PACKAGE PAGE 29
INCLUDING HOW TO USE THE EMULATOR WITH CODE AND WORKING APK
BY DETLEF OVERBEEK

Advertisers
Barnsten Page 15
Blaise Pascal Magazine
special offer book + usb librabry Page 13
Components 4 Developers Page 40
Free Pascal an Lazarus Foundation Page 16 Publisher: Foundation for Supporting the Pascal Programming Language
MITOV SOFTWARE Page 20 in collaboration with the Dutch Pascal User Group (Pascal Gebruikers Groep)
Stichting Ondersteuning Programmeertaal Pascal

2 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


Stephen Ball Peter Bijlsma -Editor Dmitry Boyarintsev
http://delphiaball.co.uk peter @ blaisepascal.eu dmitry.living @ gmail.com
@DelphiABall

Michal Van Canneyt, Marco Cant David Dirkse


michael @ freepascal.org www.marcocantu.com www.davdata.nl
marco.cantu @ gmail.com E-mail: David @ davdata.nl

Benno Evers Bruno Fierens Primo Gabrijeli


b.evers www.tmssoftware.com www.primoz @ gabrijelcic.org
@ everscustomtechnology.nl bruno.fierens @ tmssoftware.com

Fikret Hasovic Cary Jensen Peter Johnson


fhasovic @ yahoo.com www.jensendatasystems.com http://delphidabbler.com
http://caryjensen.blogspot.nl [email protected]

Max Kleiner
www.softwareschule.ch
max @ kleiner.com

John Kuiper Wagner R. Landgraf KimMadsen


Kim Madsen
john_kuiper @ kpnmail.nl wagner @ tmssoftware.com www.component4developers
kbm @ components4developers.com

Andrea Magni Boian Mitov Jeremy North


www.andreamagni.eu mitov @ mitov.com
andrea.magni @ gmail.com
jeremy.north @ gmail.com
www.andreamagni.eu/wp
Detlef Overbeek - Editor in Chief Howard Page Clark Heiko Rompel
www.blaisepascal.eu hdpc @ talktalk.net [email protected]
editor @ blaisepascal.eu

Wim Van Ingen Schenau -Editor Peter van der Sman Rik Smit
wisone @ xs4all.nl sman @ prisman.nl rik @ blaisepascal.eu
www.romplesoft.de

Bob Swart B.J. Rao Daniele Teti


www.eBob42.com [email protected] www.danieleteti.it
Bob @ eBob42.com d.teti @ bittime.it

Anton Vogelaar Siegfried Zuhr


ajv @ vogelaar-electronics.com siegfried @ zuhr.nl

Editor - in - chief
Detlef D. Overbeek, Netherlands Tel.: +31 (0)30 890.66.44 / Mobile: +31 (0)6 21.23.62.68
News and Press Releases email only to [email protected]

Editors
Peter Bijlsma, W. (Wim) van Ingen Schenau, Rik Smit,
Correctors
Howard Page-Clark, James D. Duff
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 80.-- Incl. VAT 6 % (including code, programs and printed magazine,
10 issues per year excluding postage).
2: Electronic - non printed subscription 50.-- Incl. VAT 21% (including code, programs and download magazine)

Subscriptions can be taken out online at www.blaisepascal.eu or by written order, or by sending an email to [email protected]
Subscriptions can start at any date. All issues published in the calendar year of the subscription will be sent as well.
Subscriptions run 365 days. Subscriptions will not be prolonged without notice. Receipt of payment will be sent by email.
Subscriptions can be paid by sending the payment to:
ABN AMRO Bank Account no. 44 19 60 863 or by credit card: Paypal
Name: Pro Pascal Foundation-Foundation for Supporting the Pascal Programming Language (Stichting Ondersteuning Programeertaal Pascal)
IBAN: NL82 ABNA 0441960863 BIC ABNANL2A VAT no.: 81 42 54 147 (Stichting Programmeertaal Pascal)
Subscription department Edelstenenbaan 21 / 3402 XA IJsselstein, The Netherlands / Tel.: + 31 (0) 30 890.66.44 / Mobile: + 31 (0) 6 21.23.62.68
[email protected]

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.

Issue Nr 4 2016 BLAISE PASCAL MAGAZINE 3


From the editor
A
few weeks ago there was some agitation so There is an announcement in this issue (page 16)
I thought I might be a good idea to have a and we hope that you will support them as good as
conversation with Embarcaderos new you can...Probably we will be able to show some
CEO Atanas Popov. great news about component handling on the next
I was able to make an appointment with him on one Pascon (page 17) Delphi Festival.
of the traveling moments and appointments he
had. The closest was Frankfurt and so we (my The next Pascon Delphi Festival will be arranged
colleague Rik Smit and me) drove there - drove in the Netherlands and it will also be English
because flying would even take more time - and in spoken.
this way we could do it in one day. We have a lot of news on that event.
We had a conversation and an interview about One very special thing is that BPM readers will
all that I thought was important for the community have a price reduction of 45 euros - so the event
and Embarcaderos future. Voices came up that will cost you only 54 euros.(Normal price is 99 ).
Delphi was going to be sold and the whole Anthony Vogelaar will be there showing his
company was to be taken over by another party. newest product: a complete version of the
Microsoft Flight Simulator and the console to
None of that proved to be true - happily. handle the flight is built in Delphi. The simulator is
also built for training and education of Pilots.
But it was also a good opportunity to learn
something about the real plans of Embarcadero and For our Brazilian readers we have a special action
the future of Delphi. that they can find at our website, so they will be
I must say Atanas was from the beginning able to take out a subscription at a special Brazilian
talkative and very open. It took all together three price and use the special offer we have for them.
hours before we were finished. That is the reason https://is.gd/4qGc38
the interview takes eight pages. We wanted to be as
complete about the views as possible. I think we I want to introduce our Google+ page for Blaise
we've been successful in that matter and I hope that Pascal Magazine: https://is.gd/bbUxQt.
you find this interview as interesting as we do. We Its an open community. You can comment here on
think the importance of this is very high and that is the new articles, old articles or ask questions , ask
why we changed the content of this issue. The for special articles, code books and things...just let
regular articles will of course be in the next issue... us know...The reactions we will publish also in our
magazine. We also will create a blog for the
And now for something completely different: Magazine.
good things are going to happen.
First of all we (as the editorial foundation) have So for now: happy readings...!
created the Delphi Pascal Academy. This institute
is going to be registered as official educational Detlef
school for Delphi and Pascal. If you become a office(at)blaisepascal.eu
member of this you will gain many advantages:
As a person you now can purchase Delphi for
academic prices and some things will probably
even for free.
You also will have access to code (such as
components), special books and articles for a lower
price.
We will describe all of that in the next issue.

On the Lazarus and FPC side there is some


great news as well: there is a new foundation that
will collect money for special purposes for that
open source group. Free Pascal and Lazarus
Foundation https://is.gd/BJG4dY.
The funds that will be raised will be used to pay
developers for special projects that will help to
create important new improvements to the
language, develop new ideas and create
components that we all are waiting for.
INTERVIEW WITH ATANAS POPOV, PAGE 1/8
CEO OF EMBARCADERO. BY DETLEF OVERBEEK / PHOTOS RIK SMIT
Atanas Popov agreed after being asked
A.
immediately to be interviewed. That was about two
months ago. About two weeks ago there was quite a
It's a very nice book to support early learning.
lot of turbulence in the community and vendors D.
went nervous, some people even saw some kind of Thank you. I was wondering about the future of
armageddon for Delphi. Even the more reason to Embarcadero, what are you planning to do? Are you
talk the new Chief, ask him al the questions about planning to run Delphi for a very long time or are you
their new policy, what is going to happen to and with trying to do something else?
Delphi. An explanation sometimes even in detail A.
follows here... A lot of people asked that question when IDERA
acquired Embarcadero.
We met in Frankfurt at the Airport and talked Part of the business was Database related, and
for about three ours.
the logical question was if we would sell the
Exhausting though very refreshing.
developer tools business.
The sensitivity around this was heightened from
the history of Borland and CodeGear.
We explained that one obvious reason for buying
Embarcadero was indeed the nice synergies with
the database business, but we also see an
opportunity to evolve the developer tools
business as a platform in itself.
Similar to IDERA, but focused on developers.
Embarcadero is our Developer Tools business
and we plan to grow it as such.
D.
Does IDERA have its own development tools as well?
A.
IDERA has two businesses, the IDERA brand
serves the complete database lifecycle
Atanas: (A.)
management needs of customers,
Being a developer is a serious commitment.
and Embarcadero serves the development tools
I think that great developers have to develop all
needs of customers.
the time.
D.
Detlef: (D.)
But will there be a possible connection from Inside
Well I couldn't do the magazine without developing,
Delphi towards IDERA databases especially?
I still do it for a hobby but I am not a developer.
Like Delphi has a connection for Oracle and things
A. like that?
I am also not patient enough to be a developer. A.
D.
IDERA develops tools for database management.
You really need to spend a lot of time as a developer,
IDERA doesn't develop databases.
and I don't have time for that.
D.
I made a list of questions. You can say yourself of
You do database mining and things like that?
course if you want to answer to them or not
A.
A.
More like optimization of how SQL runs, how
Sure. By the wayI have a present for you, our
Oracle runs, making sure that databases run
new Starter Book for Delphi.
properly.
D.
I have seen that, Thank you very much!

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 5


INTERVIEW WITH ATANAS POPOV, PAGE 2/8
D.
So if I understand correctly, with IDERA I could
manage Microsoft SQL?
A.
Microsoft SQL Databases.
D.
So there is not a real connection to Embarcadero?
A.
That's the Idea. Thats what it does yes.
D.
So there is not a real connection?
A.
There is the connection that both provide
excellent technology tools..
D. A.
Yes of course, but what if those tools are written in It depends.
C or C++? The market in Europe for IT Tools is growing.
A. D.
I don't know the languages used to develop the Well, we could say America is growing towards
IDERA tools. Europe and the other way around.
I'm sure it's a mixture of toolchains, there are web A.
interfaces and many other components. There are many cool tools developed in Europe.
They are not written in Delphi for sure. We just acquired a company in Germany called
I do know that a lot of database tools are written in Gurock. Gurock was founded by two Brothers in
Delphi. It lends itself very nicely for that, Berlin. First they developed a tool in Delphi called
but IDERA tools are quite new and probably SmartInspect.
leverage other technologies. It was not growing that fast and they decided to
D. develop another tool called TestRail.
So that's why you made the division between That tool today is extremely successful and is
Embarcadero and Idera? used by thousands of companies.
A. The interesting point is that they are based in
The separation was planned from the beginning. Berlin and a lot of their customers are based
The idea was that Embarcadero will focus on the in the US.
development tools business with Delphi and It is not a developer language tool,
C++Builder at its core and then continue to evolve but it is a development tool because it's focused
them, but also try to find other products that fit on testing.
with the core. We will grow this business and The guys are very well known in the Delphi
make it successful on its own. world.
D. They published Delphi feeds.
If I may ask that question, we in Europe are not used to D.
or hardly can believe that one can lend money for That's interesting
buying Programming tools etc. because banks in A.
Europe or in Germany or in Holland would never give Their very smart developers and have done an
money for it. amazing job with the resources they have
A. I think today Europe contributes a fair share of IT
We buy companies all the time with money from development. So it's a good place to invest.
banks and investors. I think European banks are
no different, but probably have a little less
experience in this space.
D.
They do? Are you sure?
A.
Not on the same scale, but yes.
D.
That's funny. We had a discussion about that and I
said that this would never happen in Europe because
of the trauma we have from 2008.

6 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


INTERVIEW WITH ATANAS POPOV, PAGE 3/8
D. with Delphi and their companies can pay for the
So we went away from my first question tools or students that will get access through our
A. academic program.
I see your first question is related to incentivizing D.
young people to use Delphi, making it easily That's not really true.
accessible. A.
Obviously we are not Microsoft and we cannot Possible, but that is our perception of the market
give away our tools to everybody for free. today and that is why we have not focused so
However, we have committed that we will much on the Delphi Starter edition.
support academic licenses for Delphi for a very On the C++ side where we have many developers
limited cost or free. and we have lost a lot of our initial penetration,
We have two immediate growth opportunities, to there is a larger opportunity to reintroduce C++
leverage the power of our existing community Builder and we want to be more aggressive
and to increase our base of young users. immediately. We want again to be recognized as a
We can be successful with young developers. major player, if not the leader in C++
There are selected countries where we have very development, which we used to be ten years ago.
high penetration of Delphi D.
We have similar ideas for Delphi, There is a difference
in education. For example,
to promote a free Starter edition between C++ from
in South Africa every high
in September. Microsoft and from Delphi.
school uses Delphi. Similar
efforts are underway in A.
Australia. This creates a nice foundation for more There is a difference in the
businesses to use Delphi in the future way C++ Builder treats the language because a lot
D. of our components are Delphi based.
I have some news about us, So when you are a C++ developer and you
in the coming weeks we will expand in Brazil and make develop in C++ Builder you get exposed to some
the magazine available there at a very low price. Delphi code. You don't need to know it, but it may
A. irritate C++ purists.
Very good. D.
D. That's not what I mean. What I mean is we have a
And then there is another opportunity with Delphi. project we have to translate a C++ DLL (Microsoft
We want to form a Delphi Academy as a club and the DLL), but we could not merge that to Delphi C++.
members of this club can buy the academic version. A.
A. Again, there may be some differences because
I don't see a problem sometimes we leverage Delphi components,
D. especially with the visualization frameworks.
Are you planning new prices? D.
A. Are there any limitations with the Starter editions?
Specially or in general? A.
D. Yes, the idea is to introduce new users to the
What I am referring to is the free C++ promotion from frameworks, but there are limitations that do not
a few weeks week ago. allow business use.
A. The version also lacks mobile development and
We do not plan significant pricing changes. some database connectivity capabilities.
However, we do want to make the Starter editions However, it is still an excellent product, and a
more accessible to grow new users. great way to get people excited about using
We liked the results from our C++ experiment and Embarcadero products for C++ development.
will repeat it this summer. D.
We have similar ideas for Delphi, to promote a Especially in the US or in Europe as well?
free Starter edition in September. A.
D. Anywhere. We have large groups of C++ users
Or at least a very cheap one in Germany, US, and Japan, but in other markets
A. as well.
I think that the demand for a free Delphi Starter D.
version may not be so high because there are I think it's far bigger then Delphi is, isn't it?
fewer independent young developers. We have
either people that have worked for a long time

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 7


INTERVIEW WITH ATANAS POPOV, PAGE 4/8
A.
Yes. C++ continues to be number 3 according to
TIOBE after Java and C, and more popular the
C#. Delphi is 12th moving up from 13th last year.
D.
It was 18th a few years ago!
A.
Could be, I think that there has been some
success in increasing its popularity. I think our
approach to bring Delphi into education should
help more.
D.
Universities?
A.
Yes, education will be a major play.
We will also promote it in a more open fashion, standard for high school programming education
integrated with other languages and toolchains. there, made a great point to that effect.
Instead of the thinking, you're a Delphi He doesn't think that Delphi is better than Java or
developer vs. another developers, we should that there is no place for Java. He was very
think that Delphi is the best language for some passionate, but also an objective educator. He felt
type of development vs. others. that Delphi is a great language to start with
For example, Delphi today is not ideal for Web because of its structure, but then students can go
Development. to Java and other languages. Most developers
However, making a Delphi self-contained app or need to know two, three or more anyway. Delphi
a back-end that works with HTML or JS client, and Object Pascal were pushed aside in US for a
could be a great solution, especially if you are variety of reasons, not sure all objective. The US
looking for speed. is a technological leader and it has affected other
I think the notion that we will make Delphi the markets, of course we think this is unfair.
most important language in the world is not (Laughing)
viable. However, it should be recognized as a D.
very useful and powerful language. That's how it works
D. A.
Well we always say it's the only language except C, Even in the US things may change for early
that is handling multiple OS. education. There is not a lot of effective early
A. education in computer sciences. A lot of the
Yes, there are a lot of benefits, but I think that the education is very practical, it was directed
mindset could be more open. towards web development, because it was very
When you think Delphi is a tool that is very good visual, so kids may learn some HTML and
for certain things and the other languages are immediately see the results in the browser, but
good for other things that opens a better dialogue that is not true programming. This approach
and encourages more developers who may know misses some of the logical aspects of
Object Pascal, to try Delphi again. development that are especially important early
It should not feel like a religion in the way Delphi on. With mobile, things are likely to change and
sometimes does. we have an opportunity.
D. D.
I tend to agree with you, but there is one big What is your opinion about open source?
differentiator, Delphi is very easy to learn. My point A.
always is, in the future we will have a tremendous We are a commercial organization and we want
need of developers. They do not all need to be Einstein. to make money, which makes us skeptical about
Because Delphi is structured and easy to learn, it can open source. Most organizations that have tried
be a very good thing for us in the future and if you to create a business model from open source have
have done Delphi it is easier to learn C#, C and C++. had challenges. Some try to monetize consulting
The other way around, not so much. and support. I have not done as much research in
A. this space historically, but we have explored
Easy to learn is an important advantage. certain trends. BTW I love Google Trends as a
For example, our MVP in South Africa, who was gage for interest. (next page)
instrumental in making Delphi the learning

8 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


INTERVIEW WITH ATANAS POPOV, PAGE 5/8
A. A.
For example, it clearly illustrates how C++ IDERA has a different way of development,
Builder was dominating the market and how it but one that is proven to produce good results.
faded over time. Another example is JBuilder, We rely on our Development Partner Network.
Borland's most significant product. It shows very We put a layer of management and process that
rapid decline. Anyhow, the point is that if you are unique and differentiating to ensure that we
look at major Open Source projects in our space, deliver very good product. We love our R&D
such as Eclipse and Firebird, they are also model and think that it will be successful for
gradually declining, so there are clearly Embarcadero.
problems. I will not comment on internal restructuring
In my opinion, a lot of these older open source the bottom line is that we are committed to our
projects have lost steam. It is easy to be 25 years products and our product Roadmap.
old and say, I am passionate about this thing, and We are excited for the future of our products and
I am going to spend a lot time developing the believe that our customers should be excited as
software. I have lots of energy. Maybe initially, well.
because it's popular, I start making money on the D.
side from consulting and development. But when The main thing is you know of what has happened in
some of the momentum is lost and priorities the past. CodeGear. People get lost.
change, then the economics change, which may That's why people can get hysteric.
explain why some of these projects decline. A.
D. I think one of the reassuring factors that
How do you see developing for Linux? customers should know is that we care a lot
Is that an issue for you? about our products. It comes straight from our
A. CEO, Randy Jacops. People may think that he
Linux is a different story. cares a lot less about development because he has
It has enough resources. many other things to worry about, but frankly
It's very much alive.... most of the discussions I have with him are
D. around products, not around financials.
But can you as a company make money on According to Randy, if we are not successful with
the Linux side? product, we are not going to be successful. I hope
A. that customers appreciate such product
We are committed making RAD Studio work on commitment.
Linux on the server side. D.
Supporting new platforms typically results in What is your future goal for Delphi?
growth for our customer base. A.
Many customers anticipate Linux and will buy Make it successful.
more licenses for that. D.
D. But in what way?
There will be no client in the future? What do you have in mind for the future?
A. A.
There is no plan for client support. There are Growth. Financial growth equates to a good
some markets that may demand it, such as product, people use more, we sell more
Russia and China, but the economics so far
do not work.
D
So we can skip that subject for the coming years?
A.
We will gladly consider it, if there is a market
demand for it. We want to deploy our resources
in places where customers can benefit.
At the end of the day the only way we are
successful is if our customers find value and
purchase our products.
D.
What's your strategy now?
You skipped the Spanish branch story?

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 9


INTERVIEW WITH ATANAS POPOV, PAGE 6/8
D. it made us think.
But how do you do that? How do you successfully position FMX in such
A. environment? It does have some very powerful
First, we need to reassure the market that we will capabilities that differentiate it from anything
continue to invest and build Delphi. else in the market.
Second is to make Delphi more popular. One of the things we are doing a little different
More people should know about the specific from before is that we want to promote a lot of
things you can do with Delphi and you cannot do our component vendors like TMS, Woll2Woll,
so well with other tools. and others, as great showcases for use of FMX.
We need to continue to deliver strong releases and It is surprising to see some of the nice FMX case
improve in the areas where we know we need to studies out there.
be improve. We already discussed some of our I hope that we learn from these experiences and
efforts to increase popularity of our products. develop a winning strategy for FMX.
D. D.
Is it possible that FMX might be dropped in the future Last year, there were big questions that Embarcadero
and that you go to native operations with Android and would try to put all components into one marketplace.
Mac? A.
A. FMX is an area where we have We still like the idea of
FMX is an area where we have not developed our complete having a marketplace
not developed our complete strategy. D.
There are many opportunities.
strategy. There are many But it's open...?
We have seen excellent progress
opportunities, and we have over the last few versions.
A.
seen excellent progress over Its open. Yes.
the last few versions. D.
D. At that time they said we want to do it all...
May I say something about that? A.
Most developers say something like this, There was some logic behind that idea and it was
FMX is a very nice tool in itself and very useable for aimed to help customers.
games and things like that. However, now we think that actively promoting
But there is a very large problem built into the FMX component partners, but keeping an open and
technology itself and it appears to be very hard to solve independent ecosystem is better.
you do not have full native controls. There is no way a company of our size can do it
Most people say it would be better to have as a separate all. The old strategy discourages external
part that is done native for Android as well as the Mac. development and innovation, and we do not like
A. that..
Again, this is an area that we are investigating. D.
FMX has some wonderful capabilities when That sounded like a very bad policy.
compared to other platforms, such as Xamarin, I agree that you should do it together.
but there is a lot more to do to increase true native A.
capabilities. After Microsoft acquired Xamerin Yes. We have a community with very talented
and made it virtually free for many developers, people. They have their own ways to develop.
I don't think that they would necessarily fit nicely
in a big company. You mentioned, Boian Mitov,
he is a great example of an awesome developer
with amazing productivity, but also his own ways
of doing things.
There are many others like him.
We want them to be very successful, because this
will make our mutual customers successful.
However, if they all worked for Embarcadero,
I am not sure that we would have the same
results.
D.
I think your idea of having an open market is better.
Far better.
What is your idea about the open community like FPC
and Lazarus?

10 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


INTERVIEW WITH ATANAS POPOV, PAGE 7/8
A. D.
Communities in general are important. People are very much asking for Linux. It's obvious
To have these associated with our products can be A.
beneficial. We will do big things, but also a lot of smaller
I do not see a problem with Lazarus, but as updates throughout the year.
discussed before, open source platforms have D.
resource challenges It is difficult to see Lazarus So what does a subscription mean in that case?
as an alternative to Delphi for everything. A.
D. That's the reason a subscription make so much
For some things it is possiblethe more you advance sensible. Customers need to be on subscription
the cause of the language should be good. I just have to get all the updates.
the feeling that some things would be better, open They get continuous value. Most large software
sourced. companies have moved to that model.
A. Our customers are embracing it as well
In some ways that is naive. If you're on the right D.
path of popularity in open source, you may gain a Why is Linux important?
lot by riding the wave attracting new people, A.
growing. You do not have that momentum with Linux will make the product more connected,
Pascal. To think that by making it open source, more open, more flexible, more efficient for
you will gain momentum is not realistic - I think. deployment.
D. D.
I don't think so as well. How do you see the server site only
A. component.or will it just
One of the reasons that Delphi Linux will make the product be coding?
still exists is that we make more connected, more open, A.
money and are able to more flexible, more efficient We will compile the code
investment and promote it. for deployment. to Linux, supporting bug
D. fixes, and many other
Speaking about the Berlin version, capabilities. So you will have a server and that
what will the next one be? Will it be Japan? will run on Linux. Very similar to running the
A. back-end on Windows.
We like Japan, Japan is one of our biggest markets. D.
The name sort of honors that. Speaking about Microsoft, isn't it how they built
D. their own market - they gave the software for free and
Is It? once you're hooked they ask for money?
A. A.
We are still deciding on the exact name. Microsoft has a large and complex product
We are committed to our roadmap and will portfolio. They are able to leverage one product
provide an update shortly. for the benefit of another, dependent on their
As discussed, there will be an update after Berlin, strategy.
possibly another one, and then will be Godzilla We are a very different company.
with Linux. We partner with Microsoft in many areas to help
The focus after that will continue to be on quality our customer work well with their platforms.
and evolving the underlining frameworks and Their success with Windows 10 has been very
language support. good for us. It created a lot of incentive for
D. people to get on our latest version.
So you will do these periodical D.
updates and do the release when I spoke to Boian Mitov about the FPC team, about
it is possible to do it. things like the RTTI, of which he is proud for having
A. built extra logic, etc. He wants them to be as close as
Yes. Generally, we want to do one release a year. possible at least to Delphi. I mean Delphi is going
Everybody is asking when we will move there. its own way, they have their own way, but they still
This year we will do the two. want to follow as much as possible Delphi. Do you
We have learned a lot from the Berlin release. mind that?
It is a nice achievement to do it right after the A.
acquisition. Not at all

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 11


INTERVIEW WITH ATANAS POPOV, PAGE 8/8
D. A.
Would you help them doing that? If Microsoft comes tomorrow and says we would
A. buy Delphi for a lot of money, we would
We do need to understand the details. I just do absolutely consider it, any business person
not know enough to comment. should (Laughing). In a business environment to
We are happy to support open source initiatives say that you would never sell Delphi is not a
where it makes sense, we are even discussing serious statement. But, do we have plans to sell
internally a few ideas around CodeWrite and Delphi? No! We bought Embarcadero with a long
JBuilder. We are happy to try and test different term commitment and plan to continue to invest
things. in the company.
D. D.
How will you sustain something in Delphi like the Thank you for giving answer to all these questions
bugs and the bug-reports or how can they be handled?
Because I think you miss a lot of people now.
A.
We have plenty of people, so resources is not
something that I worry about.
JETBRAINS
I do worry about quality, but that is a constant JetBrains (formerly IntelliJ) is a
worry, and should be for anybody that deals software development company whose
with a product. tools are
D. targeted towards software developers
and project managers.
W A
IKIPEDI
There is a special group for bug reports and things As of 2015, the company has over 500 employees in
like that? its five offices: in Prague, Saint Petersburg, Moscow,
A. Munich, and Boston.
Absolutely. We have a very sophisticated R&D The company offers an extended family of integrated
development environments (IDEs) for the
organization and teams dedicated to all programming languages Java, Ruby, Python, PHP,
functions. The bug reports or quality is a major SQL, Objective-C, C++, and JavaScript.
focus area, as we have communicated on In 2011 the company entered a new area by
introducing Kotlin, a programming language that
numerous occasions.
runs in a Java virtual machine (JVM).
Customers can read about this on our blog and
product roadmaps. XAMARIN
D. Xamarin is a Microsoft-owned San Francisco,
California based software company founded in May
What is your policy towards resellers, such as
2011 by the engineers that created Mono, Mono for
Barnsten? They have been doing reselling for a long Android and MonoTouch that are cross-platform
time. There is the rumor that you are going to sell implementations of the Common Language
straight on the internet. Infrastructure (CLI) and Common Language
Specifications (often called Microsoft .NET).
A.
With a C#-shared codebase, developers can use
We already sell on the internet. Xamarin tools to write native Android, iOS, and
We are very committed to and proud of our Windows apps with native user interfaces and share
partners, and Barnsten is one that would testify code across multiple platforms.
for that. CODEWRITE
D. CodeWright is a Windows Programmers Editing
So you can buy straight from the company's System for software developers originally marketed
webstore? by Premia Corp. (Beaverton, Oregon) and developed
by Premia co-founders Eric Johnson and Don Kinzer,
A. initially released in 1991. Premia was acquired in
Correct, in many markets, our partners have April 2000 by Starbase Corp. which was itself
their own webstores too. In general, we love the acquired in January 2003 by Borland.
partnership model and are very flexible.
After the acquisition, we expanded the partner
model to more markets, such as Australia and
India.
D.
So in closing, we must stress that you never had a
thought of selling Delphi?

12 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


SPECIAL OFFER:
FOR AUGUST AND SEPTEMBER 2016

RKS E GET THE BOOK INCLUDING

D D I tml THE FAMOUS LIBRARY STICK


I
es.h
_Gam

V
DAVID DIRKSE COMPUTER MATH & GAMES IN PASCAL

ath
FOR 75 EUROS + SHIPPING
D A ales
at
pres laisepas
cal.e
u/Da
vidD
irkse
/Compu
terM

INCLUDING:
w w .b
w
53 projects and code fully explained.
HOWARD PAGE-CLARK

The Delphi 3 Delphi Berlin source code


is available together with full explanation.
Most of the projects can be done with
FPC and or Lazarus as well.
For a preview go to:
http://www.blaisepascal.eu/
david_dirkse/
UK_Book_Department_DavData.html
; PDF file - excellent readable on your
dure
proce
var tablet. Printable.
9 do
begin := 1 to
for i
b e g i n

end;
end;

L I B R A R Y 2 0 1 6

TH & 3 4
MA 1 2 5

UTER PASCAL
6 10 12
7 8 9
M P 11
CO S IN
13
14 15 16 17
18 19

ME 20 25 26
27
GA 28
21
22 23 24
33
34 35 36
29 30 31 32
40 41 42
37 38 43
39 45+ 47 48 49
POCKET EDITION 44 46
50
Also printed in full color. 51
A fully indexed PDF file is included.
Resize, rotate, compress digital images.
Design your own font, generate and reduce Truth
Tables from Boolean algebra.
And more important: understand how it all works!
The book contains 87 chapters, 53 projects with
source code and compiled programs (exe).
The book is highly educational and suitable for
beginners as well as for professionals. WINDOWS 10

Play board games, solve puzzles, operate a


BLAISE PASCAL MAGAZINE
vintage mechanical calculator, Produce 3- AUTHORS ALFABETICAL ALL ISSUES IN ONE FILE
dimensional computer art, generate lists of prime
numbers, explore and draw any mathematical PUBLISHER: PRO PASCAL FOUNDATION

function.
Solve systems of equations, calculate the area
of complex polygons. THE FAMOUS LIBRARY STICK
Draw lines, circles and ellipses. Newest technique USB 3 / 16 GB
you receive the library of the magazine updated
For the games, winning strategies are explained.
from issue 1 to issue 51. See details at
For puzzles the search algorithm.
For all projects: the math behind is thoroughly http://www.blaisepascal.eu/subscribers/
discussed. UK/UK_CD_DVD_USB_Department.html

COMBINATION
BOOK INCLUDING THE LIBRARY STICK EXCL. SHIPPING 75
http://www.blaisepascal.eu/david_dirkse/UK_Book_Department_DavData.html

13 Issue Nr 4 2016 BLAISE PASCAL MAGAZINE


DAY 1

DAY 2

DAY 3

Nerd Reflections #5 By Kim Bo Madsen

Community for Blaise Pascal Magazine

Google+ page for Blaise Pascal Magazine:


https://is.gd/bbUxQt.
Its an open comminity. You can comment here on the new
articles, old articles or aks questions, ask for special articles,
code books and things...just let us know...
The reactions we will publish as well in our magazine.

14 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


GET THE FREE TOOL

REST Debugger
Explore. Understand. Integrate

Embarcadero's free solution for


exploring, understanding,
and integrating RESTful web services
with Delphi and C++Builder apps:

Debug RESTful web services


Easily prototype Delphi
or C++Builder REST apps
Useful testing across
app development lifecycle
No code required

Explore and Understand


RESTful Web Services

The Embarcadero REST Debugger


empowers developers to explore, test,
and ultimately understand how
a RESTful web service works.
Dive right into REST data with
filterable JSON blobs, streamlined
Oauth 1.0/2.0 authentication, GET THE FREE TOOL!
and configurable
request/resource parameters.

No Code Required to Integrate REST Functionality

Directly copy and paste REST components from the REST Debugger to the RAD
Studio, Delphi or C++Builder IDE. This enables configuration and consumption of
REST services in Delphi or C++Builder apps with just a few clicks!

Prototype and Connect Delphi or C++Builder Apps to RESTful Web Services

Escape the mire of debugging REST calls in code and use the REST Debugger to fast
track data-rich prototyping with apps built using Delphi or C++Builder.

get the free tool:


http://www.barnsten.com/default/development-tools/free-tools/rest-debugger
or call: +31 (0)23 542 22 27
FREE PASCAL AND
LAZARUS FOUNDATION
http://foundation.freepascal.org
The Free Pascal and Lazarus foundation is a non-profit organisation
dedicated to the promotion and sponsoring of the
open source projects Free Pascal and Lazarus.
Donations are welcome

A NEW HORIZON
FOR LAZARUS
AND FREE PASCAL

Get in touch with us:

Lazarus/Free Pascal forum


Mail us at: [email protected]
Use the contact form
and we'll get back to you !

On the foundation Google+ community, on invitation


https://is.gd/BJG4dY
http://foundation.freepascal.org

16 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


PASCON
BLAISE PASCAL MAGAZINE
ARTIFICIAL INTELLIGENCE PAGE 1/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
BY BOIAN MITOV
The quest for intelligent machine has started long Artificial intelligence (AI) is the
before the first computers became reality. For intelligence exhibited by machines.
centuries mechanical devices have been created to In computer science, an ideal
mimic human behavior, and grab the imagination "intelligent" machine is a flexible WIKIPEDIA
of the spectators with the promises of mechanical rational agent that perceives its environment and
intelligence. But only after the first electronic takes actions that maximize its chance of success at an
computers appeared, creating such intelligence arbitrary goal. Colloquially, the term "artificial
became feasible. intelligence" is likely to be applied when a machine
The first attempts at such intelligence were uses cutting-edge techniques to competently perform
focused on teaching the computers to play games or mimic "cognitive" functions that we intuitively
and solve mathematical problems. They have associate with human minds, such as "learning" and
proven fairly good at both tasks. However when an
"problem solving".
attempt was made to connect a camera to a
The colloquial connotation, especially among the
motorized cart and have a computer navigate it
public, associates artificial intelligence with machines
through a room full of obstacles, it became
apparent that such simple task represents a major
that are "cutting-edge" (or even "mysterious"). This
challenge to the computer, and so began the quest subjective borderline around what constitutes
for creating the intelligent computer. "artificial intelligence" tends to shrink over time; for
example, optical character recognition is no longer
perceived as an exemplar of "artificial intelligence" as
it is nowadays a mundane routine technology.
Over the years many approaches have been tried. Modern examples of AI include computers that can
The initial attempts with hard-coded algorithms, beat professional players at Chess and Go, and self-
eventually were replaced with the so called Expert driving cars that navigate crowded city streets.
Systems that dominated the field in the 80s.
The idea was that if we take all the Here is how a classifier typically works:
knowledge of an expert in the form of facts,
and rules and program it in the computer, we will FEATURES CLASSES
have a system that will behave the same way as
FEATURE
the expert. DATA
EXTRACTOR CLASSIFIER
This approach however was not a success.
The amount of knowledge an expert system
needed was huge, and once programmed with this The Data is processed by a module called feature
knowledge, the system did not possess the ability extractor,
and features are extracted from the data.
to adapt and acquire more knowledge on its
own. The fiasco of the Expert Systems, dealt a As example in the case of image recognition,
major blow to the field of Artificial Intelligence. the features can be the colors of each pixel.
So close were they associated with the term AI, The features are then sent to the classifier module.
that their failure damaged the image of the entire If the module is trained, it will output one or more
field. classes to which the Data belongs.
In the mid-late 90s another AI approach The way the classification is output may differ
emerged, revolving around a different concept between different classifiers and implementations,
called classifier. A classifier can be trained to but the principle is the same.
classify data into different categories based on In some cases only one value will be sent in the
some features of those items. The classifiers output, indicating the most likely class, where in
quickly proved to be very successful in many other cases the classifier can be implemented to
areas, and today they dominate the world of AI. give different probabilities for each of the possible
With the new dominance of the classifiers, and classes.
because of the bad image that the Expert Systems Before using the classifier to classify the data, it
gave to the field of AI, classifier based AI today is needs to be trained. Here is a diagram showing the
often referred to as Computational Intelligence. process of training a classifier:
Today classifiers are used everywhere. Among
FEATURES
the most widely used classifiers are the SPAM
filters. They are used to classify e-mails into legit
FEATURE
e-mails and SPAM. Other popular types of DATA CLASSIFIER
EXTRACTOR
classifiers are object recognitions classifiers used
for facial detection and recognition, Speech
recognition, OCR, Gesture recognition, and even CLASS
search engines.

18 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


ARTIFICIAL INTELLIGENCE PAGE 2/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
To train the classifier, we send features (As Depending on the way the NEURONS of the
example pixels of a picture), and send the class that different layers of the NEURAL NETWORKS are
should be detected by the classifier (Whatever is connected the neural networks can be feed-
on the image - as example human, cat, flower etc.), forward, or recurring.
and the classifier will learn this. The process is In the FEED-FORWARD NEURAL NETWORKS , the
repeated with many features and classes. This set outputs of the neurons form each layer are
of features and classes is called training set . connected to the inputs of the neurons of the next
Once the classifier is trained, usually another layer in the direction from the Input Layer to the
set is used to verify that the classifier is working Output Layer :
properly. For this a separated set of features is HIDDEN
used, and the result of the classification is INPUT
compared with the expected classes. OUTPUT
Once we have verified that the classifier is
well trained, we can start using it.
Some classifiers are designed to be trained once,
and then used without further training. Other
classifiers can be trained over time while
working to improve their performance. There are
even some special types of classifiers that
automatically discover classes (clusters) from the
data. Such classifiers are often used in the search
engines to group the results based on similarities.
There are many types of classifiers, and new
ones are introduced over time. One of the best
known is the Neural Network classifier .
THE NEURAL NETWORK IS MODELED AFTER
THE HUMAN BRAIN. In recurring neural networks, some neurons can
It consists of elements called be connected to previous layers:
NEURONS usually
organized in layers, in1 wx1y1 wy1z1
and connected to
x1 y1 z1 b1
each other.
The first layer of in2
NEURONS is called Input Layer , and the last is x2 y2 z2 b2
called Output Layer.
The features are sent to the Input Layer , and the
Output Layer generates the classes. The layers
between the Input and the Output layers are called
ink wxkyl wxlyn
Hidden Layers . xk yl zn bn
Each NEURON has multiple inputs called
SYNAPSES, and one output called AXON.
The values from each input are multiplied by
coefficient (Weight), and added together. u1
The result is processed
through a non linear
activation function ,
u2
usually a sigmoid function:
( A sigmoid function is a
mathematical function
having an "S" shaped curve
(sigmoid curve).
X1 W1

W2 u y
X2 + F(u)
ul
X3 W3

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 19


20 Issue Nr 4 2016 BLAISE PASCAL MAGAZINE
ARTIFICIAL INTELLIGENCE PAGE 3/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
Backpropagation, an abbreviation for "backward
I have been fascinated by the field of AI for long
propagation of errors", is a common method of
time, and wanted to bring it closer to the Delphi
training artificial neural networks used in conjunction
world. I had already developed computer vision
with an optimization method such as gradient descent.
library, and it used some classifiers, but I wanted
The method calculates the gradient of a loss function
an universal AI solution that can be used to
with respect to all the weights in the network. The
classify anything, so few years ago, I set to build gradient is fed to the optimization method which in
an AI DELPHI LIBRARY , and called it turn uses it to update the weights, in an attempt to
IntelligenceLab.
minimize the loss function.
Over time, I continued to expand the library,
Resilient Propagation*2, Rprop,
and as AI tends to be heavily CPU demanding,
short for resilient backpropagation, is a learning heuristic
I added support for parallel processing and
for supervised learning in feedforward artificial neural
OpenCL GPU execution of some of the classifiers
networks. This is a first-order optimization algorithm.
for very high performance. My goal for the This algorithm was created by Martin Riedmiller and
future is to upgrade all the classifiers in the Heinrich Braun in 1992.
libraries to utilize GPU and parallel processing. Start a new VCL Form application:
To introduce you to the library, I will start
with a very simple project using the Neural
Networks. We will use a Neural Network with one
input (One feature), and one output, and will use
it to approximate a function based on limited
number of known points.

Imagine as example that we want to control


the flow of water with a valve, but the valve has
some unknown non linear function. What we
can do is, we can turn the valve to few different
positions, measure the water flow, and then use
those values to train the neural network, and
have it approximate for us the rest of the points.
While this can be solved with other
approximation methods, the Neural Network has
some advantages. For once, it can approximate a
function with multiple input variable
parameters, something not easily solvable with
other approaches. In the case of the valve we can Type Scope in the Tool Palette search box,
add one more parameter for water pressure, and then select TSLScope from the palette:
even another one for water temperature both
affecting the flow in some unknown way. For
this simple example I will use only one input
parameter(feature) , but it should be easy to
add more.
There are different ways to train the Feed
Drop it on
Forward Neural Networks. Two of the most
the form:
widely used methods are Back propagation , and
Resilient propagation . Both of them propagate the
correction for the difference between predicted
and expected signal from the output layer to the
input layer, making small adjustments at each
intermediate hidden layer. In this project we will
use the Back Propagation*1 training, however it
is very easy to change it to use the Resilient
Propagation*2, by using
TILNeuralNetworkRPropTrain instead of the
TILNeuralNetworkBackpropTrain
component.

22
ARTIFICIAL INTELLIGENCE PAGE 4/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
Type neur in the Tool Palette search box, In the Object Inspector Click on the button
then select TILNeuralNetwork from the palette: and select the ILNeuralNetwork1
component:

and drop it on the form,

This will connect the 2 components, and will allow


the ILNeuralNetworkBackpropTrain1 component
to train the neural network.

then select TILNeuralNetworkBackpropTrain:

and drop it on the form.

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 23


ARTIFICIAL INTELLIGENCE PAGE 5/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
Double click on the SLScope1 to open the
channel editor and click on the button
to add one more channel:

Set the name of the


first channel to Train:

Expand the Points property of the channel, Set the name of the second channel to Predict,
and set its Visible sub-property to True: then expand the Points property of the channel,
and set its Visible sub-property to True:

24 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


ARTIFICIAL INTELLIGENCE PAGE 6/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
Next we will add a button to start in the code editor for the Button1Click,
the training, and the testing of handler add the following code:
the classifier. procedure TForm1.Button1Click(Sender: TObject);
Type button in the Tool Palette var
search box, then select TButton I : Integer;
from the palette: ATrainingData : ISLRealMatrixBuffer;
AResponses : ISLRealMatrixBuffer;
ATestData : ISLRealBuffer;

const
SAMPLES = 26;

begin
// Train the Neural Network
ATrainingData := TSLRealMatrixBuffer.CreateSize( SAMPLES, 1 );
AResponses := TSLRealMatrixBuffer.CreateSize( SAMPLES, 1 );
SLScope1.Channels[ 0 ].Data.Clear();
SLScope1.Channels[ 1 ].Data.Clear();

for I:=0 to SAMPLES - 1 do


begin
ATrainingData[ I, 0 ] := I * 4;
AResponses[ I, 0 ] := abs(sin(I/10) + sin(I/3 + 0.1) * 0.1 )/4;
SLScope1.Channels[ 0 ].Data.AddXYPoint( ATrainingData[ I, 0 ],
AResponses[ I, 0 ] );
end;
and drop it in the form,
then Double Click ILNeuralNetworkBackpropTrain1.Train( ATrainingData,
on the button: AResponses );

// Test the Neural Network


ATestData := TSLRealBuffer.CreateSize( 1 );
for I := 0 to SAMPLES * 4 do
begin
ATestData[ 0 ] := I;
ILNeuralNetwork1.Predict( ATestData );
end;

end;

Here is what the code does:


After declaring variables, we will specify the
number of training samples:
const
SAMPLES = 26;

We will start by declaring a matrix of the training


samples:
// Train the Neural Network
ATrainingData :=
TSLRealMatrixBuffer.CreateSize( SAMPLES, 1 );

The matrix will have SAMPLES number of


training feature sets(the first parameter). Since we
have only one input for the neural network we
will have one feature per sample (the second
parameter).

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 25


ARTIFICIAL INTELLIGENCE PAGE 7/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
Next we will create a similar set of expected
responses. Again since we have only one output
the size will be SAMPLES by 1:
Aresponses := TSLRealMatrixBuffer.CreateSize( SAMPLES, 1 );

After clearing the scope channels, it is time to


prepare and populate the training and responses
sets:
for I:=0 to SAMPLES - 1 do
begin
ATrainingData[ I, 0 ] := I * 4;
AResponses[ I, 0 ] := abs(sin(I/10) + sin(I/3 + 0.1) * 0.1 )/4;
SLScope1.Channels[ 0 ].Data.AddXYPoint( ATrainingData[ I, 0 ], AResponses[ I, 0 ] );
end;

In this case we will use some function to generate


the relationship between the samples, and we will
also plot the training samples on the Channel[ 0 ]
of the scope. In the Object Inspector expand the Outputs property,
The next step is to train the Neural Network: and set the value of its Size sub-property to 1:
ILNeuralNetworkBackpropTrain1.Train( ATrainingData, AResponses );

And finally we can test the classifier to see how


well we have trained it:
ATestData := TSLRealBuffer.CreateSize( 1 );
for I := 0 to SAMPLES * 4 do
begin
ATestData[ 0 ] := I;
ILNeuralNetwork1.Predict( ATestData );
end;

The rest of the necessary code will be shown a bit


later, where we will plot classified data.
Next we will configure the Neural Network
Inputs, Outputs and layers.
Select the ILNeuralNetwork1 component. In the
Object Inspector expand the Inputs property, and
set the value of its Size sub-property to 1:

This will specify 1 output for the Neural Network.

This will specify 1 input for the Neural Network.

26 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


ARTIFICIAL INTELLIGENCE PAGE 8/9
CREATE AND TRAIN YOUR FIRST NEURAL NETWORK
In the Object Inspector, select the HiddenLayers
in the code editor for the
property, and click on the ellipsis button
ILNeuralNetwork1Result handler add the
following code:
procedure TForm1 . ILNeuralNetwork1Result (
ASender : TObject ; AFeatures : ISLRealBuffer ;
AResult : TILClassifierResult );
begin
SLScope1.Channels[ 1 ].Data.AddXYPoint( AFeatures[ 0 ],
AResult.Results[ 0 ] );
end;

This will plot the recognized samples during the


testing stage of the code we wrote earlier in the
button handler.
and add 2 hidden layers:
Select the Button1 on the form, and in the Object
Inspector set the value of the Caption property to
Run.

When you start the training process, the


ILNeuralNetworkBackpropTrain1 will repeat
training the neural network until one of the 2
conditions is met.
Either a certain maximum number of iterations (also
called Epochs) is reached, or the maximum change in
the output compare to the previous iteration
In the HiddenLayares editor dialog, becomes smaller than a specified threshold (Epsilon).
select the 2 layers. In the Object Inspector set the
value of the CountNeurons property to 6: Now we will specify the 2 conditions:
Select the ILNeuralNetworkBackpropTrain1
component.
In the Object Inspector, expand the
TerminationCriteria property, and set the value
of its Epsilon sub-property to 1E-7, and the
MaxIteration to 100000:

This will configure both hidden layer neurons to


have 6 neurons each. Close the editor.
In the Object Inspector switch to the Events tab,
and Double-Click on the OnResult event:

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 27


ARTIFICIAL INTELLIGENCE PAGE 9/9
CREATE AND TRAN YOUR FIRST NEURAL NETWORK
The project is ready.
You can run it. Click on the Run button:

"You may need to click on the "Run" button a couple of times until the Neural Network is trained well."
The red line is the training data with the training Boian Mitov is a software developer and founder of
points shown as red circles. The green line is the Mitov Software http://www.mitov.com,
result of the testing of the trained neural network. specialized in the areas of Video, Audio, Digital
This is one of the simplest demonstrations of Signal Processing, Data Acquisition, Hardware
Artificial Intelligence Classifier. Control, Industrial Automation, Communications,
It is not as interesting as image or speech Computer Vision, Artificial Intelligence, parallel and
distributed computing.
recognition, but it is a good simple example of
He has over 30 years of overall programming
Neural Network application. experience, and 20 years of Delphi experience in
large variety of software problems.
In the following Articles however we will dig deeper
He is author of the OpenWire open source
into the exciting world of AI, and will do more
technology: http://www.openwire.org, the
interesting and complex projects, involving image
IGDI+ open source library:
and voice pattern recognition.
http://www.igdiplus.org, the VideoLab,
SignalLab, AudioLab, PlotLab, InstrumentLab,
VisionLab, IntelligenceLab, LogicLab, AnimationLab,
CommunicationLab, Visual Live Bindings, the free
Mitov.Runtime libraries: http://www.mitov.com,
OpenWire Studio -
http://www.openwirestudio.com, Visuino
https://www.visuino.com/ and the VCL for
Visual C++ technology: www.mitov.com.
Boian Mitov is also a founding member of the Free
Pascal and Lazarus Foundation.
http://foundation.freepascal.org/

28 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


CREATE AN ANDROID PACKAGE PAGE 1/11
INCLUDING HOW TO USE THE EMULATOR
WITH CODE AND WORKING APK BY DETLEF OVERBEEK
INTRODUCTION An Android emulator is installed
In this article we will create a Multi Device Application on by default during the RAD Studio
an emulated android device. installation. You should allow this emulator to be
We are going to use the Multi Device Application we also installed during the installation of DELPHI.
used in Issue 4 2016 'How to build an app in xml'. This emulator is used as the default target for an
We also show where you could find the information to use Android application, so that you can create and
any of your devices to run a Multi Device Application. How run an Android application on your development
to do this varies per device so we can not explain it fully system without an Android device connected.
within the scope of this article. However we hope to point
you into the right direction by showing how to do it with a
Samsung S5 -android version 5.0.1. and for the emulator You better NOT use an Android emulator on a
we chose for the NEXUS 6 -because it seemed to be a virtual machine (VM), there is no GPU support
smaller item and that might run faster for the emulator on VMs. However, if you are
running Delphi on a VM on a Mac OS X
THE EMULATOR computer, you can consider using a remote
Before we try to test the application we will explain emulator on the Mac, because the emulator does not
some basics about android emulators. work on VMs.
WHAT IS AN ANDROID EMULATOR?
Although an emulator might run on a VM, the
An android emulator is an Android Virtual Device (AVD)
emulator will not actually run an application.
that represents a specific Android device.
You can use an Android emulator as a target
ANDROID EMULATORS ARE HEAVILY
platform to run and test your Android applications
on your PC, an Android device connected. HARDWARE-DEPENDENT.
That means it has two effects:
THE ADVANTAGE OF THE EMULATOR IS THAT YOU CAN 1. the hardware is being emulated
DESIGN FOR ALL KINDS OF MOBILES AND EVEN PADS. 2. the hardware on which the emulator runs.
To create an Android emulator
(made available by Google as part of the Android SDK), If the error messages about OpenGL ES pops
your machine should at least have the following up when you try to run your Android Emulator,
hard and software items: this means that your GPU is probably not suitable.
Intel Core i5 CPU (of your computer) If you want to create your own ANDROID EMULATOR,
rather even faster think of creating an emulator for each Android
4GB of RAM device you want to support. Keep in mind that
GPU emulation must be listed in the Android emulators often run so slow that some
hardware list of the emulator image developers consider them as unusable.

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 29


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 2/11
WITH CODE AND WORKING APK

It is a well-known performance issue that Android Thirdley At Android 2.2 or higher,


emulators are extremely slow. If you really think a Just-In-Time (JIT) compiler is added
so you might try Turbo Cocoa. (In the two earlier to Dalvik VM to analyze and optimize the Java
articles of BLAISE PASCAL MAGAZINE issue number byte-code while the program is running (for
51and 52 is explained how this tool for android helps example, JIT can compile a part of the byte-code to
certainly worth a test: www.TurboCocoa you can binary code before its execution). But in many cases,
even ask for a discount if you are a BLAISE native code still runs faster than Java code. Java code is
PASCAL MAGAZINE subscriber). Android run by Dalvik VM on Android. Dalvik VM is specially
emulators run much slower than real devices due designed for systems with constrained hardware
to the ARM platform emulation on top of a non-ARM resources (memory space, processor speed, and so on).
system. If performance prevents you from using an
Android emulator side by side with Delphi, you ANDROID EMULATORS REQUIRE
A SEPARATE GPU
could run and debug your Android Application (Graphics processing unit)
remotely. A graphics processing unit (GPU), also occasionally
Android emulators need a lot of machine resources called visual processing unit (VPU), is a specialized
and for the CPU. Running an Android emulator electronic circuit designed to rapidly manipulate and
and RAD Studio side by side on the same PC might
alter memory to accelerate the creation of images in a
be very troublesome, depending on the CPU and
frame buffer intended for output to a display. GPUs are
Memory of your development PC. Especially do
used in embedded systems, mobile phones, personal
not do this on a virtual machine (VM).
computers, workstations, and game consoles. Modern
RUN AND DEBUG YOUR ANDROID GPUs are very efficient at manipulating computer
APPLICATION REMOTELY graphics and image processing, and their highly parallel
If you need to run an Android emulator and you structure makes them more efficient than general-
are not able to use your development PC, you can purpose CPUs for algorithms where the processing of
run your Android emulator on a second machine, large blocks of data is done in parallel.
and have your development PC connected to this In a personal computer, a GPU can be present on a
second machine using SSH, so that Delphi can video card, or it can be embedded on the motherboard
detect and use any Android emulator running on orin certain CPUson the CPU die (integrated
that second machine. Circuit).
Note: This method is not restricted to Android
emulators; you can use this method with Android Android emulators are very much hardware-
devices connected to the second machine as well. dependent.
This means the hardware being emulated as well
Because of obvious reasons, emulators do of
as the hardware on which the emulator runs.
course not have all of the features that real devices
Therefore we recommend that you verify you
provide, although you can emulate some of those
have a suitable graphics card on your
features like geo location.
development system.
NDK (The Android NDK is a toolset that lets you
1. Open Control Panel\Appearance and
implement parts of your app using native-code
Personalization\Display\Screen Resolution.
languages such as C and C++. For certain types of apps,
2. Click Advanced Settings.
this can help you reuse code libraries written in those
3. Take a look at the displayed properties of
languages.)may improve application performance.
your graphics card.
This is usually true for many processor-bound
If you do not have a suitable GPU, it is probably
applications. Many multimedia applications and
not worth your time to create and attempt to run
video games use native code for processor-
an Android Emulator. Find another development
intensive tasks. The performance improvements
system that does have a suitable GPU.
can come from three sources. Firstly, the native
We do not recommend Intel GPUs.
code is compiled to a binary code and run directly
If you receive error messages about OpenGL
on OS. Secondly while Java code is translated into
ES when you try to run your Android emulator,
Java byte-code and interpreted by
this means that your GPU is probably not
Dalvik Virtual Machine (VM).
usable.

30 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 3/11
WITH CODE AND WORKING APK

You cant change things


that they dont want you
to change at least not easily.
Whats Inside?
In addition to the operating system itself,
the System Image contains wallpapers,
sounds, icon images, configuration and
property files, the kernel, and a whole bunch
of apps.
When you flash a custom ROM like
CyanogenMod or AOKP, youre essentially
replacing your System Image with a new
one with all the customizations, settings,
and apps that the ROM authors have put
spent tireless hours crafting into their
custom ROM. These custom ROMs are
usually kept more up-to-date than their
stock counterparts, and typically run faster
and more smoothly. Most have fewer pre-
installed apps (which we affectionately refer
to as Bloatware), so you have more room to
put the content you want (movies, music,
apps, wallpapers, etc.).

Flashrom can be a universal flash


programming utility used to detect, read,
verify, erase, or write BIOS chips in DIP,
PLCC, SOIC, TSOP, or BGA packages. It
supports parallel, LPC, FWH and SPI
flash interfaces. It can be used to flash
firmware images such as BIOS or coreboot,
or to back up an existing firmware.

Before you create an Android emulator, you need If you installed the Android SDK and NDK during
to install an Android system image that your RAD Studio installation, a valid Android system
emulators can use. image should already be shown as Installed in the
Android SDK Manager. In this case, you do not
What is the System Image?
need to install another Android system image.
In desktop and laptop computers, the System Image is
Follow these steps:
basically the operating system (Windows, Mac, Linux,
Unix, etc.) that you spend all your time in. You turn on 1. Start the Android SDK Manager
your computer, wait while it boots, then run all your (select Start | All Programs | Embarcadero RAD
apps and do all your work on the desktop which lives Studio | Android Tools).
inside the System Image. On Android its not that 2. In the packages tree, locate and check the
dissimilar. ARM EABI v7a System Image node within the
When Android boots up it takes you right into the first Android node in the list. For example:
System Image. Most users spend their lives running the
Android 4.2.2 (API 17) or Android 4.3 (API
stock.System Image the one that came pre-installed
18)
on their phone or tablet. That image contains all the
settings, configurations, and apps that both the OEM
and the carrier have decided are best for you. They
update it whenever they get around to it (unless they
have a new phone or tablet that they want you to buy).

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 31


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 4/11
WITH CODE AND WORKING APK

32 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 5/11
WITH CODE AND WORKING APK

3. Click Install 1 package. (Clear any


checkboxes that were auto-selected.)
4. In the Choose Packages to Install page, click
Accept License, and then click Install to
install the system image.

To create an Android emulator on your system, In the Create new Android Virtual Device (AVD) dialog
follow these steps: box, select an Android device to emulate, and enter
1. Start the Android SDK Manager (select Start | the details describing the Android device you want
All Programs | Embarcadero RAD Studio | to emulate. In order to run the Multi Device Aplication
Android SDKs | Android AVD Manager). the Android emulator must meet the following
2. In the Android Virtual Device Manager, click requirements:
the New button to create a new virtual 1. In Target, select an Android SDK with an
device. API level that is 17 or higher. The drop-down
list contains your installed versions of the
Android SDK.
2. Under Emulation Options,
check Use Host GPU.
3. In Device, select the Android device

HINT: Emulating an older Android device like


the Nexus S might be faster than emulating a
newer, larger device like the Nexus 10.

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 33


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 6/11
WITH CODE AND WORKING APK

We were not able to install it at first time, in the


correct way. We then decided which was very
helpful to just try a minimal design and find out if
it would run at all. It didn't.
After that we suddenly saw there was an option
on the AVD: Use Host GPU. We chose for that and
started agin, and guess what:
it worked.

34 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 7/11
WITH CODE AND WORKING APK

After doing this we also tried it on our own design


and again it worked.
Choose Use Host GPU
1. Click OK twice to create your new
Android emulator.
2. You can now view your emulator in the
Android Virtual Device Manager.

Delphi lists your Android Emulators in the Project EMULATORS ARE NOTORIOUSLY SLOW TO
Manager, within the Target node of the Android Target START AND TO RUN, SO STARTING THE
platform node.
EMULATOR BEFOREHAND MEANS THAT
NOTE:
YOUR APP CAN GET TO THE EMULATOR
As a reference, here are the default installed
locations of the Android development tools as MORE QUICKLY.
installed by the RAD Studio installer:
If you need to start the Android SDK Manager
directly, here is its location:
Path for Win 7
c:\Users\Public\Documents\RAD Studio
\12.0\PlatformSDKs\
adt-bundle-windows-x86-20130522
\SDK Manager.exe
This is Delphi XE 5 (12)

c:\Users\Public\Documents\
Embarcadero\Studio\18.0\ The recommended way to start an Android
PlatformSDKs\ emulator is by using the Android Virtual Device
android-sdk-windows\SDK Manager, which can be started from the Android
Manager.exe SDK Manager.
This is Delphi Berlin (18) To start an Android emulator such as the default
emulator installed in Delphi:
If SDK Manager.exe does not start, use 1. Start the Android Virtual Device Manager
Android.bat,which is located here: (select Start | All Programs | Embarcadero RAD
C:\Users\Public\Documents\ Studio | Android SDKs | Android AVD Manager).
RAD Studio\12.0\PlatformSDKs\
adt-bundle-windows-x86-20130522\
sdk\tools\android.bat
This is Delphi XE 5 (12)
c:\Users\Public\Documents\
Embarcadero\Studio\18.0\
PlatformSDKs\
android-sdk-windows\tools\
This is Delphi Berlin (18)

STARTING AN ANDROID EMULATOR


When the emulator is the current target platform,
you do not have to start the emulator before
running your Android app on the emulator.
However, we recommend that you start
your Android emulator separately,
perhaps before you start RAD Studio.

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 35


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 8/11
WITH CODE AND WORKING APK

1. Select the emulator and click Start.


2. Then click Launch on the Launch Options
dialog box.
3. Your emulator should now start
(this does take ten minutes, good for coffee):

36 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 9/11
WITH CODE AND WORKING APK

In the Project Manager, your emulator should HINT:


appear in the Target node of the Android target If the Project Manager does not
platform, with its assigned port (such as (5554)): show your running Android emulator as
running, with the same icon as in the screen shot
above, see Using the Target Node. In the Project
Manager, ensure that the emulator's name is in
boldface and the port number is indicated in
parentheses (such as (5554)), indicating that the
emulator is running and is the current selected
target platform.
You could manually refresh the list of available
targets for a target platform (for all devices: iOS
Device or Android), right-click the Target node
and select Refresh.
Before we can run the multi device application
on the emulator we will have to activate
debugging on the emulated device. This can be
found under
Settings\Developer options\Debugging.
To run the application from Delphi we follow the
next steps.

TO RUN YOUR APPLICATION ON YOUR


ANDROID EMULATOR
1. Open your Android application in
RAD Studio.
2. In the Project Manager, enable the
emulator as the target platform.
(double click on the target)
3. In the device selector in the FireMonkey
Mobile Form Designer, select the device
that matches the emulator you are using.
For example:
4. Run your application:
To run with debugging (Run > Run or F9)
To run without debugging
(Run > Run Without Debugging or
Shift+Ctrl+F9)
5. Compile and deploy messages should
appear in the IDE.
6. If the emulator is not running, the IDE
displays:
"The selected emulator is not
running. Do you want start it?"
Click Yes.
A "Launching emulator" message is
displayed.

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 37


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 10/11
WITH CODE AND WORKING APK

7. Open your emulator screen and


watch for the app to appear.

38 Issue Nr 5 2016 BLAISE PASCAL MAGAZINE


CREATE AN ANDROID PACKAGE
INCLUDING HOW TO USE THE EMULATOR PAGE 11/11
WITH CODE AND WORKING APK

Delphi builds your Android application and runs


it on the selected Android emulator.
If the active Android emulator is not running,
RAD Studio shows a dialogue box that gives you
the choice to start your Android emulator.
If your Android emulator screen is locked, unlock
it to access your application.

The code for this article is available at your


private download site.

If you miss anything or have no access please let


us know... [email protected]

Issue Nr 5 2016 BLAISE PASCAL MAGAZINE 39


INTELLIGENT SYSTEMS?

BETTER USE KBMMW...


- Now multimonitor remote desktop V5 (VCL and FMX)
- Rad studio and Delphi 10.1 BERLIN support
- High performance LZ4 and Jpeg compression
- Impoved NextGen support including IOS 64 bit
- Native high performance 100% developer Supports Delphi/C++ Builder/RAD Studio
defined application server with support for 2009 to 10.1 Berlin (32 bit/64 bit, Android,
loadbalancing and failover IOS 32/64 and OSX where applicable)"
- Native high performance JSON and XML
kbmMemTable is the fastest and most feature rich
(DOM and SAX) for easy integration with
in memory table for Embarcadero products.
external systems - Easily supports large datasets
- Native support for RTTI assisted object with millions of records
marshalling to and from XML/JSON, - Easy data streaming support
now also with new fullfeatured XML schema - Optional to use native SQL engine
(XSD) import - Supports nested transactions and undo
- High speed, unified database access - Native and fast build in M/D,
(35+ supported database APIs) with aggregation /grouping,
range selection features
connection pooling, metadata and
- Advanced indexing features for
data caching on all tiers extreme performance
- Multi head access to the application server,
via AJAX, native binary, Publish/Subscribe, Warning!
SOAP, XML, RTMP from web browsers,
kbmMemTable and kbmMW
embedded devices, linked application
servers, PCs, mobile devices, Java systems are highly addictive!
and many more clients Once used, and you are hooked for life!
- Full FastCGI hosting support. Host PHP/Ruby
/Perl/Python applications in kbmMW!
- AMQP support
( Advanced Message Queuing Protocol)
- Added AMQP 0.91 client side gateway
support and sample.
- Fully end 2 end secure brandable Remote
Desktop with near REALTIME HD video,

COMPONENTS
4
8 monitor support, texture detection,
compression and clipboard sharing.

DEVELOPERS
EESB, SOA,MoM, EAI TOOLS FOR INTELLIGENT SOLUTIONS. kbmMW IS THE PREMIERE N-TIER PRODUCT FOR DELPHI /
C++BUILDER BDS DEVELOPMENT FRAMEWORK FOR WIN 32 / 64, .NET AND LINUX WITH CLIENTS RESIDING ON WIN32 / 64,
.NET, LINUX, UNIX MAINFRAMES, MINIS, EMBEDDED DEVICES, SMART PHONES AND TABLETS.

You might also like