You are on page 1of 40

BLAISE PASCAL MAGAZINE

ALL ABOUT DELPHI AND DELPHI PRISM(.Net) , LAZARUS & PASCAL AND RELATED LANGUAGES

Pascal

15/97
Download edition

STARTER VERSION

Delphi XE Starter edition reviewed by Howard Page Clark Delphi XE Starter try: a littel Mailserver by Jim Duff ClientDataset: what to do if you dont have it? get kbmMemTable CodeGear Edition its free! by Detlef Overbeek Introduction to Databases Part 2: Common Database Objects by Cary Jenssen Advantage Database Server and Delphi XE Starter Edition by Howard Page Clark Moving /adding your components into the Delphi Starter Edition by Rick Smit

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

BLAISE PASCAL MAGAZINE 15 ALL ABOUT DELPHI AND DELPHI PRISM(.Net) ,LAZARUS & PASCAL AND RELATED LANGUAGES
CONTENTS
Articles
Delphi XE Starter edition reviewed
by Howard Page Clark by Jim Duff page 7 page 13

Volume 15, ISSN 1876-0589


Editor in chief Detlef D. Overbeek, Netherlands Tel.: +31 (0)30 68.76.981 / Mobile: +31 (0)6 21.23.62.68 News and Press Releases email only to editor@blaisepascal.eu Authors B Peter Bijlsma, C Marco Cant, D David Dirkse, Frans Doove, James D. Duff G Primo Gabrijeli, H Fikret Hasovic N Jeremy North, O Tim Opsteeg, P Herman Peeren, Howard Page-Clark R Michael Rozlog, S Henk Schreij, Rik Smit, Bob Swart,

Delphi XE Starter try: a littel Mailserver ClientDataset: what to do if you dont have it? get kbmMemTable CodeGear Edition its free!
by Detlef Overbeek page 21

Introduction to Databases Part 2: Common Database Objects


by Cary Jenssen page 28

Advantage Database Server and Delphi XE Starter Edition by Howard Page Clark page 31 Moving /adding your components into Delphi Starter Edition
by Rick Smit page 35

Editors
Peter Bijlsma, Rob van den Bogert, W. (Wim) van Ingen Schenau, Miguel van der Laar, M.J. (Marco) Roessen . Correctors Howard Page-Clark, James D. Duff Translations M. L. E. J.M. (Miguel) van de Laar, Kenneth Cox (Official Translator) Copyright See the notice at the bottom of this page. 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
1: Printed version: subscription 60.-(including code, programs and printed magazine, 4 issues per year including postage). 2: Non printed subscription 35.-(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 office@blaisepascal.eu Subscriptions can start at any date. All issues published in the calendar year of the subscription will be sent as well. Subscriptions run per calender year. Subscriptions will not be prolonged without notice. Receipt of payment will be sent by email. Invoices will be sent with the March issue. Subscription can be paid by sending the payment to: ABN AMRO Bank Account no. 44 19 60 863 or by credit card: Paypal or TakeTwo 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 68.76.981 / Mobile: + 31 (0) 6 21.23.62.68 office@blaisepascal.eu

Columns
Foreword page 4

Advertisers
Advantage Database Server Cary Jensens newest book about Advantage Database Server Components for Developers Database Workbench Pro by Upscene Productions DA Soft - AnyDac TMS Software page 3 page 5 page 40 page 6 page 27 page 19 / 20

International Pascal Conference


18 June May 2011 LAZARUS USB Stick Combination with the book page 16 page 27

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.

Page 2

COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Foreword
A programming beginner? Who wasn't at one time? We all have our memories about that phase. Those were the days... Actually it was rather like an earthquake when I had the first glimpse of Delphi... It felt like being in love. The steadily developing tool became better and better, in spite of the problems that each release threw up. Even today it continues to improve. And finally here is the first new Starter Edition in years. Forget all the complaints made towards Embarcadero about their waiting too long and taking too much time. We now have a beginner's version again. This is a great tool even for professionals. You can do almost anything with this Starter version. Of course it is cut down from the Professional Edition, and you can discuss endlessly what should or should not have been included in it. But we all understand that Embarcadero needs to be profitable in order to continue development of its tools, and actually I think this is a very fair-priced coding tool. If you really want a Pascal IDE for nothing, you can use Lazarus. So we can do our task again and try to convince beginners, teachers and start-ups that Delphi (Pascal) is the best learning, teaching and development language in programming. Let's get on with demonstrating that...

Blaise Pascal

Page 4

COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Februari 2011 BLAISE PASCAL MAGAZINE 15

Page 6

Februari 2011 BLAISE PASCAL MAGAZINE 15

Delphi XE Starter edition reviewed


starter expert
DELPHI XE and above (Win32)

By Howard Page Clark

A new version of Delphi is always an exciting prospect for Pascal developers, even those who don't customarily work on the Windows platform, because Borland/Inprise/CodeGear/Embarcadero have been leaders in the Pascal compiler and IDE market for so long. It was a surprise to me to learn that with the latest XE version of Delphi (and C++ Builder) Embarcadero had introduced a budget Starter version alongside the Professional, Enterprise and Architect versions of Delphi XE, since for the last five years it looked as though they were completely opposed to producing anything similar to the Turbo Explorer version which was given away in 2006, but is no longer available.
Since the withdrawal of the Turbo offerings, Embarcadero's minimum Delphi product has been the Professional RAD Studio or Professional Delphi XE. Priced in the UK at 356 + VAT (upgrade), the Professional Edition is clearly not aimed at amateurs, hobbyists or students, nor at beginners (unless these people are independently wealthy). From their own promotion, Embarcadero's target market for the XE Starter edition appears to be commercial software developers, rather than amateurs. The Delphi Starter Edition is both designed and priced to allow individuals and startups to bootstrap their vision until related revenues reach $1,000 at which point a specially priced Professional Edition license can be purchased. So they are pitching this cut-down, introductory Delphi at 'start-up' businesses with low revenues. Once revenue generated from use of Delphi XE Starter exceeds $1,000, they require an upgrade to the Professional Edition. Note, this is 'revenue' not 'profit'. In other words, any commercial use of Delphi XE Starter at all is a pathway into purchase of the Professional or higher package. What software start-up will survive beyond its first year if it does not have revenues of more than $1,000? I don't run a software business, not even one with as low a turnover as Embarcadero envisages, so this review of XE Starter is written from the point of view of the hobbyist programmer, and also someone who does use Delphi programs in small charities (non-profit corporations in American parlance) which rely on volunteers for staffing, and have few financial resources. That is, UK charities which would not be in a position to purchase the XE Professional Edition, but who might consider the 127.20 (inc. VAT) cost of Delphi XE Starter a good investment. Many students may be in a similar situation. Prices are 149 + VAT in continental Europe, $149 in the US for 'upgrading', and apparently you can 'upgrade' after using Notepad as your source code editor!
Februari 2011 BLAISE PASCAL MAGAZINE 15

So what do you get for your money? An almost complete, versatile and stable IDE with access both to legacy code and the latest language enhancements such as generics and anonymous methods. A slew of components (supplied as both release and debug .dcus) offering all the basics of the VCL as well as giving access to Vista dialogs, ribbon controls, component support for Windows touchscreen and gesture APIs, and database support largely limited to the (deprecated) BDE and Interbase. You get a very responsive IDE, which loads more quickly than any recent Delphis (on my dual core 4GB RAM system it loads in 15 seconds, compared to RAD Studio 2010's 40 seconds). You get a world class 32-bit optimising compiler/linker which is extremely fast. After installation the IDE is very customisable, with windows that dock easily, and a choice of desktop layouts (see Figure 1). Interestingly, an option to restore the classic Component Palette that graced Delphi's first versions is available. It shows in the illustration, below the main menu. This works with or without the Tool Palette window which can also be seen in the lower-right window in the illustration. I find this option to add the 'old' component palette back to the IDE helpful, perhaps because I'm used to the Lazarus IDE interface. However, it does seem to have been added hastily although accessible via a context menu if you right-click in the main menu area, it hasn't made it into the Customize dialog's Toolbars page (see Figure 2). Don't Embarcadero's developers use their own ActionManager or ActionLists?

Figure 2: The Customize dialog which lists 10 toolbars (but not the Component entry) The Delphi IDE is delightfully customisable, and a mouse click or two are all you need to switch to a more convenient layout, or revert to a former one.
COMPONENTS
DEVELOPERS

Page 7

Delphi XE Starter edition reviewed (Continuation 1)

Figure 1: The Delphi XE Starter IDE showing all toolbars - left part
Page 8
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Delphi XE Starter edition reviewed (Continuation 2)

Figure 1: The Delphi XE Starter IDE showing all toolbars - right part
Februari 2011 BLAISE PASCAL MAGAZINE 15
Page 9

Delphi XE Starter edition reviewed (Continuation 3)

Figure 3 shows the full toolbar layout of Figure 1 adjusted to give more room for working in the code editor by removing all the toolbars and enlarging the editor window (and you can of course make the editor full screen if you wish). The arrangement of editor page tabs at the top, and Code, Design and History tabs at the bottom of the editor window (hanging into the status bar) makes for quick and easy moves between views.

The IDE has not changed greatly from Delphi 2010, but an enhancement included in the Starter version is the integration into the IDE of Subversion features (from CollabNet) so you can use them directly, and have no excuse for neglecting version control of your projects! Subversion functionality is accessed from the File menu, which has a new Open From Version Control option which shows a Checkout dialog where you can checkout a project, once you have set up a repository (see Figure 4), and from the Project context menu (see Figure 5).

Figure 3: The IDE configured to give more elbow room for editing code
Out-of-the-box, before adding any third party components XE Starter includes 22 pages of components. If you discount the deprecated BDE and Win 3.1 pages, and the 6 pages of open source Indy 10 components that is still 14 pages of high quality VCL components, and those pages are identical to those pages in the more expensive XE Edition palettes, except for the Data Access page which lacks TClientDataSet and the TXML components. And, unlike the crippled Turbo Delphi, you can install further components into Delphi XE Starter (unless they require external compilation like the DevExpress components).

During installation you have the options to download the documentation, Interbase and ER/Studio, and an ISO of Partner product trials. The documentation is essential, of course, and so is Interbase if you are going to do any serious database work requiring use of SQL.
Page 10
COMPONENTS
DEVELOPERS

Once you have burned the ISO to a DVD you will find it contains over 40 offerings, including some freeware or open source Delphi components and wizards, including CnPack and the JEDI library and components. Installation of the JEDI components requires use of a binary installer (not included on the ISO) available from their website. You can also download an excellent Windows installation engine, InstallAware Express, CodeGear Edition, which makes the business of producing Windows .msi files for distributing your software bearable (see Figure 6). There is also a trial licence offered for the download of ER/Studio, a database modelling and design tool.

Februari 2011 BLAISE PASCAL MAGAZINE 15

Delphi XE Starter edition reviewed (Continuation 4)

Figure 4: Checking out a software project using the integrated CollabNet Subversion server Not part of the installation process, but available free from the Embarcadero site for registered users is a useful .pdf download of Bob Swart's new book, Delphi XE Starter Essentials. In spite of the mention of XE Starter in the title, however, there is only one chapter devoted to the Starter Edition. Misleading title apart, it is a good book, and the relevant chapter covers the Starter IDE in some detail. The other chapters give an overview of language features added since Delphi 2009, including Unicode.

Figure 6: The progress as InstallAware installs 246 MB of software What don't you get with the Starter Edition, compared to the Professional Edition? Well, quite a bit, actually. But then, this is a Starter Edition. I list below the omissions I'm aware of, beginning with the VCL. Omissions from the VCL: No source code for the VCL. For commercial use, this may be a show-stopper. For hobbyists, this is annoying, but not unexpected, since you haven't paid for it. Database functionality limited to Interbase (or the BDE). No TClientDataSet, no dBExpress components, no dbGo (ADO) components, no database reporting via Rave or other components. No DataSnap server. No TeeChart components for graphing data.

Figure 5: The Subversion menu accessed from the project context menu, new to XE's IDE Internet access limited to use of Indy components. No Internet page, no InternetExpress, WebSnap, WebServices, WebBroker, Web Documents or VCL for the Web. So no easy interface with SOAP, JSON and so forth. There are no widgets for REST transactions, and thus no easy interface to Facebook, Google Maps, Amazon marketplaces and so on. No XML components including TXMLDocument.

Februari 2011 BLAISE PASCAL MAGAZINE 15

COMPONENTS
DEVELOPERS

Page 11

Delphi XE Starter edition reviewed (Continuation 5)

Figure 7: Trying to run the Delphi compiler at the command- line is frustrating
IDE shortcomings in the Starter Edition:

Lack of an external compiler. If you try to run Delphi XE Starter's compiler outside the Delphi IDE, you get the disappointing message shown in Figure 7. This means that makefiles and scripted builds are not going to work in the Starter Edition, and it does lead to problems for some third party component development houses who rely on external compilation for installing their component suites. However the assembler tasm32.exe has not been crippled, as far as I can see (though, if you're a Windows assembly programmer, you're hardly likely to be buying the Starter Edition of any development suite). Some IDE code generation functionality has been removed. If you're accustomed to typing a class skeleton and then pressing [Ctrl][Shift][C] to get the implementation code written out for you, the Starter Edition does not oblige. However, it does have extensive auto code completion functionality via tooltips that pop up with suggestions for completing code as you write it. For instance, typing ch shows a tooltip offering the type Char, the conversion function Chr() or the change directory procedure ChDir(). No CodeSite debugging or logging (included with XE Professional). No AQTime profiling (included with XE Professional). The help invoked by pressing [F1] makes no distinction between XE Starter and other Editions of XE, so it can suggest options that are not available or appropriate for the reduced IDE of the Starter. The code examples installed are identical with those for the higher versions (they are now in a folder called Samples rather than Examples. I found them after quite a search at C:\Users\Public\Documents\RAD Studio\8.0\Samples). The CPP, DataSnapXE, DelphiPrism and Modelling subfolders are useless for Delphi XE Starter, and should not be installed by an intelligent installer. Some code examples should have been checked and weren't. 'If they compile they're OK.' But visual glitches in the about boxes shown in Figures 8 and 9 would have been so simple to correct.
Conclusion?

Figure 8: The Swat.dproj About box

Figure 9: The resxplor.droj About box to see how many of the Starter sales turn into Professional, or Architect sales in due course. It has cost them little extra to produce it in terms of programmer time and resources (sqlmon.exe, for instance, included with the Interbase download is Borland 2001), and it should generate both revenue and interest among a broad group of people who cannot afford the other XE offerings, and yet would like to use a modern Pascal-based IDE. Thank goodness Embarcadero has listened to those who have been urging them to do something of this sort ever since 2006.
Howard Page-Clark lives near Poole, Dorset in the UK. He is a hobby programmer who first made use of Delphi to develop database programs when working as a book keeper for a disability charity. After a period as a teacher of science to teenagers, he now works as a volunteer with charities and church groups. He is married to Jodi, and they have four adopted children, now all grown-up.

So although there are free 'competitors' such as the Visual Express IDEs and Lazarus/Free Pascal I think the XE Starter Edition is an excellent addition to the Pascal marketplace, and it will be interesting for Embarcadero
Page 12
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Delphi XE Starter tried out with a demo program: by Jim Duff a little Mailserver
starter expert
DELPHI XE and above (Win32)

For the purpose of this article, I will introduce two projects: a simple, but useful, single form project that can send emails, and a second project that uses a database. The second project also uses the form from the first project to show how multiple forms within a project are associated with one another. What is a Project? It is a set Background of one or more units or forms which, when compiled and As a backdrop to what follows in this article, the name built, form an executable program with a .exe filename Delphi, as most current users know, was applied to this suffix, ready to be deployed for use by yourself or your product based on the historical Greek saying: "If you want customers. to talk to [the] Oracle, go to Delphi". This modern day connection no pun intended was based on one of the Sample Project One major elements of Delphi, which was providing a simple Most development products simply do the 'Hello World' and effective means of talking to databases via the various as their starting example. Delphi demonstrators, however, database management systems (DBMS), such as Oracle. usually create a single form and place about five or six components on it. When it is then compiled and run in Delphi was released by Borland in 1995, and was based on no time flat, they navigate through a grid of details from a its earlier product Turbo Pascal which introduced the IDE live database. (Integrated Development Environment). The beauty of Delphi was that it retained the speed of compilation and There are several web sites that can assist Delphi execution brought forward from its ancestor. It also developers, whether you are a beginner and want to get extended the IDE to become a visual based RAD (Rapid some basic programming help, or a more experienced Application Development) environment. programmer wanting to know about an area that is new to you. One such site is delphi.about.com by Zarko Gajic.
Februari 2011 BLAISE PASCAL MAGAZINE 15
COMPONENTS
DEVELOPERS

By the time this article is published, most existing Delphi users will have caught up with the enhancements provided for in Delphi XE, and become aware of the announcement, by Embarcadero, in late January 2011 of the Starter Edition. The aim of this edition is to get newcomers into using the highly productive Delphi development toolkit. From a marketing perspective, this is a huge challenge for Embarcadero, and most existing users will no doubt welcome this move to raise the level of Delphi in the development world. From the Blaise Pascal Magazine perspective, the Delphi Starter Edition now provides a good reason for all subscribers to not only read the articles and discuss them with colleagues, but to pass them on to friends who may have a need to get into software development. Such needs could be for personal or small business record keeping, or as a starting point for larger business requirements. There have been some discussions in several Delphi-related user web sites regarding the lack of third party components that can be attached to this Starter Edition. Such components play a large part in the world of Delphi, especially for people who would rather take advantage of other people's skills in creating required components, rather than reinventing the wheel themselves. My understanding is that there are timing issues involved, as Embarcadero needed to get this edition out to the market place quickly and that, in time, these components may well become available. As we write this, third party component suppliers, such as Nexus Database Systems, are providing Starter Editions of their products for easy installation into the Delphi Starter Edition see www.nexusdb.com. The Starter Edition can be purchased for USD199, and provides a 365 day licence period. Users can upgrade to Professional or other versions at any time, and other conditions apply in regard to the amount of income derived from Starter Edition developed products see the Embarcadero website below for further details.

So the simplification of connections to databases, the effective generation of the related user interfaces, as well as having the Object Pascal based programming language under the bonnet, are all wrapped up in a single word called productivity. Over the years, ownership of the Delphi product has changed hands several times, and finally it has become the complementary product of Embarcadero Technologies, being a software organization specializing in database productivity tools for the major database vendors: Microsoft SQL Server, Oracle, MySQL, SQL Anywhere, InterBase, Firebird, and more. It is also interesting to note that Oracle have an XE version of their product that provides a testing environment just as Delphi XE Starter Edition does. Their XE Version stands for Express Edition, whereas my understanding of Delphi XE is that it stands for version 15 Latin X, plus the fifth letter of the alphabet. In keeping with the times, Delphi 2010 introduced features for Windows 7 support, touch and gesture functionality, plus other tool-based enhancements; the XE version further extends the ability for building Cloudbased applications. All of these details and more can be found by starting to look at the following link:
http://www.embarcadero.com/products/delphi/starter.

Examples

Page 13

Delphi XE Starter tried out with a demo program: a littele Mailserver (continuation 1)

For this exercise, I downloaded a project from


http://delphi.about.com/od/indy/a/emailsend-indy.htm.This project contains a single form

that enables you to send emails, something that is relevant in today's world. The project uses the Indy components, which come with the Starter Edition. You can simply download this project, then compile and run it as a stand-alone program as follows: Start Delphi XE, and on the Welcome Page, click on 'Open Project'; Navigate to the folder where you did the download, via the Open Project dialog; Select 'MailSenderProject.dpr'. After the above two steps, you now have the form, with its visual components, sitting in the Integrated Development Environment (IDE), and ready to go. At the foot of the IDE page there are three tabs that allow you to shift from the visual Design view shown here to a Code tab that shows the underlying code (you can use the F12 key to flip between these two tabs), plus a third tab that shows the History of your code changes.

Figure 2: Project One: MailSenderProject Object Inspector View of TIdSMTP Component Also notice that the component type names start with the letter T, being T for Type, the original Turbo Pascal classification; in this day and age, they are actually Objects, but the T prefix has persisted. You, as the programmer, then give each instance of a component a name that is relevant: eg, you may have several TTable components on a form, each one named according to the data held in the database, such as tblCustomers, tblEmployees etc. Click on the Project menu item and select Build MailSenderProject, or simply press the Shift+F9 keys to build the project, which creates the .exe file ready for deployment. Then press the F9 key to run the program. How easy is that?

Figure 1: Project One: MailSenderProject Main Form In addition to the normal labels and Edit box components that make up the visual aspects of this form, there are three components that make life easy for the Delphi developer: the two Indy components - a TIdMessage component named MailMessage and a TIdSMTP component named SMTP - plus the general TOpenDialog component named AttachmentDialog that is used to fire up a standard Windows Open dialog for locating an attachment. These visual component/object types show up in the Object Inspector when any of them are clicked, but are not seen when the program is running.
Page 14
COMPONENTS
DEVELOPERS

Figure 3: Delphi XE Menu and Icon Bar (part only)


Some Settings made by Delphi

If you look in the folder that contains this downloaded project, you will see the project filename had the file suffix of .dpr (Delphi Project) that had been created in an earlier version of Delphi an excellent example of backward compatibility. Now, the newly created project under Delphi XE has the suffix .dproj, and that is the one that will be opened in future; this new name/suffix is also now shown in the list of Recently Opened Projects on the Delphi Welcome Page.
Februari 2011 BLAISE PASCAL MAGAZINE 15

Delphi XE Starter tried out with a demo program: a littele Mailserver (continuation 2)

Creation of this sample project comprised the You will also note that there is a MailSenderProject.ini file, following steps: contained in the project folder, that contains details of the Host (SMTP) Server and the From information, so you Create the required database and its tables (just one don't have to enter them each time you run the program. table in this example); Have a look at the contents of that file, and then view the Open a new Project in Delphi; code inside the program (press F12), to see how they Create a Data Module unit; match up: see procedures GetSettings, and SaveSettings, Create the main working form; the former one shown as follows, in the very easy to read Add the above Sample Project One Email form to the Pascal language: project and make two very simple changes to make it procedure TMailerForm.SaveSettings; work as part of this latter Project Two. var
Some Settings made by the Program
ini : TIniFile; begin Ini := TIniFile.Create(ChangeFileExt (Application.ExeName,'.ini')); try ini.WriteString('SMTP','Host',ledHost.Text); ini.WriteString('MAIL','From',ledFrom.Text); ini.WriteString('MAIL','To',ledTo.Text); ini.WriteString('MAIL','CC',ledCC.Text); finally ini.Free; end; end; (* SaveSettings *)

As the database has been created along with the downloaded project, you now only need to connect to the database, rather than create it. Initally using the tools provided by Interbase, follow these instructions to connect to the sample database provided. This will give you an idea of the properties and functionality provided in managing a database. Run the Interbase Console application IBConsole. Use the following default values: User = 'SYSDBA', whenever prompted, until you are ready to set your own values.

Sample Project Two - XEStarter

This will then provide a connection to this sample's database. From here, you can view all properties of the database and the Mynames table, by a right-mouse click on As you saw in Project One above, it is convenient to send the relevant icons. emails from a program that remembers your basic settings. But what about remembering the email addresses and other information about all of your customers, friends or Once downloaded and opened in Delphi, you will see that Project Two contains three units: the main unit of the relatives? This is where databases come into their own. We will now look at having a database that will remember program, a Data Module, plus the slightly modified unit that was part of Project One above. this information for us, and give us the ability to select which customers, friends or relatives we wish to email The difference between the Data Module and the two today. other forms is that the former is a non-visual component that is visible in the IDE, but is not visible when the The primary requirement for any database project is to program is executed. Its main purpose is to act as a logical have the database of your choice installed in this case unit that contains connections to the database, plus other Interbase. database related components such as tables, queries (where you use the language called SQL) and data sources (used The Delphi XE Starter Edition provides for the for connections from elements such as grids to the installation of Interbase 2009 on the installation setup screen. Once you click that selection, you are taken to the relevant tables or queries etc.). Embarcadero web site where you download the 2009 Here are the relevant samples of the forms and code as version, and are given a registration key. During the installation, take all the default options except one: on the listed above. page that shows Select Components, also tick the box that says Client Only (and leave all others ticked), and then continue. The next time you start up Delphi XE, you will see Interbase as an item in the Tool Palette on the lower right hand side of the IDE.

A major aspect of database development is an understanding of how databases are designed for maximum efficiency and productivity. Databases are a set of related tables, hence the name Relational Database, built under the design rules outlined by the pioneer of the relational model for databases, Edgar F Codd. Plus, DBMSs all provide a 'standard' language for creating and accessing databases via the tool known as Structured Query Language (SQL).

Password = 'masterkey'

Once inside IBConsole, click on Database | Add, and navigate to MYNAMES.IB

Februari 2011 BLAISE PASCAL MAGAZINE 15

COMPONENTS
DEVELOPERS

Page 15

THE NEW INTERNATIONAL PASCAL CONFERENCE 18* JUNE 2011 IN HOLLAND


* The date has been prosponed from 14 of May towards 18 of June 2011

INTERNATIONAL PASCAL CONFERENCE IN HOLLAND


20 Page 16
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Delphi XE Starter tried out with a demo program: a littele Mailserver (continuation 3)

Firstly, the DataModule unit. This shows four components which are: db1 a TDatabase component that identifies the database and its location; ibTrans1 a TIBTransaction component, being a working element for the transaction used by the db1 TDatabase component; dstblMyNames - a TDataSource component used as a connector for other components pointing to TTables or TQueries; in this case it is pointing to the MyNames table; tblMyNames a TIBTable component that defines properties of the table. One such property is an IndexName which we have specified as indxLastName, that sorts the data into the required sequence to make life easier for locating the record(s) you are after.

This form unit comprises three components only: The large element in the lower part of the form, being a TDBGrid, that displays the selected data fields in the database. These are shown in alphabetical order of LastName, FirstName, as set up by an index in the database; A TDBNavigator, a standard component in Delphi that can access any type of database table or query. This enables you to navigate through the various records, and allows you to add, edit, delete records, if applicable to the application. Note that both the TDBNavigator and TDBGrid components have a property called DataSource, both of which contain the value (point to) dstblMyNames which in turn points to the MyNames Table. (For the purposes of this basic demonstration, we have used a TTable as the source element for the Grid and Navigator, something that is not usually done in larger applications where multiple users are accessing the same database. A grid is usually sourced from a TQuery but that's another story for when you graduate to client/server or multi-tier systems). The third component is a Tbutton, that you activate to call the Email unit copied over from the first example project above. There are other button types that enable you to place icons inside them that's your choice... There are three steps required in order to include the Email form from the Project One example above into Project Two. Firstly, by clicking on the '+' button in the Delphi icon bar (seen in Figure 3 above, just below the Component menu item) and selecting the Email form, that unit is then included in the project. The first of two program modifications to be done is the inclusion of a 'Uses' clause, activated by clicking on File | Use Unit..., or by pressing Alt+F11, and selecting the DataModule unit. This enables the Email Unit, when called, to access the database table and use the record that is currently being pointed to in the grid of the main form. The second change to this program unit is a slightly modified one-liner within the procedure TmailerForm.GetSettings as shown above in Project One. Here is the code change note the initial line of code is commented out by the two '/' characters:
//ledTo.Text := ini.ReadString('MAIL','To','');

Figure 4: Project 2: XEStarter - DataModule Unit The second form is the main form for this application, and looks like this:

ledTo.Text

:=

dmStarter.tblMyNamesEmail.AsString;

Figure 5: Project 2: XEStarter - StarterUnit (Main Form)

Februari 2011 BLAISE PASCAL MAGAZINE 15

COMPONENTS
DEVELOPERS

Page 17

Delphi XE Starter tried out with a demo program: a littele Mailserver (continuation 4)

So, when the program is run, the 'To' edit box is initialised with the Email field taken from the selected record in the database table pointed to by the tblMyNames component within the DataModule unit named dmStarter. An example of the end product, when run, is shown as:

A recent article in eWeek.com mentioned the fact that the number of transactions processed by COBOL programs is currently 200 times the number of Google searches each day. So, how many people think COBOL is dead and buried? When people talk about different programming languages, I get a feeling of deja vu going back to the mid sixties, when our 'competitors' said real programmers don't use COBOL, as they were using the somewhat lower level and non-business like Fortran. They were gob-smacked, and rightly so, when our systems were developed and successfully deployed much more quickly and effectively than theirs. Sometimes I see Delphi as the modern day COBOL, because its primary objective is business productivity. Also, both have about the same number of current developers 1.5 to 2 million worldwide. Unfortunately, many people think both are dead how wrong they are.

Figure 6 Project 2: XEStarter - Live Screen When the Send Email button is clicked, the email address of Anthony Dell will be placed in the 'To' edit box, while the remaining settings, such as the 'Host' and 'From' names will be initialised from the .ini file as before. Full documentation for all of the steps involved in this project is beyond the scope of this article, so the project can be downloaded from www.jdduff.net/XEStarterProj.zip. Once downloaded and opened, the various forms, components and source code can be viewed as described above.
Summary

I wish Embarcadero all the best in their marketing efforts to introduce many new members into the Delphi world. Whilst the Starter Edition is one method for doing this, others, such as heavy advertising and introduction into the business and education arenas also need to be brought to the fore. James D (Jim) Duff Long time Programmer and Developer. Machine Code, COBOL, Pascal, Delphi...
jim@jdduff.net

For some years prior to Delphi being owned by Embarcadero, the level of marketing and support was viewed as not being up to standard by many users, many of whom moved on to other products or languages, whilst outsiders thought that Delphi had died. Embarcadero have certainly resurrected the product with the three most recent 2009, 2010 and XE versions, and have raised the confidence of Delphi developers world-wide. There are a limited number of web links in this article, however one can Google any of the keywords used, or any other aspects of using Delphi depending on what elements you are after. Speaking of Google, a newly placed verb in our dictionaries, how many times a day do you Google for something, and how many times a day do you do a financial transaction, either online, or walking down to an ATM (Automatic Teller Machine)?

About the author: Jim is a member of ADUG (Australian Delphi User Group), and lives in Melbourne, Australia. He lives in a city apartment with his wife, Cathy, and has three grown children who live nearby. He has always appreciated the productivity of higher level languages, having learned to program in machine language on an Elliott 803, and then moving straight into COBOL. The logical move to Turbo Pascal and Delphi later followed. He has worked in the software development area of Banking, Finance, Government and IT companies in Australia, New Zealand and the UK. He currently has a small business - where he is also training his son Anthony in Delphi - supplying software to the local motor trade.

Page 18

COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Take off in style with Delphi XE Starte r Edition and TMS Software components
TMS Component Pack
Single developer license Site license 195EU 695EU

productivity software building blocks

Create modern-looking & feature-rich Windows applications faster with over 300 components in one money and time saving bundle. Includes: powerful grid, flexible planner, Windows7, Office 2010/2007/2003 ribbon/toolbars, automatic application update, advanced edits, syntax highlighting memo, controls with HTML formatted text support, touch enabled smooth controls and much much more...

TMS Advanced Charts


Single developer license Site license 75EU 275EU

Sophisticated DB-aware or non DB-aware multipane or multi-serie vertical & horizontal oriented charts. Supports Line, Bar, Area, Band, Stacked Bars, Stacked Area, Pie, Donut, OHLC, Spider, CandleStick, Histogram, Bubble, Cylinder, Pyramid, Error, Digital line charts.

TMS Scripter Studio Pro


Single developer license Site license 175EU 575EU

Add flexibility & configurability to your applications with native Pascal or Basic scripting and full IDE with form designing, object inspector, component palette and more. You can create, design, run and debug script projects which can contain multiple scripts and forms just like a Delphi project.

Visit our website: www.tmssoftware.com | info@tmssoftware.com Fully functional & free trial downloads for Delphi XE Starter Edition

Take off in style with Delphi XE Starte r Edition and TMS Software components

productivity software building blocks

TMS Smooth Controls Pack


Single developer license Site license 95EU 395EU

Set of feature-rich sophisticated looking and smoothly animated controls including calendar, listbox, imagelist, panel, buttons, pagecontrol, LEDs, spinner, jogwheel, gauge, tabpager, trackbar, progressbar, timeline, megamenu, and database aware listbox, imagelistbox, combobox, datepicker & timeline.

TMS Flexcel Studio


Single developer license Site license 75EU 225EU

Powerful, extensive & flexible component suite for native Excel report & file generation. TMS Flexcel allows to generate database & Excel file template driven reports, create Excel files on the fly without needing to have Excel installed.

TMS Advanced Toolbars & Menus


Single developer license Site license 125EU 395EU

Windows 7 scenic ribbon or Office 2010 & 2007 style ribbon control + Office 2003 docking toolbars & menus with support for themes, actionlists, toolbar customization & persistence and much more

TMS Diagram Studio


Single developer license Site license 95EU 395EU

Add diagram and flowchart capabilities to your application. Diagram Studio provides MS Visio-like interface for building diagrams, flowcharts, UML graphs, at runtime, including predefined blocks and open architecture for adding your own blocks.

Visit our website: www.tmssoftware.com | info@tmssoftware.com Fully functional & free trial downloads for Delphi XE Starter Edition

ClientDataset: what to do if you dont have it?


Get kbmMemTable CodeGear Edition its free!
starter expert
DELPHI XE and above (Win32)

By your editor

Here is a short account how to install an equivalent to the Client Dataset - the free kbmMWmemtable items from KBMW. (The starter edition is not equipped with the well known Client Dataset. So because it would be nice to have a similar option I started looking for something similar and quickly found one solution. The kbmMWmemtable is for free and it seemed to be installable. I have succesfully installed it and found it all in good working order. You need of course to download it and register and all of this stuff, but it is well worth it. So to get it you need to go to http://www.myc4d.com and start registering. After that you can make your choices in the left column, and download it.

Installing for a beginner is a bit awkward: you should select the kbmMWmemtable only - during the installation - because then you can get it done. The other options won't work because the starter version has no ADO components etc. and then it would need those components to be installed and therefore its useless to try them.

Figure1: The various screens for registering

Figure2: Make the right choice... The installation so far is very simple. It runs and then will give you a message that its finished. But after that it becomes a little tricky: 2 Files need to be copied from C:\Program Files\kbmMWCG to the BPL directory, usually in XE starter at c:\Program Files\Embarcadero\RAD
Studio\8.0\bin\

The files are: kbmMemDesDXECG.bpl and kbmMemRunDXECG.bpl


Februari 2011 BLAISE PASCAL MAGAZINE 15
COMPONENTS
DEVELOPERS

Page 21

ClientDataset: what to do if you dont have it? (Continuation 1)

Figure 3: The tools and options menu Go to Delphi options and choose "Delphi Options and " Library

Figure 4: Choose Library

Figure 5: Choose library path...


Page 22
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

ClientDataset: what to do if you dont have it? (Continuation 2)

Add the path the installer used to install kbmMWCG (default C:\Program Files\kbmMWCG) to both: the Library search path and the Browsing search path.

Figure 6: Add to the brwosing path After these steps, you are ready to start using kbmMWCG edition. Then you need to change some settings inside Delphi:

Figure 7: Go to Components and choose Install Packages

Februari 2011 BLAISE PASCAL MAGAZINE 15

COMPONENTS
DEVELOPERS

Page 23

ClientDataset: what to do if you dont have it? (Continuation 3)

Figure 9: Showing the added component group

Figure 8: Click the add button Now you will have to add the new component - and only then will you find the components on your palette. Figure 10: The added components You need to add some components; add a data source, a grid and connect them. I dropped all the components because of testing. It is all straightforward Delphi programming: RAD at the best: drag " drop " connect. As you can see I opened a little window by right clicking on the kbmMemTable and found a wonderful set of possibilities. The original client dataset does not have that many features!

Figure 11: Create a new application

Now for testing we do not require much: create a new Visual Forms Application as in Figure 11. Figure 12: The memtable and other components added to the form
Page 24
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

ClientDataset: what to do if you dont have it? (Continuation 4)

Figure 13: The borrowd stucture Here is a new type of fish created: I borrowed the structure from the fishfact databse. The Memtable also can work with DB/BDE and some other files very easily so you don't need ADO.

Figure 14: In design time

Figure 15: The final test: a new sort of fish is introduced... Conclusion: What looked like a loss is turned into a gain: the added component group is even more equipped then we had hoped for. I think it might be worthwhile to do add this kbmMW group to an even higher version: Professional etc...
Februari 2011 BLAISE PASCAL MAGAZINE 15
COMPONENTS
DEVELOPERS

Page 25

LAZARUS, including LAZARUS USB STICK


the complete guide
New: Combination (for our readers) Lazarus USB Stick Portable (Windows) icluding Lazarus Complete Guide - as pocket English action price : 55,00 (bound - does not break) plus 13,50 postage costs Total amount including Postage and USB stick 68 ,50

Graphical User Interface programs for Windows 32 and 64 Windows CE, Mac OS, Unix and Linux

Including

M. van Canneyt, M. Grtner, S. Heinig, F. Monteiro de Cavalho, I. Ouedraogo.


COMPONENTS

LAZARUS: COMPLETE GUIDE

Februari 2011 BLAISE PASCAL MAGAZINE 15

Introduction to Databases Part 2: Common Database Objects


starter expert

By Cary Jenssen

This is the second article in a series designed to introduce you to basic database concepts. In the first article in this series (Blaise Pascal, Magazine 11) I provided an introduction to some basic database architectures, and briefly discussed the components that you use in Delphi to work with databases. In part 2 of this series I will take a closer look at the types of objects that are usually found in a database, and I will discuss the role that they play in database development. As in the previous article, I am going to discuss these topics at a low level, making few assumptions about what you might already know about databases. In this article I am going to focus specifically on relational databases. Relational databases are structured databases where data is spread across a number of different, but related, files. There are other types of databases, such as object oriented databases. However, the major databases that you are likely to use with Delphi, such as ORACLE, MS SQL Server, MySQL, and Sybase ASE, are all relational databases. Even the local file server database that shipped with the original Delphi, the Borland Database Engine (BDE) used Paradox and dBase files, which are also relational in nature.

For example, a customer table might have one column for the customer's account number, another column for the customer's name, and yet another column for the customer's credit limit. While tables with hundreds of columns are not unheard of, in most good database designs a table contains anywhere from a handful to a few dozen columns. The number of rows contained in a table depends on how many "things" you need to keep track of. A table might have just a few rows, but in large databases it is not uncommon to have millions of rows. The column names, the column types (character, integer, decimal, date, and so on), and size (for example, maximum number of characters in a character field) or precision (number of decimal places to store for a decimal field), defines what is called the table's structure.

When the table's structure contains at least one large field, such as memo fields, image fields, BLOb (Binary Large Object) fields, this data is often stored in a separate structure. For example, a Paradox table with at least one memo field consists of two files, one for the non-memo data and one for the memo data. If that table also contains image fields, the image field data is stored in the same file along with the memo data. A typical database often consists of many tables. In a Here is another way to look at it. Delphi's data-related relational database, these tables are usually designed in components are designed with relational databases in order to minimize, or even eliminate altogether, repetition. mind. For example, each record in a customer table holds information specific to one customer. For example, their Common Objects of a Database account number. If the database is designed to hold There are a number of different objects that you find in most relational databases. In some databases, these objects information about product sales, the database contains a separate table for individual invoices. are represented by individual files. For example, in a Paradox database, a table is stored in one or two separate files (depending on whether or not there is large binary or One of the pieces of information that most likely will memo data associated with the table). By comparison, in a appear in an invoice table is the account number of the MS SQL database, all of the data structures are stored in a customer to whom the sale applies. However, the invoice table should not hold the customer's name, since that single file with the MDF extension. How these structures are physically stored is a detail that is information can be looked up in the customer table using the customer's account number, which in this case, must only relevant when it comes to copying a database. As a be unique for each customer. result, I am going to specifically focus on the role played by these objects. In particular, I am going to discuss tables, Using a similar logic, the invoice table will not contain information about individual items sold under that invoice. indexes, stored procedures, views, and user defined Instead, that information will be held in another table, functions. possibly called lineitems, where each item appearing in the lineitems table contains a code for the product sold, the Tables Tables hold the data of a database. From a structural number of that product sold, and the invoice associated perspective, tables consist of rows and columns, where the with the sale. table includes one row for each of "thing" and one column for each piece of information about that "thing." The "relational" part of a relational database is the use of For example, a table of customers will have one row for unique identifiers in two or more tables to associate the each customer, and one column for each piece of records. For example, the customer's account number information that you might want to stored about each associates an invoice with a customer, while the invoice customer. A given table will have zero or more rows (a number in the lineitems table associates a particular table with zero rows is called an empty table), and one or product being sold with an invoice. There's a bit more to it more columns, which are also commonly called fields. than this, but I think you get the idea.
Page 28
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Introduction to Databases Part 2: Common Database Objects (Continuation 1) Indexes Views

Stored procedures, like views, are objects that are stored in the database, and which can be accessed using SQL. However, stored procedures can contain loops and/or conditional statements, providing you with a greater degree of control. In short, stored procedures are shared The second purpose of an index is to quickly locate one or more records based on data in the index. These indexes subroutines that you can call. may or may not be unique indexes, depending on the fields Depending on the database, stored procedures may make used to define the index. Since indexes are already sorted, use of SQL scripts or a proprietary language supported by that database. In nearly every case, however, stored attempting to located records based on the one or more procedures can accept one or more parameters. fields of an index means that the data can be searched Furthermore, they can optionally return either a single very quickly in order to locate the associated records. value (a scalar value) or an entire table of data (or no data The third purpose of an index is to sort the data from a at all). table. Actually, the records of the table are not actually sorted, but an index can be used to display those records What your stored procedure returns is driven entirely by in the sort order defined by the index. your needs. For example, you could replace the two employee -related views mentioned in the preceding section by creating a stored procedure with a name like The fourth purpose of an index is closely related to the GetEmployeesByDepartment, to which you pass the second and third purposes. An index can be used to identifier (Department number, for example). This stored quickly join the data from two or more related tables. Once again, the data from the two or more tables are not procedure could then return a result set that includes the current employee records for the requested department. actually combined, but the index makes it very each to create virtual tables based on the associations between the fields (and indexes) of those tables. This type of operation Here is what a simple stored procedure definition that produces this effect might look like. This particular stored is commonly performed by a SQL query that links data procedure is written in Advantage SQL. from multiple tables, such as those that make use of the JOIN keyword. PROCEDURE GetEmployeesByDepartment Indexes are actually more flexible than I've implied. Most CREATE (DeptNo CHAR ( 4 )) BEGIN databases permit you to create indexes based on DECLARE @DeptNo; expressions, such as an equation formed by two or more @DeptNo = (SELECT DeptNo FROM __INPUT); SELECT * FROM Departments fields and maybe even a function or two. As a result, WHERE DepartmentNo = @DeptNo; indexes permit you to sort, search, and join tables based END; on data derived from the table's fields.
Februari 2011 BLAISE PASCAL MAGAZINE 15
COMPONENTS
DEVELOPERS

Indexes are ordered data structures that add a number of important features to a relational database. To be honest, it would be possible to create a database without creating indexes. But in practice, nearly every relational database has at least one, and in most cases, many indexes for each table. In short, an index is a data structure that holds subsets of the data in your tables, in most cases, about one or more columns. When a table has more than one index, each index is based on either a different column or different collection of your table's columns. The data in each index is sorted, permitting it to be searched very quickly. Indexes serve four distinct purposes, and these best explain why they contains data that also appears in the tables themselves. First of all, an index can be used to prevent duplicate data from appearing in a table. This type of index is referred to as a unique index. For example, in order to ensure that no two customer's are assigned the same account number (which would break the association between a customer and their invoices), the account number column should have a unique index. If you ever try to insert a new record that uses an account number that duplicates one that already exists in the table, or try to change the account number of an existing record to one in use by another record, the unique index ensures that the change will be rejected outright (an exception will be raised).

A view is a SQL query that is stored in the database, and which can be treated like a virtual table. Almost all remote database servers support the creation of views, but only a few local file servers do. For example, Paradox does not support views. However, the Advantage Local Server (a free, local file server version of the Advantage Database Server) does support views when a data dictionary is employed. Views can be as simple as a query that selects only those employees from a given department. For example, there may be one view that retrieves current employees who work for the marketing department, and another view that retrieves current employees from the accounting department. On the other hand, views can be very complicated, including subqueries and joins between many tables, and may even include subqueries or joins to other views. In short, a view can be almost any query (but in most cases cannot include parameters, which are placeholders for values defined outside the query, nor can they contain SQL scripts, SQL statements consisting of two or more separate queries).
Stored Procedures

Page 29

Introduction to Databases Part 2: Common Database Objects (Continuation 2) This stored procedure could be executed by using the following query, assuming that 1001 is a valid department number:
EXECUTE PROCDURE GetEmployeeByDepartment('1001');

Also like views, stored procedures are supported by most remote database servers, but only a few local file server databases.
User-Defined Functions

Special Upgrade Offer for all Delphi, C++Builder and Borland Developer Studio versions until 31 March 2011 - buy your upgrade now We have heard that not all registered users were aware that the upgrade eligibility for users of 2006 and earlier versions of Delphi, C++Builder and RAD Studio/Borland Developer Studio had expired. If you are one of those customers, we want to make it up to you. We have re-opened the upgrade window for a limited time and extended upgrade pricing to you until 31 March 2011. Five Key Reasons to Upgrade to XE today Latest technologies and platform support Get Unicode, Windows 7 support and UI look and feel, the latest database drivers, cloud computing, touch and gesture input, and much more! Work faster and more easily with even more new tools Special editions of CodeSite, AQtime, IP*Works components, FinalBuilder (in the Enterprise edition), plus visual PHP IDE in RAD Studio Get earlier versionsfree XE version includes earlier versions of the tool you buy including Delphi 7, C++Builder 6 and Delphi and C++Builder 2007-2010 Stay eligible for future upgrades to 64-bit and cross- platform Upgrade to XE and be eligible for upgrade pricing to future versions. With exciting plans around 64-bit, mobile, and cross-platform development you will not want to miss out Join the crowd that loves XE Do not just take our word for it, see for yourself what developers are saying about XE Extra Savings on Enterprise Upgrades NOW! As part of this offer, you qualify for special time limited pricing on Enterprise upgrades. Get DataSnap XE with expanded dbExpress database server connectivity, FinalBuilder Embarcadero Edition and all the other great Enterprise functionality at the lowest price yet! Here are some of the amazing upgrade prices that you qualify for: New User Delphi XE Professional C++Builder XE Professional RAD Studio XE Professional Delphi XE Enterprise C++Builder XE Enterprise RAD Studio XE Enterprise 899 899 1399 1999 1999 2799 Upgrade Price 499 499 799 999 999
(regularly 1299)

User defined functions are similar to stored procedures in that they are subroutines that you can write in either SQL or some proprietary language (depending on the database). However, unlike stored procedure, which can return no data, or even an entire table of data, user-defined function always return a single scalar value. User defined functions are designed to be used in queries where an expression is expected. For example, imagine that you have written a user defined function named RandomLimit() that returns a random number between 1 and some number that you pass as a parameter. Consider the following query, which will randomly assign a value from 1 to 10 to the customers listed in the customer table, and order them by this value:
SELECT RandomLimit(10) as Segment, AccountNumber, Name FROM Customer ORDER BY Segment;

Here again, not all databases support user-defined function, though the majority of remote database servers do. On the other hand, most local file servers do not.
Summary

In this second in a series of articles on database development I have turned my attention to five specific objects that are found in most mainstream databases. In the next article in this series I will cover Delphi's TDataSets, with specific focus on the roles played by TFields and TParams.
About the Author Cary Jensen is Chief Technology Officer of Jensen Data Systems, a consulting, training, development, and documentation and help system company. Since 1988 he has built and deployed database applications in a wide range of industries. In addition, Cary is the best selling author of more than 20 books on software development, and winner of the 2002 and 2003 Delphi Informant Reader's Choice Award for Best Training. A frequent speaker at conferences, workshops, and seminars throughout much of the world, he is widely regarded for his self-effacing humor and practical approaches to complex issues. Cary has a Ph.D. from Rice University in Human Factors Psychology, specializing in human-computer interaction.

(regularly 1299)

1499

(regularly 1799)

Page 30

COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Starting out with Advantage Database Server and Delphi XE Starter Edition
starter expert
DELPHI XE and above (Win32)

by Howard Page Clark

The newly released Delphi XE Starter Edition has much to commend it, but perhaps its major disappointment is the lack of versatile database connectivity apart from Interbase Express (if you discount the deprecated BDE). So it is a great help, especially to new and student Pascal programmers who will buy XE Starter if they buy anything to know that Sybase are offering their Advantage Local Server database system for free (if you only want to create local desktop applications) and that it installs effortlessly into Delphi XE Starter. The full client/server Advantage package is priced from just over 200 upwards depending on the licence terms and number of users. You can't argue with a free local database implementation and this enables you to develop very sophisticated data-intensive applications which have no restrictive licences or trial-ware limitations. Although Advantage tables descend from TDataSet and Advantage queries descend from TQuery, the Advantage implementation outshines the deprecated BDE in every respect, while still being easy to learn for those familiar with BDE table, alias and query concepts.

The Advantage server works with several data formats: legacy DBFs (dBase III and above), FoxPro and Visual FoxPro, CA-Clipper, and its own ADT format (which is superior in terms of security and performance, and should be your choice unless you are constrained to work with say a FoxPro database). It can import and export data in many other formats too, including Access MDB, Paradox , Pervasive SQL (Btrieve) tables, CSV, and via OLE DB/ADO various other proprietary formats if you have the appropriate OLE DB provider. Installing into Delphi XE Starter adds a new Advantage page to the component palette (see Figure 2).

Figure 2: The Advantage component page

Figure 1: Installing Advantage Data Architect There are no dbExpress or ADO database components supplied with Delphi XE Starter Edition, which meant I needed to assess options for building a quick database application. I had not used either Interbase or Advantage before, and looking at the learning curve for each it seemed that Advantage was going to be easier for me, since it basically extended what I already knew about BDE databases.
Februari 2011 BLAISE PASCAL MAGAZINE 15
COMPONENTS
DEVELOPERS

Page 31

Starting out with Advantage Database Server (continuation 1)

Any database needs an accompanying utility for creating and restructuring tables, adding indexes, constraints and triggers, importing data and so forth. Advantage installs a Database-Desktop-type utility called Advantage Data Architect, which you might think would be referred to as ADA, but is actually known as ARC. This comprehensive tool (written in Delphi the source is provided) is itself an example of the power and flexibility of the Advantage Server and ADT file format. Advantage works either with free tables (if you need to access legacy databases) or tables that are bound to a data dictionary. Data dictionary tables are the preferred development route, since you can then take advantage (pun intended) of proper database security such as defining constraints for data validation and preventing access to tables except via the dictionary (i. e. you can keep table access restricted only to what you allow through your application). Advantage has full transaction processing capability, with commit and rollback features.
A very simple concordance application

Parsing biblical text is unhidden during parsing and the cursor changes to an hourglass. A fully updated grid gave rise to this end message:

Figure 4 Using adsTable.EnableControls With refresh turned off, parsing performance was noticeably better:

For simplicity in the example developed here no data dictionary is involved, nor is there proper provision for catching exceptions or errors, or fully normalising the data, or polishing the interface or optimising any of the routines. The aim is to show how simple code can develop a useful database application quickly (i. e. before the deadline for this article!) using a combination of Delphi XE Starter Edition and Advantage components and Server. This example uses local data, but it is trivial with Advantage to scale up to client/server remote operation by altering connection parameters to point to a network share recognised by the Advantage server. I wanted to test the Advantage database engine with realistic amounts of data without resorting to meaningless randomly generated nonsense or exposing actual private data from the charities where I work, so I decided to use text data from the public domain, and create a simple concordance for part of the Hebrew scriptures, taken from the American Standard Version (or ASV). This was easy to obtain and needed little in the way of cleaning up to be useable. This raw data was imported into an Advantage table named asv.adt with the following structure:
Field name Type Size

Figure 5 Using adsTable.DisbleControls I had opted for a text-data application because I wanted to explore Advantage's support for full text search, and its dedicated FTS indexes. However, I discovered this is most useful for memo fields and is of value for locating a given text, but no good for generating an analysis of the text which is what this application does. However I did exercise the Advantage Locate() function in this example with a simple implementation of an incremental search via the OnChange event of a TEdit field named edtSearch:
procedure TfrmMain.edtSearchChange(Sender: TObject); begin Screen.Cursor := crHourGlass; with dmAdvantage do if adsTblWords.Locate('Word', edtSearch.Text, [loCaseInsensitive, loPartialKey]) then edtSearch.Color := clGreen else edtSearch.Color := clRed; Screen.Cursor := crDefault; Sleep(1000); edtSearch.Color := clWindow; end;

The performance of this routine was disappointing, probably because of the long character fields and indexes Book char 50 which need to be built for freshly parsed data. If the data ChapterNo integer (4 byte) were normalised and each word assigned a numeric ID it VerseNo integer (4 byte) would doubtless be much faster. Verse char 1000 I wondered if writing my own iterator to visit each record Figure 3: Structures in turn and perform some action would be better than The text in each verse is parsed by clicking the Parse Text using a built-in Locate function. By use of procedural to Words button, which scans asv.adt and inserts each variables (declared to be of object) it is possible to invoke word found into a separate table: words.adt. The any form method on the visited record. The interface of minimum word size to be considered for inclusion is set in the uTableIterator unit is shown here (the implementation a TSpinEdit control which defaults to 4 (thus ignoring if, is equally simple-minded). the, and, very and so on). Refresh of the data grid during parsing is enabled or disabled via a checkbox. To give visual feedback if the grid refresh is disabled a label saying
Page 32
COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Starting out with Advantage Database Server (continuation 2)


type TadTableIterator = class(TObject) private FTable: TAdsTable; public constructor Create(aTable: TAdsTable); procedure Execute; virtual; abstract; end; TadTableIteratorProc = procedure(aTable: TAdsTable) of object; TadTableIteratorFunc = function(aTable: TAdsTable): boolean of object; TadTableIterWorker = class(TadTableIterator) private FprocWork: TadTableIteratorProc; FfuncWork: TadTableIteratorFunc; public procedure Execute; override; constructor Create(aTable: TAdsTable; pWork: TadTableIteratorProc; pCondition: TadTableIteratorFunc); end;

The ADT format has 19 field data types available including Unicode (as UTF16 matching Delphi's implementation of Unicode strings), Date, Time, Autoincrement, CurDouble (an 8 byte currency floatingpoint type), Money (an 8 byte integer type), Memo and Image. In spite of large files (17 MB for asv.adt, and 18.5 MB for words.adt) I experienced no corruption of data or indices such as I have experienced in the past with large Paradox files. It offers true unique indexes for primary key support. If you wish you can access the server directly (without needing the Advantage TDataset descendants) through the Advantage Client Engine API (just as you could make BDE-specific calls using the API for the BDE).

TadTableIterator

TadTableIterator is the ancestor class with an abstract Execute method from which the TadTableIterWorker class descends. By use of both a pWork procedure and a pCondition function it is possible to engineer Execute to operate only on records that satisfy some boolean condition. For instance, to determine the length of the longest word in the table we want a condition that always returns True (so that every record is considered). Whereas for an iteration of the table that is locating perhaps only one record we want a condition that will reject almost every record. I was impressed by how fast the iteration of a 203,634 record Advantage database proved to be (just a second or two). The full code for this example application is available for download from the Blaise website. I quickly discovered using this routine that the longest book name had 14 characters. So providing for 50 characters in the table design was clearly too generous. However, I was only able before the deadline to prepare ASV data from the books Genesis to Psalms, and it may be in covering the other Hebrew books (Proverbs to Malachi) that longer book names will be encountered. This project is far from complete. I plan to add other public domain versions (King James, in this 400th anniversary year, Jewish Publication Society version and others), and do quite a bit of normalising of data and construction of more intelligent indexes, adding SQL queries for comparisons and so on. My experience with Advantage certainly leads me to want to use it as the default database engine for accompanying Delphi Starter Edition. Questions I had were usually resolved quite quickly from the help file that comes with the package. This includes the text of an entire book (Advantage Database Server v8.1: A Developer's Guide) about Advantage written by Cary Jensen and Loy Anderson. The book is well written and comprehensive including use of Advantage in Visual C# and Visual Basic and with Java, PHP and .NET. Together with the many other pages of documentation I hardly needed to go online at all.
Februari 2011 BLAISE PASCAL MAGAZINE 15

Figure 6: The test application reporting via a table iterator It was gratifying to see that Advantage include a Lazarus package in the download, and I tried this out briefly. Since components are linked statically in Lazarus the IDE has to be recompiled to add them to the IDE. Initially I found that the recompiled Lazarus ran briefly and died. I think this was because it could not find the Advantage server. Downloading the server enabled the recompiled Lazarus IDE to work normally. However a full comparison has not been attempted between Delphi XE Starter and Lazarus.
BDE

The BDE has been frozen since Delphi 7, and considering its problems running on Vista and Windows 7 it is surprising that Embarcadero bothered to include it in the Delphi XE Starter Edition. 'Deprecated' ought to mean it is no longer part of new releases.
COMPONENTS
DEVELOPERS

Page 33

Starting out with Advantage Database Server (continuation 3)

Figure 7: The import data formats supported by ARC

Advantage is actively developed and includes all the database functionality a user of the Starter Edition could want. It is a very good match, and the Local Server is priced to be attractive to everybody. ARC is a stable and versatile tool, easily used by people familiar with Borland's Database Desktop or the Lazarus Data Desktop or FlameRobin. It can access and modify both FoxPro and Clipper DBF formats and also supersede their well-known limitations. For example, the maximum field name length is 10 characters, deleted records are merely marked for deletion (and can still be accessed up until a table is packed), unique indexes do not enforce record uniqueness, and memo files can include large amounts of wasted space. The ADT format avoids all these shortcomings, and adds data dictionary functionality, encryption and access security for good measure. If you have Delphi XE Starter Edition and are looking for a good database solution, you would be foolish to ignore the download of the free Advantage Local Server. You can find it here:

www.sybase.com/products/databasemanagement/advantagedatabaseserver/delphi-components

BOOKS FROM MARCO CANT COMBINED INTO ONE PDF

A single PDF bundling together 3 ebooks: Delphi 2007 Handbook, Delphi 2009 Handbook, and Delphi 2010 Handbook. The material has not been edited, it is simply the merging of the three original ebooks. The collection of books covers all of the new features of Delphi 2010 since Delphi 7, covering the IDE, the Delphi language, Unicode support, Windows development, new VCL components, database access, DataSnap, and much more. In total the combined book has almost 1,000 pages of Delphi-related content, in a single easy-to-search PDF file.
http://sites.fastspring.com/wintechitalia/product/delphihandbookscollection

Page 34

COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Moving /adding your components into the Delphi Starter Edition?


By Rick Smit
starter expert
DELPHI XE and above (Win32)

In this very simple and short article we explain how to move or install components, whether older components or new ones. This is very easy, and can be achieved with just a few mouse clicks. Embarcadero has done a great Job by that. Anyone can do this. So there is no need to worry about losing your older components. But be sure to to make a backup! In a new environment you can use one of your old programs or make a brand new one to discover all the new possibilities. In both cases it might be convenient to have your own components available. So how do you install components in the new small Delphi XE Starter Version? You could do it slowly like a snail, or quickly like a rocket launch.to do the job. Lets start with the rocket method.
Start:

Figure 1:main-menu item Component In the subsequent Install VCL Components dialog, you must complete the path to your component directory, and specify whether to add them to a new or an existing package (Figure 2). With the ellipsis button you can browse the path to the component of your choice. (Figure 3) Choose Openen to get the install window.(Figure 4)

Choose in the main menu the item Components and then choose: " Install Component. See Figure 1 at the right top:

Figure 2: Use the ellipsis to browse your files

Figure 3:Select the Component files

Figure 3:Select the Component files


Februari 2011 BLAISE PASCAL MAGAZINE 15
COMPONENTS
DEVELOPERS

Page 35

Moving /adding your components in to the Delphi Starter Edition? (Continuation 1)

Figure 4: Choose for Install into a new package In the next window (Figure 5) we have to give our new package a name. This is the name we will see in the Tool Palette. By the way you can always rename it in the Tool Palette by rightclicking the category name. Give it a clear description and choose Delphi package. Click Finish and if the source is correct then all the work is done for us. (Figure 6) Now we can use our new installed component(s), see Figures 13 and 14 at the end of this article. And now the slow way. The slow way means that we have to do a lot of the work ourself. We have to know that we have to put our component(s) files into a container called a package before we can register them into the RAD studio.

Figure 5: The install into new package window

Page 36

COMPONENTS
DEVELOPERS

Februari 2011 BLAISE PASCAL MAGAZINE 15

Moving /adding your components into the Delphi Starter Edition? (Continuation 2)

Figure 6: The package is installed and the component is registered. So here are the steps we are going to do: 1 Create a new package, (Figure 7) and view it in the IDEs Project Manager (Figure 8). 2 Install one or more component(s) into the package container (Figure 9). Browse towards the files we need (Figure 10). 3 Rename the package with the name we want. You can see it as category in the Tool palette (Figure 11). 4 Save the package. 5 Install the package (Figure12). Step 2 To add something to it we need to rightclick the mouse pointer over Package1.bpl. In the next pulldown we choose Add (Figure 9) and browse the next window (Figure 10) towards the component files and pick Open. Step 3 Rightclick the mouse pointer over Package1.bpl and click Rename to give the package1 the name you want to see as a category on its tab in the Tool Palette. Step 4 Use the same window to Save it.

Figure 7: The new Package

Step 1 Choose in the main menu the item File "New "PackageDelphi. (Figure 7) and you will find the brand new Package1.bpl in the the IDEs Project Manager (figure 8)

Figure 8: The empty package in the IDE Project manager In figure 8 we see that the contains of package1 are empty.
Februari 2011 BLAISE PASCAL MAGAZINE 15

Figure 9: Add content Now we can see the renamed package PascalGG.bpl, with the TColorButton component inside. (Figure 11 next page)
Page 37

Moving /adding your components in to Delphi Starter Edition? (Continuation 3)

Figure 10: Browse the component (ColorButton) source file Step 5 The last step is to finally install the component: right click PascalGG.bpl, choose Install and your job is done. To see the result: Open File " New " VCL Forms Application and take a look at the Tool palette: the new category with the component is available. (See Figures 13 and 14)

Figure 11: Contains has been filled, and the package renamed from package1

Figure 12: Install the PascallGG package


Page 38

Februari 2011 BLAISE PASCAL MAGAZINE 15

Moving /adding your components into the Delphi Starter Edition? (Continuation 4)

So as you can see: the Job is done. The Color button is available. Have fun trying it out. At our website we have several components that can be used. Of course you need to be a subscriber or become one first... Figure 13: The Old Tool Palette Figure 14: The new Tool Pallette www.blaisepascal.eu

Februari 2011 BLAISE PASCAL MAGAZINE 15

Page 39

THE WORMHOLE FOR DATABASES AND SERVICES


ESB, SOA.MoM, EAI TOOLS FOR INTELLIGENT SOLUTIONS IN COMPONENTS THE NETHERLANDS: UTRECHT / PREMIERE DE MEERN SATURDAY SEPTEMBER kbmMW IS THE N-TIERE PRODUCT FOR18 DELPHI< C++BUILDER BDS DEVELOPERS DEVELOPMENT FRAMEWORK FOR WIN 32, .NET AND LINUX WITH CLIENTS RESIDING ON WIN32, .NET, INFORMATION: www.blaisepascal.eu LINUX,UNIX MAINFRAMES,MINIS,EMBEDDED DEVICES

You might also like