Blaise8 UK AllDownload

Embed Size (px)

DESCRIPTION

Blaise8 UK AllDownload

Citation preview

  • BLAISE PASCAL MAGAZINEPascal8

    October 2009Publisher: Foundation for Supporting the Pascal Programming Language

    in collaboration with the Dutch Pascal User Group (Pascal Gebruikers Groep) Stichting Ondersteuning Programeertaal Pascal

    Cover price Europe: 10.00 / UK 10.00 / US $ 10.00

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

    Delphi 2010 what a feeling! - page 7Gestures could be the new must in our computers future

    Counters - page 11 Learning counting again, - could wel be a hobby...

    Virus in Delphi? - page 14Nick explains how to get rid of the virus and block it.

    Dezign for databases - page 16A fantastic alternative for its expensive competitors, and its even cheaper.

    Customizing the T-Field data display - page 18Diving deeper into the possibilitys

    Using Free Pascal and Lazarus to create applications for OSX - page 20Working on the Mac is hot

    Writing Delphi Components II: Custom Properties and Windows Controls - page 22

    In the new Delphi versions it looks all different.My Top Five Delphi 2010 New Features - page 24

    Except for guestures ther is a lot of news...Fast Graphic deformation by using Scanlines - page 28

    Control your own image or blow it up! Berlusconi on the edge Wide Information Bus (Introduction) - page 33

    What is it and what the use for it? Freehand Drawing (Introduction) - page 36

    shows how to create your own paint program

    Bob Swart

    David Dirkse

    Nick Hodges

    Marco Roessen

    Henk Schreij

    Jeremy North

    Marco Cant

    Pawel Glowacki

    Peter Bijlsma

    Fikret Hasovic

    David Dirkse

  • Page 2 / 2116 COMPONENTSDEVELOPERS 4

    Articles

    Columns

    in the pdf file: click and you go straight to the download link

    Foreword, page 4

    is prolongued until november

    Advantage Database Server page 3Components for Developers page 40Datanamic page 6Fastreport for VCL page 38Fastreport for .Net page 39RT science page 15

    = Code Downloadable

    DELPHI CONTEST

    Books - View at the new Windows 7 page 5

    Frans Doove

    Advertisers

    Editor in chief

    News and Press Releases

    Authors

    Editors

    Translations

    Copyright Trademarks

    Caveat

    Subscriptions

    ABN AMRO Bank Account no. 44 19 60 863 or by credit card: Paypal or TakeTwo

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

    Subscription department

    Detlef D. Overbeek, NetherlandsTel.: +31 (0)30 68.76.981 / Mobile: +31 (0)6 21.23.62.68

    email only to

    N Jeremy North,O Tim Opsteeg,

    V Hallvard VassBotn.

    A.W. (Bert) Jonker, M. L. E. J.M. (Miguel) van de Laar

    M. L. E. J.M. (Miguel) van de Laar, Kenneth Cox (Official Translator)

    (prices have changed)

    (including code, programs and download magazine)

    or by written order, or by sending an email to

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

    [email protected]

    www.blaisepascal.eu [email protected]

    [email protected]

    BC Marco Cant, D David Dirkse, Frans Doove,G Primo Gabrijel! i! ,

    P Herman Peeren, S Henk Schreij, Rik Smit, Bob Swart,

    Rob van den Bogert, W. (Wim) van Ingen Schenau,M.J. (Marco) Roessen.

    See the notice at the bottom of this page.All trademarks used are acknowledged as

    the property of their respective owners.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.

    1: Printed version: subscription 50.-- (including code, programs and printed magazine, 4 issues per year including postage.

    2: Non printed subscription 30.--

    Subscriptions can be taken out online at

    plus postage.

    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:

    Edelstenenbaan 21 3402 XA IJsselstein, The NetherlandsTel.: + 31 (0) 30 68.76.981/Mobile: + 31 (0) 6 21.23.62.68

    Peter Bijlsma,

    Corrector

    Subscriptions are parallel to the calender year.

    Cover price in Europe: 12.50 / UK 12.00 / US $ 18.00

    Foundation for Supporting the Pascal Programming Language (Stichting Ondersteuning Programeertaal Pascal)

    Volume 8, ISSN 1876-0589

    BLAISE PASCAL MAGAZINE 8CONTENTSALL ABOUT DELPHI AND DELPHI PRISM(.Net) ,LAZARUS & PASCAL AND RELATED LANGUAGES

    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.

    Copyright notice

    October 200 9 BLAISE PASCAL MAGAZINE 8

    Delphi 2010 what a feeling! - page 7Gestures could be the new must in our computers futureCounters - page 11 Learning counting again, - could wel be a hobby...Virus in Delphi? - page 14Nick explains how to get rid of the virus and block it.Dezign for databases - page 16A fantastic alternative for its expensive competitors, and its even cheaper.Customizing the T-Field data display - page 18Diving deeper into the possibilitys Using Free Pascal and Lazarus to create applications for OSX - page 20Working on the Mac is hotWriting Delphi Components II: Custom Properties and Windows Controls - page 22In the new Delphi versions it looks all different.My Top Five Delphi 2010 New Features - page 24Except for guestures ther is a lot of news...Fast Graphic deformation by using Scanlines - page 28Control your own image or blow it up! Berlusconi on the edge Wide Information Bus (Introduction) - page 33What is it and what the use for it? Freehand Drawing (Introduction) - page 36shows how to create your own paint program

    Bob Swart

    David Dirkse

    Nick Hodges

    Marco Roessen

    Henk Schreij

    Jeremy North

    Marco Cant

    Pawel Glowacki

    Peter Bijlsma

    Fikret Hasovic

    David Dirkse

  • Page 4 / 2118

    ForewordThe summer holidays are over and we all are back to business. For us as editors, things were a bit different. Due to all the extra work with the special issue and publishing the first Portuguese edition, we had to abandon our holiday plans.

    Now we have reached issue eight, with some very interesting articles about the new Delphi 2010 which I think is the best yet and a nice article about how to morph your own portrait. Just for fun, we did this with a picture of Berlusconi, an interesting politician whom claims to be the ultimate defender of freedom. But the coding is also very interesting.

    With Delphi 2010, we all hoped there would be the first cross compiler for Linux and Mac.Too bad. It didn't work out that way. We still have to wait.

    There are some major improvements: The help file is better than ever: easy and quickly accessible, more items, more specific about Delphi and one thing I do love particularly is the tagged button bar with the components - classic, but very effective. Great. The total program is much faster and more stable. Its very much faster to install, it was quite annoying with 2009. But

    Now some things that aren't so good. For Delphi to be attractive to a very large group of programmers, two major changes are necessary.

    First, a cross compiler must be available as soon as possible. Very soon.

    To illustrate my point: in order to better understand object oriented aspects of programming I took a course on Java at the University of Amsterdam. Besides learning a lot and obtaining insight into many issues, I soon realized how much we are pampered with our Delphi IDE.

    Java still does not have anything comparable to RAD. Java is a beautiful language, but it cannot compete withDelphi (Pascal) : it's not fast, , coding is labour-intensive, its graphic support is not very sophisticated and what sometimes is forgotten, at low level the Java compiler is almost never competitive in terms of speed and there for it is almost impossible to run technical applications at low (engine) level.

    But it runs on a lot of Platforms.- which is nice until you discover that under Linux the Eclipse environment moves at a snail's pace.

    However, one thing is true: Write once, Run anywhere.That's what we are missing badly. Espacially for the Mac. We need the future and the future is twofold: multi O.S. and Internet.

    Second,it's nearly impossible for beginners to get acquainted with Delphi. There's the 30-day trial version, but you can't learn Delphi in 30 days. This is not only bad; it's short-sighted.

    I can easily imagine that Codegear is very busy creating the next generation - which is why we would like to suggest to Embarcadero: if you dont have the time or man power to produce a special version, please offer international user groups - with registered members to purchase an educational license.

    Nothing needs to be changed, perhaps there could be some sort of splash screen: 'Licensed exclusively for non-commercial use'. Leave it up to the user groups to determine which of their members are eligible for this version. With this, we would be in a position to convince people of the enormous quality of Delphi.

    It is nonsense to think that people can't get their hands on a pirated copy: the internet is huge. You should trust people. Most of them don't want a pirated copy; they use it in their work or their hobby, and they want their own, legal copy but at an acceptable price. People who use it professionally should pay the commercial price, but students (of Delphi), hobbyists and starters should be able to have ready access to a less expensive version.

    Two years ago, when Embarcadero took over Codegear, it was promised to me personally. I was very enthusiastic. But now, going into the third year, there is still nothing available. I regard this as unacceptable.

    I sincerely hope that this problem can be resolved quickly.

    Detlef Overbeek,

    We need the starters and beginners.

    e-mail: [email protected] Detlef.Overbeek+ 31 (0)30 6876981mobiel + 31 (0)6 21.23.62.68

    COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

    by Detlef Overbeek Editor

  • Page 5 / 2119COMPONENTSDEVELOPERS 4

    After getting acquainted with a sizeable new book, I often arrive at the conclusion that the there is a direct relationship between the size of the book and the degree of difficulty of the software forming the subject of the book (and I also had this fear with the present book). This conclusion arose from my experience with comparable books on Windows Vista.I must admit that I was not previously acquainted with any books by this author, but it turns out that he has written a large number of books on similar subjects.

    As a native Dutch speaker, I found the title somewhat puzzling at first. According to my EnglishDutch dictionary, 'unleashed' has several possible meanings, and the examples include a flood of words and venting your rage. My impression is that the author did not have the latter intention in mind, but instead aimed to write an introduction to a new, complex and extensive bit of software that can do a lot of things and hopefully will cause fewer problems than its predecessor.

    The first thing that struck me about this book was its extensive table of contents. First there is a high-level overview on two pages divided into seven sections, followed by a full table of contents of the 31 chapters that extends over fourteen pages and is in turn followed by a seven-page introduction.

    I consider such an extensive table of contents extremely important as an introduction and an aid to studying the book, and especially useful to obtain an overview of the topics addressed by the book and thereby the capabilities of the software it describes. Naturally, it is difficult to master a subject discussed in a book totalling nearly 800 pages, and the table of contents is an essential aid in this regard.This book is actually an extensive user's guide to Windows 7. My impression is that the author does not assume that readers are fully familiar with the previous version of Windows, but instead aims the book at all users.The book consists of 31 chapters and two appendices, grouped into in seven sections. The sixteen-page table of contents gives an overview of the topics discussed in the book

    Here it is evident that the author has the reader in mind; he writes for both IT professionals and home users of the software.Part 1 (Chapters 15) lets the user get acquainted with this version of Windows and become familiar with it.Part 2 discusses the maintenance of the Windows 7 system.Part 3 discusses relatively advanced topics.Part 4 discusses security aspects, Part 5 addresses problem solving, Part 6 deals with networking, and Part 7 discusses scripting.

    My opinion of this book is very positive. It has many extensive and clearly worded explanations, as well as many code examples and overviews.Readers have the option of registering the book. When a definitive version of Windows 7 is released, registered readers will receive an updated version of the book free of charge, along with all the examples and code in the book.As far as I can determine, at the time of writing of this review this is the only book on Windows 7 that is actually available in English or Dutch, although dozens of books on Windows 7 (in English) have been announced.

    Book reviews by Frans DoovePaul McFedries: Microsoft Windows 7 Unleashed

    2010, Pearson Education ISBN 13: 9780672330698ISBN 10: 0672330695

    English; paperbound, 791 pages (including table of contents).Recommended price: 40.

    William R. Stanek: Windows 7 Administrator's Pocket Consultant

    2010, Microsoft Press, ISBN 978 07356 6007, English, paperbound, 680 pages. Recommended price: 30.

    This book has an introduction and seventeen chapters. Each chapter consists of roughly 40 pages, which is a consequence of the systematic approach.The principal target group of the author is not individual users of Windows 7, but instead system administrators. The author further differentiates this group into administrators who already work with Windows, users with a certain amount of responsibility for computer administration, and administrators who migrate to Windows 7 from an earlier version of Windows or from an entirely different system.

    However, I think that individual users can also use this book to considerable benefit, although the book devotes more attention to the everyday activities of system administrators than to the specific aspects of Windows 7. These aspects are actually embedded in the text, but I fear that this makes the book more difficult for individual users, despite the fact that the text has an open and accessible style.

    October 200 9 BLAISE PASCAL MAGAZINE 8

  • Page 6 / 2120

    The book begins with an extensive table of contents for the seventeen chapters, grouped into sections. It occupies seventeen pages. I always find an extensive and readily comprehensible table of contents a very positive feature, not only because it gives the reader a quick overview of the book and makes it easier to find everything, but also because it helps the reader grasp the subject matter. I regard this as extremely important from a learning perspective.

    The following capsule description of the contents is intended to give an idea of how the author presents the topics. Chapter 1 provides an introduction to Windows 7, including installation and architecture. Chapter 2 discusses working with Windows PE (the replacement for MS DOS) and the recovery environment (RE).

    COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

    Book reviews (continuation)

    Chapter 3 deals with major topics such as user policies and computer policies, which are the rules that govern the users and the computer for activities such as using a network.Chapter 4 is dedicated to automation of the Windows 7 configuration.Chapter 5 discusses the administration of user access and security. Chapter 6 deals with configuring computers under Windows 7. Chapter 7 discusses the configuration of Windows 7 features and options, which differ from those of previous Windows versions. Chapter 8 discusses the operation of the hardware devices (options) and drivers. Chapter 9 deals with program installation and maintenance.

  • Page 7 / 2121

    One of the new features of Delphi 2010 is the native support for touch, gestures and multi-touch (supported by Windows 7). Although it has always been possible to support simple touch in Delphi applications, where the touch screen simply emulates a mouse (so you can touch the buttons on the screen without using a keyboard or mouse), it was not yet possible to have Delphi (out-of-the-box) respond to special gestures or multi-touch events. These features are now possible with the release of Delphi 2010, and hence the topic of this article.

    In order to play along, you need a copy of Delphi 2010 (you can download and install the 30-day trial edition if you wish). Start Delphi 2010. In order to create a new application, I do File | New Other, which brings me to the Object Repository. This is the first area where we can see some changes already: a handy filter option at the top, to hide the icons and wizards that I'm not looking for. Just enter a few characters like App in order to filter the contents of the Object Repository down to the App-specific icons and wizards. A nice way to help me find my way without getting lost in the dozens of items.

    This filter is especially important now that the Object Inspector shows all icons in all catagories, even when they are not applicable at this time (for example in the ActiveX category, where a number of wizards cannot be used until an AxtiveX library project has been created first). The benefit is that you will always see what's possible, even if it's not applicable just yet. The filter will also hide these items, although this is not visible in the screenshot above.After starting a new VCL Forms Application, we first continue by building a small database application. Just use a TclientDataSet in order to produce a stand-alone executable (without the need for database drivers). As data contents, I'd like to show the biolife table, which can be found in the biolife.xml file in the Common Files\CodeGear Shared\Data directory (in the future this might become the Common Files\Embarcadero Shared\Data directory perhaps).As soon as the FileName property of the TClientDataSet component is pointing to the biolife.xml file, we can use the Object Inspector to set the Active property of the TClientDataSet to True to show all data at design-time. By clearing the FileName property while Active is set to True, the data remains visible, but this time we force the data to be stored in the DFM file itself, and no longer outside of the application. This is a special trick that I use every now and then, to embed the data inside the executable. Note that there are consequences to this approach: first of all, the DFM file will become about 2 MB in size (so it takes a while to save or compile the project especially the linking stage). Second, and sometimes worse, is the fact that since the data is embedded in the executable itself, you cannot make any changes to the data. This may often be a show stopper, unless you're building a brochure or catalog that you don't want or need people to change anyway (like a city plan with pictures for example). For our demo, I'm assuming we do not need the biolife data to be changed by the user, so we're on our way to produce a standalone executable indeed.

    Biolife FieldsWith the data persistent in the TClientDataSet, we can double-click on this component to start the Fields Editor. Right-click in the Fields Editor and select Add All Fields to see the available fields from the biolife table in the Fields Editor. In order to see them all (except one) on the form, we can simple drag them from the Fields Editor and drop them on the form. All, except for Length_In, which I don't need (unless you don't use centimetres as your measurement type, in which case you could decide to skip the Length (cm) field instead of course). Each of these fields will be transformed into a label and data-aware control when dragged onto the form. Most fields will end up being represented by a TDBEdit control, with the exception of Notes (inside a TDBMemo) and Graphic (in a TDBImage). After moving the TDBImage controls around, my version of the form looks as follows:

    Touch and ActionSpeaking of touch: now we're getting to the interesting part of the article: the touch and gesturing support in Delphi 2010. We need to start by adding a TActionList component on the form. This will help to connect gestures to (standard) actions later. Delphi 2010 already contains a number of pre-defined gestures, which can be connected to actions (saving a lot of work compared to writing individual event handling code), as I'll show shortly. The TActionList component does not have to be filled with (standard) actions right away, because we can do that on the fly (when needed). However, we do need a special TGestureManager component on the form as well (see screenshot above), and we should assign this TGestureManager component to the GestureManager subproperty of the Form's Touch property.

    Gestures Using the Object Inspector, we can expand the Touch property in order to view the GestureManager subproperty (assigned to the TGestureManager control on the form). We also see a Gestures subproperty, with a list of standard (and later also custom) gestures supported by Delphi 2010. The list of standard gestures starts with Left, Right, etc. Next to each gesture in the Object Inspector, we see a checkbox (to indicate that the gesture is hooded to an action or event) as well as a little drawing that depicts the gesture movement (albeit without direction, so the horizontal line for Left and right looks the same).For each gesture we can use the Object Inspector to create a New Action (for which we then need to implement the OnExecute event handler), or we can select an existing standard action (which is then added to the TActionList component). For our example, let's connect the Left gesture to a Standard Action from the Database category, namely TDataSetPrior (in order to move to the previous record). The screenshot on the next page shows the different submenus that have to be used to connect the TDataSetPrior action to the Left gesture.

    by Bob SwartDelphi 2010 what a feeling!

    Figure 1: to start with

    expertstarter DELPHI 2010 / Win32Touch en Gestures

    Figure 2: Note that I'm not using a TDBNavigator control on purpose, since I want to use the touchscreen with the simple touch and gesture functionality for navigation.

    COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    Delphi 2010 has just been released at the time of writing see and for more

    information and ordering possibilities of Delphi 2010 en RAD Studio 2010.

    http://www.eBob42.com http://www.bobswart.nl

  • Page 8 / 2122

    After we've connected the Left gesture, it's just as easy to connect the Right gesture to the TDataSetNExt action, the ChevronLeft gesture to the TDataSetFirst, and the ChevronRight gesture to the TDataSetLast action. The two chevron gestures can be compared to bigger than and smaller than characters, but then drawn with your finger on the touchscreen.

    The only thing left to do is compile the project and run it. If you have a touch screen (like the LG L1510SF 1024x768 Flatron that I purchased for a good price) then you can move your finger over the screen to make the gesture movements required. If you do not have a touch screen, then you can still emulate this behaviour by using the mouse: click with the left mouse button and drag the gesture movement around the screen. It's not the same, but at least you can test your gesture movements without the need to purchase a touchscreen yourself. Either way, you can use the Left, Right, ChevronLeft and ChevronRight gestures now to navigate through the records of the biolife table without the need for a keyboard or TDBNavigator control.

    Apart from the built-in standard gestures, we can also create our own custom gestures with Delphi 2010. This can be done with the TGestureManager control: right-click on it, and select Custom Gestures. Inside the dialog that follows, you can click on the Create button to create a new gesture, where you need to move your finger over the touch screen (or drag with the mouse) to draw the initial path of the gesture. Once the initial path is drawn, we can still make some modifications to it, to ensure it will be recognised correctly. As an example, let's draw the Z character (see next screenshot), and give it the name Zorro

    Action!

    Custom Gestures

    (a famous tv-character in The Netherlands about an outlaw hero who uses his sword to draw a Z on the chest of his government victims) When making custom gestures, it's important to realise that the gesture must be one fluent movement. As a result, you cannot make an X gesture, since that requires two separate gestures. For the X-gesture that I created, I had to change the sensitivity, which is set to 80% by default, to ensure that it's easily possible to have the Z-gesture be recognised when drawn on screen by an end user.

    Figuur 4: zorro is in the air?

    Figure 3: the steps to get to the list of gestures

    COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

    Delphi 2010 what a feeling! (continuation 1)

  • Page 9 / 2123

    If an unrecognised gesture is made, then the GestureID is equal to 0 (which may be an indication that you need to work on the sensitivity of your custom gestures, or explain more clearly how the users should make their gesture).We have to remember for ourselves what the ID values are of our custom gestures, of course. Fortunately, there is also another way to connect an action to the custom gesture. If you take a look at the third screenshot again, you'll see the Object Inspector with the Touch property and the Gesture subproperty.

    COMPONENTS

    DEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    Delphi 2010 what a feeling! (continuation 2)

    procedureconst var Boolean

    beginif thenelse

    end

    . ( : ; : ; : ); . = - ( ) ( ( . ))

    ;

    TForm1 FormGesture Sender TObjectEventInfo TGestureEventInfo Handled

    EventInfo GestureIDShowMessage

    ShowMessage IntToStr EventInfo GestureID

    1'Zorro'

    After all this work, it's very fortunate that we do not have to draw the custom gestures for each new application, but we can simply store (export to a .dgf file Delphi Gesture File) and load or import the .dgf in the TGestureManager of another application again. Once we have a custom gesture, we can work with it (i.e. respond to the recognised gesture) in two ways. First of all, we can use the OnGesture event of the form itself. In this event handler, we get the EventInfo of type TGestureEventInfo, as well as a var parameter Handled to indicate when set to True - that we've handled this gesture.Note that we will only get inside the OnGesture event handler if we didn't make one of the standard and already connected gestures such as the Left, Right, ChevronLeft or ChevronRight gestures.When inside the OnGesture event handler, we can use the EventInfo.GestureID field to identify the ID of the custom gesture. In our case, that value was -1, so my event handler can be implemented as follows:

    Figure 5: Zorro is listed now

    A high sensitivity requires that you redraw the blue dots exactly, and lower sensitivity extend the grey area around them (until it gets too fuzzy where you might confuse one gesture with another). We can also use the Custom Gesture dialog to remove dots from the gesture line, add new dots, zoom in and/or out, modify the coordinates and play a simulation of the gesture, as well as a test where you need to redraw the gesture to see if it is recognised correctly. It may take a while, but in the end you will have a near perfect custom gesture.When you click on OK, you are returned to the Custom Gesture dialog of the GestureManager component where a preview of the gesture shape is drawn as well as the name we've given it, and the ID (which starts by -1 and counts further down).

  • Once the gesture is connected to a custom action and its OnExecute is implemented, the Ongesture event handler of the form will no longer respond to his Zorro gesture (have a try for yourself if you wish).Running the demo project we've created so far and which I've called Touching Biolife does not show a GUI different from a normal non-touching GUI. If you take a look at the next screenshot, there's no indication (yet) we're dealing with a touch- and gesture-enabled application. The lack of a TDBNavigator may lead you to wonder how to navigate to the next record, but that's about it.

    Figure 7: now you can try

    Sweeping your finger over the screen from left to right (for the next record) or from right to left (for the previous one) may be a bit strange at first, but you'll quickly get the hang of it. The effect is of course much nicer if the form would contain a city map or street plan, where you can move the map around with your fingers. This can also be done with gestures, and even better with the so-called Multi-Touch support which can be found in Windows 7 (but which also requires special, more expensive, hardware). Using Multi-Touch and interactive gestures, the EventInfo structure of the Ongesture event will hold field values for the inertia (speed of the gesture), as well as the start and stop coordinates of the gesture. Since this is only supported by Windows 7, in combination with special hardware compatible with the multi-touch and interactive gestures, I'll leave an example behind for now (until I can get my hands on the special multi-touch hardware that is).

    The following screenshot shows the TTouchKeyboard on my machine, using the US-International keyboard layout, at the bottom of the Touching Biolife form:7 Obviously, placing the virtual keyboard at the bottom of the form is not a very effective way to handle input. It would be more convenient to use some kind of pop-up dialog that shows the virtual keyboard only when needed for example. But once the virtual keyboard is shown, we can use the keys on the screen as touch buttons and click on the keys to produce the input text. And if you have no touch screen but a mouse attached to your machine, then you can obviously still use the mouse to click on the buttons (so as a software developer you do not need to have a touch screen to work with the TTouchKeyboard only when it comes to multi-touch and interactive gestures you need Windows 7 and the special hardware).

    Figure 8: the virtual touchpad

    Deployment

    Bob Swart

    A final word: in order to turn the current demo application into a really standalone executable, we should add the MidasLib unit to the uses clause of the project, so we do not need to deploy the MIDAS.DLL. This results in a truly standalone executable that we can place on a USB-stick for example in order to show an application that doesn't need mouse or keyboard in order to run.

    procedurebeginend

    . ( : ); ( )

    ;

    TForm1 Action1Execute Sender TObject

    ShowMessage 'Zorro also likes to touch Delphi 2010'

    Right below that, the standard gestures are listed. However, as soon as we add a custom gesture, a new entry Custom is shown in the Object Inspector right above the standard gestures. Custom contains the list of (currently only one) custom gestures that have been added to the TGestureManager. In this case, just the Zorro gesture, including the image preview of the Z, as we saw before in the Custom Gesture dialog.This means that we can now make a connection between the gesture and an action. In this case, I'd like to create a new action, select this action in the Object Inspector when done, and then implement the OnExecute event handler of the new action, for example as follows:

    Touch KeyboardOne more thing I can show you is the final step to make the application completely independent from mouse and keyboard: for deployment in a kiosk or bus station for example. Since these applications sometimes still need some textual input, Delphi 2010 contains a special TTouchKeyboard component. One which shows the keyboard layout for the current locale (which means that users from France will get the accents available on the keyboard when they need them).

    Delphi 2010 what a feeling! (continuation 2)

    Page 10 / 2124 COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

    To get more information about Delphi 2010 licenses, please see my website at http://www.bobswart.nl/CodeGearor send me an e-mail at [email protected] (also to ask about subscription or renewals).

    Bob Swart - is Reseller for BeNeLux (Belgium Netherlands Luxemburg)

  • This article covers some fundamental arithmetic operations in ICT applications with emphasis on the operators mod and div.

    Computers are only able to handle numbers. Only problems that are expressable in numbers can be solved by a computer.In daily life , numbers may be grouped in the following categories:

    Arithmetic and math start with counting.Below, a simple counting device is pictured

    It is not interesting how this counter performs it's functions. It may be mechanical, by pinwheels, electronical or electro-mechanical using relays.The reset signal forces the counter in it's first state '0'.A next increment signal forces the next state '1'. In state '4', the highest of this counter, a next increment again forces state '0' and an 'overflow'signal is generated. In digital technology, this overflow is called a 'carry'.Assume that N increments take place after a reset. Table below lists state T of the counter after increment N.

    N 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14T 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4

    We notice that the counter has 5 distinct states Therefore it is called a modulo 5 counter. To express T as a function of N , some (new) notation is required, we write : T is the remainder of the division of N by 5. mod is an operator, just like In the table above we read In case of a modulo 44 counter (counting ) which received 1208 increments, it's state will be

    To program this operation in delphi, we simply write:

    Using a handheld calculator we proceed : remove digits left of the decimal

    point and multiply Please note : in rare occasions a very small rounding number is necessary to obtain an integer number.

    The number of state transitions from highest to 0 we call C , the number of carries.

    is the number of carries out of a modulo 5 counter after N increments.We notice, that C is the integer division of N by 5.

    To program the calculation in Delphi, type

    T = N mod 5

    + - * 14 mod 5 = 4

    0..43

    T = 1208 mod 44

    T := 1208 mod 44.

    1208 : 44 = 27.4545...0.4545... * 44 = 20

    C = N div 5

    C := 1208 div 44

    Notation:

    Counters by David Dirkseexpertstarter DELPHI / Win32

    Figure1: note: 'stand' is Dutch for 'state'. 0, 4 are the lowest and highest state.

    category examplequantity Kilogram, degrees,meters,secondsfactor 15%, half, doubleindex 4 stars hotel, 2nd left, house numbercode Pincode, bus 147, ASCII code

    Rounding

    Two dimensional tables

    The fields are numbered 0 to 23.Calling N the number of a field, than N = column + row * 6.For the columns, we notice a modulo 6 counter. ( )For a known value of N, the column and row can be calculated :

    The computer memory is a one dimensional table of bytes.In case of a two dimensional table, a small calculation is necessary to obtain the memory location.In Delphi, the elements of a two dimensional array are stored in the memory as outlined in the table below: (values 0,1,2,3,... in sequential order)

    example: 23 mod 6 = 5

    column = N mod 6 row = N div 6

    So, is the same element as In general, using an array of rcount rows :

    .adresses the element 1 right of i, adresses

    the element left down of i.This approach may result in considerable time saving with some board games requiring extensive analyses. Using simple and operations, fields can be scanned up, down or diagonally. More time consuming operations like multiplication are avoided.

    A1[9] A2[2,1]

    A2[ col, row] = A1[col * rcount + row]A1[ i + 4] A1[ i 3]

    +

    var array ofarray of absolute

    : [ ] ; : [ , ] ;

    A1 byteA2 byte A1

    0..230..5 0..3 // A1,A2

    Figure: 2 two dimensions

    Figure 3: Let's define above structure both as a one- and as a two dimensional table by using the absolute directive.

    Assume a drawing application, using a paintbox with squares of pixels. A MouseMove generates an event and supplies the (x,y) cordinates. is the number of squares left of the mouse X so.......

    is the X position rounded down to a multiple of 20. In case we want to round to the nearest multiple of 20 we calculate:

    To round upward to the next multiple of 20:

    20 * 20

    X div 20

    (X div 20) * 20 .....

    ((X + 10) div 20) * 20..........{note: 10 = 20 div 2 }

    ((X + 19) div 20) * 20..........{note: 19 = 20 - 1}

    Using a calculator:1208 : 44 = 27.4545... 1208 div 44 = 27

    + - *

    remove digits right of the decimal point .

    div also is an operator, like or mod

    Page 11 / 2125COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

  • Location on the screen

    In figure 4 above a black rectangle constitutes 100 * 100 pixels on the screen.A mouse move presents the (x,y) cordinates of the cursor so

    Each field has an orange area. To test if we are positioned in this area, we program :

    orange boolean x , y

    x x y y

    orange X y y

    A Sudoku puzzle typically has a board with columns 1..9, rows 1..9 and groups 1..9.Refer to the picture below.

    column i = x div 100row j = y div 100

    100 100100 100100

    100 25100 75100 25100 75

    varword

    modmod

    andandand

    Sudoku

    : ;: ;

    ........... := ;:= ;

    := ( > )( < )( > )( < );

    100x

    Notice, that we count from 1..9, which is unsuitable for mod and div operations. Therefore , conversion is needed from 1..9 to 0..8 before mod and div operators may be applied. Given column i, row j , we want to calculate the field that contains this element.This can be done using following function:

    The total counter T0..T3 may be regarded as a counter.

    N = 120 causes state 0 0 0 0 and one carry out of T3.Say N = 68. What will be the state of each individual counter?

    , is the number of carries out of T0 , increments to T1

    , increments to T2.

    , increments to T3.

    So, counter states are 2 0 3 0 (written left to right)At this point, the reader may get worried about the usefulness of this exercise. Continue reading and see.........:A pancake restaurant offers the following choices:

    modulo (2 * 4 * 5 * 3) = 120

    68 mod 2 = 0, so T0 = 086 div 2 = 43

    T1 = 43 mod 4 = 343 div 4 = 10T2 = 10 mod 5 = 010 div 5 = 2T3 = 2 mod 3 = 2

    type of flour: white(0) of whole wheat (1) ...counter 0size : small(0) medium(1) large(2) extra large(3) ...counter 1type : plain(0) apple (1) porc (2) cheese(3) banana(4).counter 2finish : sugar(0) molasses(1)jam (2) ...counter 3

    functionvarbegin

    end

    ( , : ) : ; , : ;

    := ( - ) div ; := ( - ) div ; := + * + ;

    ;

    IJtoGroupNr i j byte byte

    x y byte

    x iy j

    result x y

    //return group Nr of field [i,j]

    1 31 3

    3 1

    Serially connected counters

    We want to convert an order into a smallest possible number, so to encode an order.Now note, that each choice is represented by an individual counter stage mentioned before. The counter state 2 0 3 0 applies to the order white flour.....extra large.....plain......jamcode N for this order is : 68.

    How do we encode order .......whole wheat(1), large(2), apple(1), sugar(0) ?So counter , asked is N.T2 is increased once, this requires increments of T0 since T0T1 together constitute a modulo counter. So, N = 8 for the moment.T1 is increased 2 times, this requires increments of T0. So now . T0 is increased once which makes

    , which is the -pancake-code of this order.Note: to obtain state T of an individual counter stage requires N = T * (modulus of preceding counters) increments into T0.

    state = 0 1 2 12 * 42 * 4 = 8

    2 * 2N = 8 + 4 = 12

    N = 12 + 1 = 13

    Above is pictured an 8 stage counter we recognize as a byte.An individual counter , counting is called a bit. is a shorthand notation we are used to in number sytems. The modulus of the byte is . If we replace the counters by modulo 10 types, counting , N would appear as a decimal number. Conversion from the binary (2) to the decimal (10) number system is accomplished by connecting N also to modulo 10 counters. N mod 10 than is the state of T0 after N increments. N div 10 is the number of carries out of T0 into T1 etc. Program below converts a positive integer (in binary in the computer memory) to a string of decimal digits. (displayed in component edit2)

    0,1,01... 11100110

    2^8 = 2560...9

    Number systems

    procedureconstvar stringbeginif then begin

    endrepeat

    untilend

    ( : ; : ); = ;

    : ; : ; = . . := ; ; ; := ; := mod ; := div ; ( [ + ], , ); = ; . . := ;

    ;

    setN nn cardinal t bytedigitconvert

    s m bytenn form1 edit2 text

    exitsm nn tnn nn tinsert digitconvert m s

    nnform1 edit2 text s

    //displays number with base t'0123456789abcdef'

    0 '0'''

    1 10

    Figure 4:

    Figure 5:

    Figure 5: schematic viewIn the picture above, 4 counters are serially connected. The carry of a stage is the increment of the next. Counter T0 is modulo 2, T1 is modulo 4, T2 is modulo 5 and counter T3 is of the type modulo 3.

    Counters (continuation 1)

    Page 12 / 2126 COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

  • Bit fields

    : [ ] ; ( , : );

    : ; , : ; := + * ; := shr ; := ; [ ] := [ ] ( shl );

    ; ( , : );

    : ; , : ; := + * ; := shr ; := ; [ ] := [ ] ( xor ( shl ));

    ; ( , : ) : ;

    : ; , : ; := + * ; := shr ; := ; := ( [ ] shr ) ;

    ;

    Var array ofprocedurevar integerbegin

    andor

    endprocedurevar integerbegin

    andand

    endfunctionvar integerbegin

    andand

    end

    BitArray byte

    setbit i j wordAbitNr

    byteNr bitNr byte

    ABitNr i j

    ByteNr ABitNrbitNr AbitNrBitArray byteNr BitArray byteNr bitNr

    clearbit i j wordAbitNr

    byteNr bitNr byte

    ABitNr i j

    ByteNr ABitNrbitNr AbitNrBitArray byteNr BitArray byteNr

    bitNr

    testbit i j word byteAbitNr

    byteNr bitNr byte

    ABitNr i jByteNr ABitNrbitNr AbitNrresult BitArray byteNr bitnr

    0..124999

    1000// bitnumber in array , counted 0..999 in row 0, 1000..1999 in row 1

    3 //div 8 = index in byte array$7 //bitnumber in byte

    1

    1000// bitnumber in array , counted 0..999 in row 0, 1000..1999 in row 1

    3 //div 8 = index in byte array$7 //bitnumber in byte

    $ff 1

    1000 // bitnumber in array 3 //div 8 = index in byte array

    $7 //bitnumber in byte$1

    GGD(3094,2310) = GGD(3094-2310,2310) = GGD(784,2310) =GGD(2310,784) = GGD(1526,784) = GGD(742,784) = GGD(784,742) = GGD(42,742) = GGD(742-17*42,42) = GGD(28,42) = GGD(14,28) = GGD(0,14) = 14

    functionvarbegin

    repeat

    untilend

    ( , : ) : ; : ;

    := mod ; := ; := ; := ; := ;

    ;

    GGD A B cardinal cardinalr cardinal

    r A BA BB r

    rresult A

    0

    This concludes my article.

    The next 250 primes

    mod and div are relatively slow operations because they involve division. For reason of speed it is better to avoid them. This is possible if the modulus is a multiple of 2. N div 2 yields the same result as N shr 1, a shift of 1 bit to the right..In general: also Instead of N mod 8 the operation N and 7 has the same answer and is much faster.

    Suppose we are programming a game and we need a 2 dimensional array of 1000 * 1000 bits and 3 procedures/functions:

    1. The forces the value '1' into column i, row j2. makes column i, row j a '1'3. supplies the value of column i, row j.

    We simply put all bits in a 1 dimensional array of bytes, for reasons of fast access.So this array must contain bytes.

    N div (2 ^ i) = N shr i N mod (2 ^ i) = N and (2^ i 1)

    procedure setbit(i , j : word)

    procedure clearbit(i , j : word)Function testbit(i , j : word) : byte;

    1000 * 1000 / 8 = 125000

    How to program this structure?

    A -non prime- number may be written as a unique product of prime factors. Primes play an important role in coding theory and in mathematics in general. For this occasion I wrote a small program to generate the next 250 primes.

    To avoid redundant work the following trics are applied:

    may be written as

    P is prime when where divisor m performs steps

    so alternating 2,4 increments.

    any prime ( > 3) has 6K-1 or 6K+1, where K = 1,2,3,4.......

    (P mod m 0) and (P div m < m)

    5,7,11,13,17,19,23,25,29.....

    Remarks:1. cannot be prime, since is is a multiple of 2.

    is a multiple of 3.only (or , which amounts to the same) and 6K+1 may be prime.

    2. A number P is a multiple of m if P mod m = 0Say and m = 7. Than 63 div 7 = 9 and 63 mod 7 = 0 , 63 is not prime.Suppose , we test P for being prime by division by

    and , but , for the first time the quotient is smaller than the divisor. We can savely assume now that P is prime, because a prime factor should be found earlier.

    3. The program uses 2 goto statements and labels.Some programmers consider this an atrocity but here it results in easy readable code.Reason is the two crossing loops. If anybody knows a nice way to rebuilt the code according to the rules of 'structured programming' , please let me know.

    6K + 26K+3

    6K-1 6K+5

    P = 63

    P = 673,5,7,11,13...67 div 7 = 9 67 div 11 = 6 .....6 < 11

    Calculation of the GCD (greatest common divisor)The GCD of two numbers is best calculated using the 'Euclidian Theorem'. This amounts to the arithmetic rule ......GCD(A,B) = GCD(A-B , B).An example:

    Program below calculates the GCD of numbers A and B by repeatedly applying the Euclidian Theorem.

    Counters (continuation 1)

    Page 13 / 2127COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    David DirkseBorn 1945 in Amsterdam, David joined Control Data Corporation in 1968, after studying electrical engineering. As a hardware engineer, he was responsible for the installation and maintenance of mainframes at scientific data centers in the Netherlands.With the decline of CDC around 1990, he studied mathematics and became a math teacher. His hobbies are programming, in particular educational software, math algorithms, and puzzle solving.http://home.hccnet.nl/david.dirkse

  • Frequently Asked Questions over de W32/Induc-A Virus (Compile-A-Virus) door Nick Hodges

    expertstarter DELPHI 4-5-6-7

    Abstract: This is a set of Frequently Asked Questions about the W32/Induc-A compile-a-virus virus that can attack old versions of the Delphi development tool.

    This virus affects only Delphi versions 4 7 released between 1998 and 2002. The W32/Induc virus does not affect newer versions of Delphi from v2005 thru v2009 or the upcoming v2010.

    This virus does not affect more current versions of Delphi. Delphi 2006, 2007, 2009, and the new 2010 release are not affected by this virus.

    This virus is called "Compile-a-Virus". It is also referred to as "W32/Induc-A".

    No, the versions of Delphi that are vulnerable to this attack (v4 thru v7) do not come with this virus nor is the virus in the language. It is caught by downloading and running an infected EXE or DLL.

    No, Delphi Prism is not affected by this virus.

    This virus does nothing to versions of Delphi newer than Delphi 7 (2002). If a machine is infected, the virus W32/Induc-A doesn't do anything malicious or create damage other than spread itself. What the virus does do is embed itself into an installation of Delphi version 4, 5, 6 or 7. Then, when an infected version of Delphi builds an EXE or a DLL, it embeds itself into that resulting binary. When the code for that EXE or DLL is run, it then looks for installed versions of Delphi 4 thru 7 and replicates itself into any installations that it finds. Then, that installation will in turn produce EXE and DLL files that will look to replicate itself anywhere it is run.

    Specifically, if it finds one of those Delphi versions, it searches for the SYSCONST.PAS file. It opens that file, injects code into it, compiles the file, and replaces the shipped version of SYSCONST.DCU with the new infected version. It then deletes the SYSCONST.PAS file it created. (The virus doesnt alter any *.PAS files on the system). The injected code simply causes the execution of code containing SYSCONST.DCU to replicate the virus.

    This particular virus seeks out Delphi v4 thru v7 but this type of virus is not in any way unique to Delphi and could effect any development environment from Eclipse to Visual Studio.

    Installations of Delphi 4 - 7 can be affected by W32/Induc-A. If an infected EXE or DLL file is run on a machine without Delphi 4 - 7 installed on it, then the virus does nothing. Virus scanners are now starting to report this infection as a virus to those people with infected binaries.

    What versions of Delphi are affected?

    What versions of Delphi are NOT affected?

    What is this virus?

    Is the Delphi IDE or the language distributing this virus?

    Is Delphi Prism affected?

    What does this virus do?

    Is this a problem unique to Delphi?

    Who is vulnerable to this infection?

    Again, the virus looks only for an installation of Delphi 4 -7.

    How do I know if I've been infected?Detecting if your Delphi installation has been infected is fairly easy. It only affects Delphi version from 4 to 7. The easiest way to tell if you have been infected is to search for the presence of SYSCONST.BAK in the \lib directory of your Delphi installation.

    The virus creates this file as part of its actions. If that file is present, you are likely infected (unless you know that you yourself created this file for some reason). If you have a SYSCONST.BAK in your \lib directory, then you can open up SYSCONST.DCU in a hex editor or even in a text editor like notepad. You can search for the code "CreateFile(pchar(d+$bak$),0,0,0,3,0,0);" in that DCU file. If it is present, you are infected.

    If I have it, how did I get it?

    How do I remove the virus from my Delphi installation?

    How do I make sure that it doesn't come back? or I don't have the virus. How do I make sure that I don't get it?

    If you have the virus, you got it buy running an EXE or DLL file on your machine that was already infected with this virus. Delphi is a very popular development tool, particularly among ISV and MicroISV developers. Ii you received an infected binary you may have received it from an application download.

    If your machine is infected, the EXE and DLL files that you produce will infect any unprotected machine where your EXE or DLL is run and that has Delphi 4 7 installed. But note again that this virus doesn't do anything malicious apart from spreading itself. However, if you detect that you have the virus and have distributed known infected files, it is prudent to notify file recipients and point them to this FAQ for more information.

    To remove the virus you should - Delete the infected SYSCONST.DCU file on your system - Replace it with the SYSCONST.DCU file from your

    installation media. Delphi versions 4 -7 include a complete install image on their CD, so you can simply copy that file from your DVD to your installation.

    This virus does not affect Delphi version 2005 thru 2010. However, if you are running older copies of Delphi v4 thru v7 then the most effective way to ensure that you dont get the virus is to move your copy of DCC32.EXE to a different directory. The IDE of these older versions doesnt require the command line compiler, so this will not affect the execution of the product.You can also prevent the virus from doing anything to your installation again by leaving a file named SYSCONST.BAK in the same location where you found it. The file can be empty. The virus checks for the presence of this file, and if it finds it, it does nothing. Leaving a blank SYSCONST.BAK file in the same location as your SYSCONST.DCU file will ensure that the virus will do nothing.In addition, you can mark all of the files in your \lib directory as read-only. This will prevent the virus from changing them.

    This is a relatively new virus, and so virus scanning software is just starting to recognize it. A number of vendors are already identifying binaries with this infection, and undoubtedly, most will follow suit soon. The best way to detect the virus is to ensure that your anti-virus software knows about W32/Induc-A and run a virus scan on your system.The binaries I am producing are infected, what can I do?Of course you first need to rid your system of the virus See above.The only way to get rid of the virus that is already in an existing EXE or DLL is to recompile that binary with a clean system.

    It is possible but unlikely. By default, packages are not affected. A package can become infected if you manually choose not to link against our RTL.DCP file and manually link in an infected SYSCONST.DCU.

    What are the implications of being infected?

    How do I tell if I have executable files on my system that are spreading this virus?

    Does this affect packages built with Delphi 4 - 7?

    Page 14 / 2128 COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

  • FAQs over de W32/Induc-A Virus (Compile-A-Virus) - vervolg

    The overwhelming majority of developers will not have done this, and if you have, then youll be able to recompile those packages with a clean system.

    There are a number of additional things you can do to protect yourself against this virus. As mentioned above, you can mark all of the DCU files in your \lib directory as read-only. And while you are at it, you might consider labeling all of the source code in the \source directory as read-only as well.

    To be absolutely safe, you can do a file compare between your \lib directory and the \lib directory on the install image on your CD.

    What else can I do to protect myself?

    If you need a file compare tool, there is a very powerful, open source tool called FreeFileSync which can be found at:

    Keep in mind that it is possible that you may have altered these DCU files yourself, so if they show up as different, be sure that you yourself havent altered them. So far, this virus only affects the SYSCONST.DCU file.In any event, it is highly recommended that you ensure that the files in the \lib directory of your Delphi 4 7 installation match those of the install image on your CD.

    http://sourceforge.net/projects/freefilesync/

    Page 15 / 2129COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    Is C++Builder affected?No. It is theoretically possible for a C++Builder EXE to become infected, but a C++Builder developer would have to take a rather lengthy set of steps and actively change and recompile a number of different things on his system in order for the virus to affect C++Builder binaries.I produce shareware and/or an ISV application built with Delphi? What does this mean?If you are running newer versions of Delphi 2005 thru 2010 then it doesnt affect you. If you are a Shareware or ISV vendor running an older version of Delphi v4 thru v7, then you should check that your machine is not infected. If it is infected you should clean it. If you have distributed infected executables to your customers, you should immediately recompile your product and distribute a new, cleaned version. It would also be prudent to notify file recipients and point them to this FAQ for more information. As anti-virus programs begin to see this virus in binaries, customers will be getting reports of your binaries being infected and youll want to be ready with a clean binary for them.

  • DeZign for Databases v5 by Marco Roessen

    Many applications use a database for storing data. A database usually is a collection of tables with their internal relations. Creating a database can be done completely from code. Another possibility is to use a tool supplied with the database engine. Using these tools a database can be visually designed; the tables and their relations are graphically represented. Examples of these tools are mysqladmin used for MySQL databases and SQL Server Management Studio for MSSQL databases. Often databases created with these tools and the chosen data types are specific for these database engines. It is not easy to convert these designs to other database engines. This article is about DeZign for Databases v5, a database engine independent tool for designing and creating databases.DeZign for Database is one the products developed by the relatively young Dutch company Datanamic. The products they have developed are:

    Powerful database design and modeling tool. Design, create, reverse engineer and modify databases.

    Compare and synchronize database content.

    Compare and synchronize database schemas (structure).

    Quickly generate test data for your databases.

    Execute multiple SQL scripts against multiple databases.

    Archive and extract database data. An easy way to migrate and backup data. DeZign for Databases is Datanamic's most prominent product. You can download trial versions of all of the above products. Please check the website ( ) for more details.

    - DeZign for Databases V5

    - DB Data Difftective V1

    - DB Schema Difftective V1

    - DB Data Generator V2

    - DB MultiRun V1

    - DB Zipper V2

    www.datanamic.com

    Figure 1: DeZign for Databases designer overview

    First impressionsWhen you install DeZign for Databases and run it the first time, you will automatically be presented a demo database. This demo database gives us the opportunity to discover the possibilities of DeZign for Databases.Figure 1 shows the two main interface elements: the designer on the right-hand side and the object browser on the left-hand side. Double clicking a table in the designer or Object browser will open an interface. This interface is used for adding, removing or modifying fields (figure 2).

    Creating a new databaseCreating a new database design is relatively easy. When you create a new project you will be asked which database engine you will be using. The currently supported database engines are DB2, dBase, DBISAM, ElevateDB, Firebird, FoxPro, Informix, Interbase,

    Figure 2: Modifying the properties of a table

    expertstarter all DELPHI versions

    Page 16 / 2130 COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

  • When generating a database it is possible to add a version to the design. By using versions, it is always possible to revert to an older version of the design. You can also create a so called SQL modify script. This script can be used to modify an existing database structure to fit the structure of an older or newer design

    Another nice feature is the possibility of importing an existing database structure. This feature is useful for investigating an already existing database structure. All tables, relations, triggers, code, etc are displayed clearly. You can modify this imported structure with the same tools that are available when designing a new database (modify tables and fields, create a database or a SQL modify script, etc). One of the properties of a database design is the target database engine. If you have to modify your initial choice for some reason (e.g. use a more powerful database engine) this is possible. The project will be converted to the other database engine target. If there are incompatibilities, they will be displayed. This function is also useful for converting imported databases to another target engine. There is one thing I want to warn you about when using DeZign for Databases: If you want to change the structure of an existing database (filled with data) using an SQL modify script, you have to take good care that there will be no loss of data. When a modification of the structure of a database is incompatible with the current existing database (e.g. changing a string field to an integer field), there is a possibility that you will lose all existing data. In these cases the SQL script created will remove the existing table (DROP TABLE) and therefore all existing data and create a new table from scratch. It is wise to check the script and backup the database before executing the SQL modify script. It would be nice if DeZign for Databases warned you about the possible loss of data.

    DeZign for Databases is an excellent tool for designing and modifying databases. Its database engine independency is big plus. The program is easy to use and gives you all the tools necessary for every day database design. The automatic versioning feature is also very useful. DeZign for Databases is relatively cheap compared to other database design tools, despite the extensive set of features.

    Importing a database structure

    Conclusion

    DeZign for Databases v5 (continuation)MaxDB, MS Access, MS SQL server, MySQL, NexusDB, Oracle, Paradox, Pervasive PostgreSQL, SQL Anywhere Studio, SQLite and Sybase ASE. For a complete list of the supported database engine versions and functionality you can check the complete overview available at

    .It is also possible to create your own DBMS database definition file. These definition files can be used by DeZign for Databases to support database engines that are (not yet) supported by default. You can find more information about this subject in the extensive help file. After choosing the database engine, you will be presented an empty workspace where you can add tables. When tables are added you will be presented a dialog containing the properties of this newly created table. You use this dialog to set table properties and add fields.A nice feature of the program is called Domains. A domain is an alias for a specific data type with specific properties set. If you, for instance, use the VARCHAR data type with the property maxchars set to 75 a lot, you can create a domain with these properties. You can give this domain a descriptive name. This domain will be available from the list with data types (starting with an @). If you have to modify the data type or one of the properties for some reason, you will only have to modify the domain. All fields using this domain will be updated automatically.When all tables are defined, we can set the internal connections by adding Relationships. For instance you can add an Identifying relationship by clicking the corresponding toolbar button. After clicking the button you can draw a line between the tables that have to be linked. Default the table relation will be set between the fields that have the same name in both tables. If this is not the intended relationship, you can manually change it (figure 3).

    When the whole database design is ready, you can check it (Database / Check model Ctrl+F9). If there are any problems or warnings they will be displayed in the bottom window: theMessageWindow. When all problems and warnings have been resolved, you can create the database (F9). An SQL script will be created for SQL based database engines. Other (non-SQL) databases will be created as a file (e.g. an MSAccess.mdb file).

    http://www.datanamic.com/dezign/supporteddatabases.html

    Creating the database

    Page 17 / 2131COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    Figure 3: Changing a relationship

    About the author:

    Marco RoessenGraduated HTS-Electronics, specialisation Technical ComputerScience, in 1993.Since then he has been working as an informatics engineer at the Centre for sleep and wake research firstly at Leiden University since 1995 at Medisch Centrum Haaglanden, Den Haag.There he develops tailored sleep research software; started with assemblerand MS Pascal, later using Turbo, Borland and Delphi Pascal. Currently also C#.He is co-developer of algorithms for automatic biomedical signal analysis.

  • = ( ) : ; : ; : ; : ; : ; : ; : ; ;

    typeclass

    privatepublicend

    TForm1 TFormADOTable1 TADOTableADOTable1ID TAutoIncFieldADOTable1Name TStringFieldADOTable1Paid TFloatFieldADOTable1Date TDateTimeFieldDBGrid1 TDBGridDataSource1 TDataSource

    {Private declarations }

    {Public declarations }

    Customizing the T-Field data display by Henk Schreij

    When you display a database field, you sometimes want to show something other than what is stored in the field. For example, you might want to show 'male' or 'female' when the stored value is '1' or '0', or show figures with two decimal places, such as 1.50 instead of 1.5. The usual approach in such cases is to create persistant fields and use their OnGetText events or Display Format properties. You can also achieve the desired result without persistant fields, as described in this article.

    For a change, here we use SqlServerExpress (Microsoft's free database application) for our example. For those of you who are used to working with Paradox or Access, it's easy to do the same thing with these applications. The example table in Figure 1 has four fields: ID (autoincrement), Name (string 15), Amount (float or real; may be empty), and Date (date and time; may be empty).

    Persistant fields

    If you fill the table with some data and display it as an AdoTable in a DBGrid, the presentation of the numbers leaves something to be desired. We are used to seeing numbers with two decimal places instead of the numbers shown in Figure 2.

    The usual solution here is to right-click AdoTable1 (or Table1 if you're using Paradox) to bring up the Fields Editor. In the Fields Editor, you again right-click and select 'Add all Fields' as shown in Figure 3.

    This gives you what are called persistant fields, which remain permanently in your program. This is an extension to the normal situation in which the fields are created at runtime when the table is opened.The advantage of persistant fields is that you can configure the properties and events of each field separately. The Object Inspector gives you convenient access for viewing or setting the configurations, such as in Figure 4 where you see the Display Format property of the Amount field. If you type '0.00' here, the numbers will always be displayed with two decimal places as illustrated in Figure 5.

    A FloatField has the DisplayFormat, but some other field types (such as StringField) do not. The specific properties depend on the field type. For example, a Boolean field has the DisplayValues property (Yes; No or T; F), an Integer field has the MaxValue and MinValue properties, and so on.

    property

    Persistant fields are thus very handy when you have special wishes for fields that are not available at runtime. However, they also have disadvantages. To start with, they end up in your code:

    With a large number of tables, this can result in pages full of 'filler' code. A more serious problem is that your fields are no longer flexible. If there are any persistant fields (even just one), no fields are created at runtime and all non-persistant fields are hidden. This can drive you crazy when (perhaps years later) you add a field to table and it remains invisible no matter what you do. You usually end up deleting the table (or AdoTable) and building it again from scratch, after which the field is suddenly visible. However, it's easy to forget to check the properties, such as DisplayFormat, and then other things are suddenly messed up. For these reasons, persistant fields are not especially popular.

    It's also possible to specify the DisplayFormat property without creating persistant fields. To do this, you have to specify the field property in the code immediately after you open the table. You can use the table's OnAfterOpen event for this, as shown in Figure 6.(Note: If you open the table in the OnShow of your form, you do not need to use OnAfterOpen. In this case, you can specify the property in the OnShow event immediately after the line containing AdoTable1.Open.)

    DisplayFormat without persistant fields

    event

    expertstarter DELPHI 2..2010 / Win32

    Page 18 / 2132 COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

    Figure 1. Structure of the test table in SqlServer 2005

    Figure 2. Default display of floating-point numbers

    Figure 3. Using 'Add all Fields' to make persistant fields

    Figure 4. Specifying the DisplayFormat property of the persistant field 'Paid'

    Figure 5. Rendering of floating-point values with DisplayFormat set to '0.00'

  • procedurebegin

    as

    end

    . ( : ); ( . ( )

    ). := ; . ( ). :=

    ;;

    TForm1 ADOTable2AfterOpen DataSet TDataSet

    AdoTable2 FieldByNameTNumericField DisplayFormat

    AdoTable2 FieldByName OnGetTextSexGetText

    'Paid''0.00'

    'Sex'

    If you double-click OnGetText, you will see a framework. Put the following code in this framework

    Unfortunately, you won't see DisplayFormat in the dropdown list if you simply try to specify this property, since DisplayFormat is not a general TField property, but instead only a property of a number field or date field. For this reason, you need a typecast to TFloatField or its general ancestor TNumericField. procedurebegin

    asend

    . ( : ); ( . ( ) ). := ;

    ;

    TForm1 ADOTable2AfterOpen DataSet TDataSet

    AdoTable2 FieldByNameTNumericField DisplayFormat

    'Paid''0.00'

    This lets you specify the properties of a TField without creating persistant fields.

    In the introduction to this article we mentioned that you may have a table where '0' and '1' stand for 'male' and 'female', which you want to show as ' ' and ' , and that you can do this by using OnGetText.

    To try this out, add a Gender field (of type Integer) to your table in SqlServer (or Access, Paradox, or whatever you're using). Here again you have two options: with or without persistant fields. First: how it works with persistant fields.If you already had persistant fields before you added the Gender field, you won't see the new field in the DBGrid.What's worse, if you use Add Fields as shown in Figure 3, there's a good chance that you won't even see the field itself. This is because AdoTable1 can't see that a new field has been added unless you have AdoTable1 open at design time. To achieve this, set the Active property of the table to True before you invoke Add Field.Once you have added the Gender field to the table as a persistant field, you can view the events of this field as shown in Figure 7.

    Using OnGetText with persistant fields

    m f

    ' ' ' '

    OnGetText without persistant fieldsUsing OnGetText without persistant fields is a bit more difficult. Two steps are necessary in this case. First you have to tell the program that the OnGetText event of the Gender field points to a specific procedure, and then you have to specify this procedure.

    Incidentally, this is how Delphi always works. You can see this if you examine the previous example in Figure 8 more closely. To do this, you have to look in the code of the form itself (the .dfm file), where the OnGetText event is linked to the procedure. It's very easy to view the code in the .dfm file: simply right-click the form, select 'View as Text', and look for the persistant field, where you will see:

    object

    end

    : = =

    ;

    ADOTable1Sex TIntegerFieldFieldNameOnGetText ADOTable1SexGetText

    'Sex'

    To restore the normal form view, right-click this code and select 'View as Form'. Now: how it works without persistant fields. The first step is the code that references the procedure:

    Incidentally, you can also put the code for the first step in the OnCreate event of the form (which is actually the usual practice).

    The second step is to specify the action in SexGetText. An OnGetText event expects three parameters (Sender, Text, and DisplayText), so you have to specify them as well. See the Help entry for OnGetText for more explanation. The resulting code is:

    procedurevar string

    beginif thenelse

    end

    . ( : ; : ; : ); . = := := ;

    ;

    TForm1 SexGetText Sender TFieldText DisplayText Boolean

    Sender AsIntegerText

    Text

    0'm'

    'f'

    Don't forget to declare this procedure, including its parameters, in the private declarations. The easiest way to do this is to use Ctrl+Shift+C to complete the code automatically.Also be sure to set the ReadOnly property of this DBGrid field to True. It's very confusing for users if what is displayed is not the same as what they have to enter, so you have to arrange for data entry outside your DBGrid.

    There is also a way to accept data entry that does not match the field content and have it be stored in the table. For this, you use the counterpart of OnGetText, which is called OnSetText.

    Unfortunately, it isn't possible to use OnSetText to enter a letter (such as or ) in an integer field, since a number field won't accept letters. You'll hear an error beep before you even get to OnSetText.

    ' ' ' 'm f

    procedurevar string

    beginif thenelse

    end

    . ( : ; : ; : ); . = := := ;

    ;

    TForm1 ADOTable1SexGetText SenderTField Text DisplayText Boolean

    Sender AsIntegerText

    Text

    0'm'

    'f'

    Here you should note that the type of Sender is TField rather than TObject, which means that you can use AsInteger to read the numerical value directly, and that Text is a variable that you can use specify the text to be displayed.The result is shown in Figure 8.

    Page 19 / 2133COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    Figure 6. DisplayFormat is not one of the listed properties

    Figure 7. Events of the persistent Integer field 'Gender'

    Figure 8. Using OnGetText to convert 0 and 1 to m and f ' ' ' '

    Customizing the T-Field data display (continuation 1)

  • OnSetText without persistant fieldsFor our example for OnSetText we will use a date field, since a date field accepts all characters. The objective here is to have the current date be stored when the user enters a space character.

    This can be done with or without persistant fields; the example here is without persistant fields. The full code, including the previous DisplayFormat and OnGetText, is as follows:

    unitinterfaceusestype

    class

    procedureprocedureprocedure

    privateprocedure

    var stringprocedure const string

    publicend

    varimplementation

    procedurebeginend

    ;

    , , , , , , , , , , , ; = ( ) : ; : ; : ; : ; ( : ); ( : ); ( : ); ( : ; : ; : ); ( : ; : ); ;

    : ;

    . ( : ); . ;

    ;

    Unit1

    Windows Messages SysUtils Variants ClassesGraphics Controls Forms DB Grids DBGrids ADODB

    TForm1 TFormADOConnection1 TADOConnectionDBGrid1 TDBGridDataSource1 TDataSourceADOTable1 TADOTable

    FormShow Sender TObjectFormCreate Sender TObjectADOTable1AfterOpen DataSet TDataSet

    SexGetText Sender TFieldText DisplayText Boolean

    DateSetText Sender TField Text

    Form1 TForm1

    TForm1 FormShow Sender TObject

    ADOTable1 Open

    {Public declarations }

    {$R *.dfm}

    procedurebegin

    endprocedurebegin

    asendprocedure var stringbeginif thenelse

    endprocedure const stringbeginif thenelse

    endend

    . ( : ); . ( ). :=

    ; . ( ). :=

    ;;

    . ( : ); ( . ( )

    ). := ;;

    . ( : ; : ; : );

    . = := := ;

    ; . ( : ;

    : ); ( ) = . := . := ( );

    ;.

    TForm1 FormCreate Sender TObjectAdoTable1 FieldByName OnGetTextGeslachtGetText

    AdoTable1 FieldByName OnSetTextDatumSetText

    TForm1 ADOTable1AfterOpen DataSet TDataSetAdoTable1 FieldByNameTNumericField DisplayFormat

    TForm1 SexGetText Sender TFieldText DisplayText Boolean

    Sender AsIntegerText

    Text

    TForm1 DateSetText Sender TFieldText

    Trim TextSender AsDateTime Date

    Sender AsDateTime StrToDateTime Text

    'Sex''Date'

    'Paid''0.00'

    1'm'

    'f'

    ''

    This example, which stores the current date when a space character is entered or nothing is entered, can easily be extended to provide other useful functions, such as storing yesterday's date or tomorrow's date if the user enters '' or '+', entering the date and time without seconds, and so on. You can also add a good automatic error handling mechanism, such as adding the month and year automatically if only the day is entered.

    One final remark: the example shows how this works with a DBGrid, but it also works with a DBEdit or the like, since the code is linked to a TField rather than the component that displays the data.

    Using Free Pascal and Lazarus to create applications for OSX.Having come from using Delphi and Visual Studio development environments and constantly hearing how an OSX based system does everything better than a Windows based system I was bitterly disappointment when I started exploring the XCode and Interface Builder developer tools by Apple. If you want to use a Pascal language on OSX your options are pretty limited. One option is Free Pascal. Free Pascal has been around for a number of years now and is updated regularly. It supports many operating systems include Win32, Linux, WinCE and OSX. To support Free Pascal there is an open source integrated development environment called Lazarus. Let's be honest here, Lazarus is pretty much a knock off of the old Borland IDE circa Delphi 7, which can be both a positive and negative, with a few nice additions thrown in. Lazarus has its own version of the VCL called LCL. It is basically compatible with Delphi's VCL. I say basically because it isn't 100% and in some areas it is far from it. You need to download the appropriate packages from the Free Pascal and Lazarus websites for your version for your MAC. Make sure you download the correct packages.

    Free PascalLazarus

    - -

    (http://www.freepascal.org/)(http://www.lazarus.freepascal.org/)

    by Jeremy North

    Figure 1: the IDE of Lazarus

    Before installing either package be sure to install the Apple developer tools. You can download these tools from the Apple Developer website You will have to create a developer account which is free - unless you select one of the paid account types. I signed up using the iPhone developer program which gives you access to the iPhone specific tools (SDK versions, simulator etc.) but also to the desktop specific tools. Be warned, the downloads are not small (nor fast - at least from my side of the world).After installing the Apple developer tools, install Free Pascal before Lazarus. This should make things a lot easier in the long

    (http://developer.apple.com).

    Launch Lazarus and go into the Environment | Options dialog. Make sure that the Compiler Path and FPC Source Directory options are set to the install location of Free Pascal. If you install to the default locations these will be

    respectively. /usr/local/bin/fpc and

    /usr/local/share/fpcsrc/

    run. Follow the installation instructions found on the website to install each package. After you have installed both Free Pascal and Lazarus, run Lazarus. By default Lazarus installs into the /Developer/lazarus folder.

    Features not in DelphiAs mentioned earlier, Lazarus has some features that are not available in the Delphi. It also has some of Delphi features that are not so good and then it just has some features of its own that are not so good.NOTE: These lists are nowhere near exhaustive.

    expertstarter

    Page 20 / 2134 COMPONENTSDEVELOPERS 4 October 200 9 BLAISE PASCAL MAGAZINE 8

    Customizing the T-Field data display (continuation 2)Consequently, we have to devise another example for OnSetText.

  • Good

    Not so good

    Lazarus includes a DIFF viewer for comparing files. Although nothing could replace Beyond Compare on my systems for that.Customizable number of recent project and files. Thisfeature is included Delphi in 2010.The tab order dialog allows you to change a forms entiretab order within the same dialog. So you don't have to keep reopening the dialog with a different parent selected like you do in Delphi.

    By default a dialog displays to tell you that you havefinished running your application. This dialog is very annoying. It can be switched off in the Debugger options located in the environment options dialog shown earlier. Uncheck the Show message on stop check box.The Importing of Delphi projects and files didn't work very well and was error prone. Eventually I gave up.Lots of setting up of custom paths to compiler and units required for projects - compounded by my importing woes mentioned earlier.

    Target Widget Type The default widget framework used by Lazarus is Carbon. Carbon is the older API although it is still used in a lot of the native Apple applications that come with newer versions of OSX. The new widget set, Cocoa is available although it is listed as Pre-Alpha in the LCL Widget Type drop down. When I tried to target Cocoa a basic project failed to compile.

    my Mac Book Pro. This project consisted of one form. The form had a main menu (with some items in it two had event handlers), a memo and a status bar. When trying to import this project the IDE crashed. A second application I tried to import did work however the imported project didn't have any unit paths assigned to it (which is done automatically when you create a new project). This means you need to set these paths manually. The second project didn't include the status bar or the main menu.

    Using Free Pascal with XCode and Interface BuilderWhen you install Free Pascal the later versions include an XCode for Integration product. This product allows you to use the XCode and Interface Builder tools to create applications using Free Pascal. While I didn't really have a lot of time to use this product, it showed considerable promise and something that will hopefully see regular updates in the future.

    Cross Platform seems to be a popular phrase lately. With Embarcadero recently announcing it will be creating Linux and OSX compatible compilers. While the details are sketchy at the moment, it has been mentioned that there will not be a version of the IDE for the alternate platforms. I created a very simple application in Delphi and saved it on to

    Cross Platform, not so much

    Figure 2: the options form

    StabilityWhile writing this article and generally exploring Lazarus, stabi- lity can be an issue. Trying to create a standard action using the component editor for the action list resulted in an Access Viol-ation that required Lazarus to be restarted. Somehow I managed to get a Debugger error (refer to screen capture). Clicking OK didn't prevent me from debugging the application though.

    While I had issues creating a new NIB (or XIB) file modifying the one included when creating the template was a simple. Every control I dropped onto the design surface worked and recompiling the application also worked fine.

    If you want to write Pascal code on your Mac and do not want to use either a Virtual Machine or Boot Camp then Lazarus and Free Pascal is an option to keep an eye on. The Intel OSX (I tested under Leopard Snow Leopard was released just prior to completing the article) version seems a little rough around the edges. If you're a developer that is interested in writing applications for the Mac in Pascal, certainly check out the Free Pascal and Lazarus combination. I'm sure they'd appreciate any assistance you gave them with bug reports or submitting fixes to the team behind the products. One advantage of Lazarus is, if there is something in it that you don't like. You have the source code on your disk and a Build Lazarus menu item in the Tools menu. Next Time: We will convert some component code from Delphi (VCL) to Free Pascal (LCL), making sure that it runs correctly on OSX as well.

    Conclusion

    Using Free Pascal and Lazarus to create applications for OSX (continuation)

    Page 21 / 2135COMPONENTSDEVELOPERS 4October 200 9 BLAISE PASCAL MAGAZINE 8

    Figure 3: a debugger error under Mac

    Figure 4: a debugger error under Mac

    Figure 4: compiler options for the project

  • Writing Delphi Components II: Custom Properties and Windows Controls by Marco Cant

    This article is the second of a series introducing a very relevant features of Delphi's architecture, namely writing your own custom components. The first article of this introductory series provided an overview of the Delphi Component Wizard and showed a first very simple component. Our second component, covered here, will add some extra properties and events. A Graphical Component with Custom Properties: The LEDTo show you a more usable graphical component, Ive built yet another LED component. (LED is an acronym for Light-Emitting Diode, a solid-state electronic light thats typically used for indicating binary conditions such as the send/receive status of a modem.) Instead of calling it TYALC (for Yet Another LED Component), Ive called it TCntLed, using the Cnt prefix after my name.

    Here is the declaration of this simple component class. As you can see, there are only two custom properties, Color and Status:

    = ( , ); = ( ) : ; : ; ( : ); ( : ); ( : ); ; ; ; : ; : ; ; ; ; ; ;

    type

    classprivate

    procedureprocedure

    publicconstructorprocedure

    publishedpropertypropertypropertypropertypropertyproperty

    end

    TCntLedStatus lsOn lsOff

    TCntLed TGraphicControl

    fStatus TCntLedStatusfColor TColor

    protectedSetStatus Value TCntLedStatusSetColor Value TColor

    Create Owner TComponent overridePaint override

    Status TCntLedStatusread fStatus write SetStatus default lsOn

    Color TColorread fColor write SetColor default clRed

    Width defaultHeight defaultOnClickOnDblClick

    2020

    For the Status property, Ive defined an enumerated data type (TCntLedStatus), which is more understandable and flexible than a Boolean data type. By convention, you should use the initial letter of the component and property name (ls for LED Status) to build the names of the enumerated values (for example, lsOn).If you examine the property declarations, you notice that Ive applied the read and write directives to specify