Mastering Delphi 7

Mastering Delphi 7

Marco Cantù

Associate Publisher: Joel Fugazzotto Acquisitions Editor: Denise Santoro Lincoln
Developmental Editor: Brianne Agatep
Production Editor: Kelly Winquist
Technical Editor: Brian Long
Copyeditor: Tiffany Taylor
Compositor: Rozi Harris, Interactive Composition Corporation
Proofreaders: Nancy Riddiough, Emily Hsuan, Leslie Higbee Light, Monique Vandenberg, Laurie O'Connell, Eric Lach
Indexer: Ted Lau
Book Designer: Maureen Forys, Happenstance Type-O-Rama
Cover Designer: Design Site
Cover Illustrator: Tania Kac, Design Site

Copyright © 2003 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. The author(s) created reusable code in this publication expressly for reuse by readers. Sybex grants readers limited permission to reuse the code found in this publication so long as the author(s) are attributed in any application containing the reusable code and the code itself is never distributed, posted online by electronic transmission, sold, or commercially exploited as a stand-alone product. Aside from this specific exception concerning reusable code, no part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic, or other record, without the prior agreement and written permission of the publisher.

Library of Congress Card Number: 2002115474

ISBN: 0-7821-4201-X

SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc. in the United States and/or other countries.

Mastering is a trademark of SYBEX Inc.

Screen reproductions produced with Collage Complete.
Collage Complete is a trademark of Inner Media Inc.

TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer.

The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever possible. Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s). The author and the publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly from this book.

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

To the late Andrea Gnesutta,
a friend the Italian Delphi community prematurely lost.


This seventh edition of Mastering Delphi follows the seventh release of a Delphi development environment by Borland, a revolution started in the winter of year 1994. As it has for many other programmers, Delphi (and its Linux twin, Kylix) has been my primary interest throughout these years; and writing, consulting, teaching, and speaking at conferences about Delphi have absorbed more and more of my time, leaving other languages and programming tools in the dust of my office. Because my work and my life are quite intertwined, many people have been involved in both, and I wish I had enough space and time to thank them all as they deserve. Instead, I'll just mention a few particular people and say a warm "Thank You" to the entire Delphi community (especially for the Spirit of Delphi 1999 Award I've been happy to share with Bob Swart).

The first official thanks are for the Borland programmers and managers who made Delphi possible and continue to improve it: Chuck Jazdzewski, Danny Thorpe, Eddie Churchill, Allen Bauer, Steve Todd, Mark Edington, Jim Tierney, Ravi Kumar, Jörg Weingarten, Anders Ohlsson, and all the others I have not had a chance to meet. I'd also like to give particular thanks to my friends John Kaster and David Intersimone (at Borland's Developer Relations), and others who have worked at Borland, including Charlie Calvert and Zack Urlocker.

The next thanks are for the Sybex editorial and production crew, many of whom I don't even know. Special thanks go to Brianne Agatep, Denise Santoro Lincoln, Tiffany Taylor, Rozi Harris, and Kelly Winquist; I'd also like to thank Joel Fugazzotto and Monica Baum.

This edition of Mastering Delphi has had a very detailed and scrupulous review from Delphi guru Brian Long ( His highlights and comments have improved the book in all areas: technical content, accuracy, examples, and even readability and grammar! Thanks a lot. In writing this book I had special contributions (to different extents) to the chapters on add-on tools and in the area of .NET programming from (in alphabetical order) John Bushakra, Jim Gunkel, Chad Hower, and Robert Leahey. A short bio and contact information for each of them is in the chapters they helped me write.

Previous editions also had special contributions: Tim Gooch worked on Mastering Delphi 4 and Giuseppe Madaffari contributed database material for the Delphi 5 edition. For Mastering Delphi 6, Guy Smith-Ferrier rewrote the chapter on ADO and Nando Dessena helped me with the InterBase material. Many improvements to the text and sample programs were suggested by technical reviewers of past editions (Delphi R&D team member Danny Thorpe, Juancarlo Añez, Ralph Friedman, Tim Gooch, and Alain Tadros) and in other reviews over the years by Bob Swart, Giuseppe Madaffari, and Steve Tendon. Uberto Barbini helped me write Mastering Kylix 2 and some of his ideas ended up also affecting this book.

Special thanks go to my friends Bruce Eckel, Andrea Provaglio, Norm McIntosh, Johanna and Phil of the BUG-UK, Ray Konopka, Mark Miller, Cary Jensen, Chris Frizelle of The Delphi Magazine, Mike Orriss, Dan Miser, my co-worker Paolo Rossi, and the entire Italian D&D Team ( Also, a very big "Thank You" to all the attendees of my Delphi programming courses, seminars, and conferences in Italy, the United States, France, the United Kingdom, Singapore, the Netherlands, Germany, Sweden….

My biggest thanks go to my wife Lella who had to endure yet another book-writing session and too many late nights (after spending the evenings with our daughter, Benedetta— I'll thank her with a hug, as Daddy's book looks quite boring to her). Many of our friends (and their kids) provided healthy breaks in the work: Sandro and Monica with Luca, Stefano and Elena, Marco and Laura with Matteo and Filippo, Bianca and Paolo, Luca and Elena with Tommaso, Chiara and Daniele with Leonardo and Matteo, Laura, Vito and Marika with Sofia. Our parents, brothers, sisters, and their families were very supportive, too. It was nice to spend some of our free time with them and our seven nephews—Matteo, Andrea, Giacomo, Stefano, Andrea, Pietro, and Elena.

Finally, I would like to thank all of the people, many of them unknown, who enjoy life and help to build a better world. If I never stop believing in the future and in peace, it is also because of them.

Visit Marco's Delphi Developer Website

This book's author, Marco Cantù, has created a site specifically for Delphi developers, at It's a great resource for all of your Delphi programming needs.

The site includes:

  • The source code of the book

  • Extra examples and tips

  • Delphi components, wizards, and tools built by the author

  • The online books Essential Pascal, Essential Delphi, and others

  • Papers the author has written about Delphi, C++, and Java

  • Extensive links to Delphi-related websites and documents

  • Other material related to the author's books, the conferences he speaks at, and his training seminars

The site also hosts a newsgroup, which has a specific section devoted to the author's books, so that readers can discuss the book content with him and among themselves. Other sections of the newsgroup discuss Delphi programming and general topics. The newsgroup can also be accessed from a Web interface.

Click To expand

Part I: Foundations