Delphi Database Programming With ADO
Delphi Database Programming With ADO
Delphi Programming
ESSENTIALS
Delphi Database Programming Course
Free online database programming course for beginner Delphi
· A Beginner’s Guide to developers. Focus on ADO techniques.
Delphi Programming
· Free course: Delphi About the Course: Related Resources
• A Beginners Guide To
ADO DB programming Delphi Programming
This free online course is perfect for Delphi
· Delphi for .NET database beginners as well as for those who want
• BOOK: Advanced Delphi
a broad overview of the art of database
· Free code APPs & Developer's Guide to ADO
programming with Delphi. Developers will learn
• Before you buy ADO VCL
VCL how to design, develop and test a database
• More ADO articles
application using ADO with Delphi. This course • Full (free) code apps and
· A-Z Site Index focuses on the most common uses of ADO in a components
Delphi application: Connecting to a database using • More tutorials and articles
BUYER'S GUIDE TADOConnection, work with Tables and Queries,
handle database exception, create reports, etc. From Other Guides
What's New and Hot • About Databases
Prerequisites:
Top Picks-Tool/VCL Elsewhere on the Web
Readers should have at a working knowledge of
the Windows operating system, as well as some • AdoAnywhere
Beginners Here decent level of Delphi Programming knowledge
base. New developers should first explore A
COM/OLE/ActiveX
Beginner's Guide to Delphi Programming
Database
Distrubuted comp. Chapters:
The chapters of this course are being created and updated dynamically on
Game Programming this site. Chapters (for now) include:
Graphics
CHAPTER 1:
Internet/Intranet Fundamentals of Database Development (with Delphi)
Mathematics Delphi as the database programming tool, Data Access with Delphi...just a few
words, Building a new MS Access database.
Multimedia Discuss about questions, comments, problems and solutions related to this chapter!
Delphi Pascal/IDE
CHAPTER 2:
Screen saver dev. Connecting to a database. BDE? ADO?
Connecting to a database. What is the BDE? What is ADO? How to connect to an
VCL Using
Access database - the UDL file? Looking forward: the smallest ADO example.
VCL Write/Enhance Discuss about questions, comments, problems and solutions related to this chapter!
Web Services
CHAPTER 3:
Windows/Shell/API Pictures inside a database
Kylix (D on Linux) Displaying images (BMP, JPEG, ...) inside an Access database with ADO and Delphi.
Discuss about questions, comments, problems and solutions related to this chapter!
Coding standards
CHAPTER 4:
Books/Publications Data browsing and navigation
Building a data browsing form - linking data components. Navigating through a
Dev. Utilities recordset with a DBNavigator.
Discuss about questions, comments, problems and solutions related to this chapter!
FAQs/Tips/Tricks
Free Code Projects
CHAPTER 5:
Humor and Fun Behind data in datasets
What is the state of data? Iterating through a recordset, bookmarking and reading
Icons and Glyphs the data from a database table.
Discuss about questions, comments, problems and solutions related to this chapter!
Jobs and Offers
Training/CD/Video
CHAPTER 6:
VCL & Tools Data modifications
Learn how to add, insert and delete records from a database table.
Discuss about questions, comments, problems and solutions related to this chapter!
Subject Library
CHAPTER 7:
Queries with ADO
All articles on this Take a look at how you can take advantage of the TADOQuery component to boost
topic your ADO-Delphi productivity.
Discuss about questions, comments, problems and solutions related to this chapter!
Advertising CHAPTER 9:
> Free Credit Report Searching for data
> Free Psychics Walking through various methods of data seeking and locating while developing
ADO based Delphi database applications.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 10:
ADO Cursors
How ADO uses cursors as a storage and access mechanism, and what you should
do to choose the best cursor for your Delphi ADO application.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 11:
From Paradox to Access with ADO and Delphi
Focusing on the TADOCommand components and using the SQL DDL language to
help porting your BDE/Paradox data to ADO/Access.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 12:
Master detail relationships
How to use master-detail database relationships, with ADO and Delphi, to deal
effectively with the problem of joining two database tables to present information.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 13:
New...Access Database from Delphi
How to create an MS Access database without the MS Access. How to create a
table, add an index to an existing table, how to join two tables and set up
referential integrity. No MS Access, only Pure Delphi code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 14:
Charting with Databases
Introducing the TDBChart component by integrating some basic charts into a
Delphi ADO based application to quickly make graphs directly for the data in
recordsets without requiring any code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 15:
Lookup!
See how to use lookup fields in Delphi to achieve faster, better and safer data
editing. Also, find how to create a new field for a dataset and discuss some of the
key lookup properties. Plus, take a look at how to place a combo box inside a
DBGrid.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 16:
Compacting an Access database with ADO and Delphi
While working in a database application you change data in a database, the
database becomes fragmented and uses more disk space than is necessary.
Periodically, you can compact your database to defragment the database file. This
article shows how to use JRO from Delphi in order to compact an Access database
from code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 17:
Database reports with Delphi and ADO
How to use QuickReport set of components to create database reports with Delphi.
See how to produce database output with text, images, charts and memos - quickly
and easily.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 18:
Data Modules
How to use the TDataModule class - central location for collecting and
encapsulating DataSet and DataSource objects, their properties, events and code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 19:
Handling database errors
Introducing error handling techniques in Delphi ADO database application
development. Find out about global exception handling and dataset specific error
events. See how to write an error logging procedure.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 20:
From ADO Query to HTML
How to export your data to HTML using Delphi and ADO. This is the first step in
publishing your database on the Internet - see how to create a static HTML page
from an ADO query.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 21:
Using ADO in Delphi 3 and 4 (before AdoExpress)
How to import Active Data Objects (ADO) type-libraries in Delphi 3 and 4 to create
a wrapper around components that encapsulate the functionality of ADO objects,
properties and methods.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 22:
Transactions in Delphi ADO database development
How many times have you wanted to insert, delete or update a lot of records
collectively wanting that either all of them get executed or if there is an error then
none is executed at all? This article will show you how to post or undo a series of
changes made to the source data in a single call.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 23:
Deploying Delphi ADO database applications
It is time to make your Delphi ADO database application available for others to run.
Once you have created a Delphi ADO based solution, the final step is to successfully
deploy it to the user's computer.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 24:
Delphi ADO/DB programming: Real Problems - Real Solutions
In real world situations, really doing database programming is much more complex
than writing about. This chapter points to some great Delphi Programming Forum
threads initiated by this Course - discussions that solve problems on the field.
CHAPTER 25:
TOP ADO programming TIPS - DB/25
Collection of frequently asked questions, answers, tips and tricks about ADO
programming.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 26:
Quiz: Delphi ADO Programming - DB/26
What would it look like: Who Wants to be a Delphi ADO Database Programming
Guru - the trivia game.
Discuss about questions, comments, problems and solutions related to this chapter!
Before this course started, there was an online poll asking for you to decide: what type of
data access mechanism are you most interested in. After more than 9000 votes it seems
that most of you are primarily interested in ADO/MS Access approach. From the fifth version
Delphi supports ADO with ADOExpress. AdoExpress components are available with the
Enterprise version of Delphi 5 and can be bought by the owners oh the Professional version.
Prior to version 5 Delphi does not support ADO. In order to participate in this course you'll
have to get your hands on AdoExpress or some other ADO enabled component set. Some of
the third-party ADO data-components can be found here: ADO Delphi VCL components. Most
of the techniques that are to be addressed in the following chapters to this course should be
easily translated and used with Paradox/dBase or Interbase users.
Those are the poll results ("What approach would you like to learn?"):
. ADO/MSAccess 4625 votes (51%)
. Paradox - BDE 167 votes (2%)
. dBase - BDE 66 votes (1%)
. Interbase 4227 votes (47%)
Get informed when the next chapter of this course becomes available online:
Name Email
subscribe
Of course, don't forget to join the Forum where all the questions are
answered and beginners are treated as experts:
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Fundamentals of Database
· A Beginner’s Guide to Development
Page 1: Delphi as the database programming tool.
Delphi Programming
More of this Feature
· Free course: Delphi Many Delphi beginners start with • Page 2: New...Database
Training/CD/Video
More Delphi
VCL & Tools · Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
Subject Library · Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
All articles on this
· NEXT ARTICLE: Inside the EXE.
topic Storing more that just code in the application executable file. Working with
resources from Delphi.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Fundamentals of Database
· A Beginner’s Guide to Development
Page 2: Building a new Database.
Delphi Programming
More of this Feature
· Free course: Delphi Before we start interacting with • Page 1: Fundamentals
databases using Delphi, it is a good
ADO DB programming Printer friendly version
idea to get a feel what modern
· Delphi for .NET databases are about. Join the Discussion
When you think of a word database
· Free code APPs & "Post your views and
you should generally think of any type comments to this chapter of
VCL of data stored inside a computer - the free Delphi database
even a SomeFile.pas file (code to Programming Course"
· A-Z Site Index some Delphi unit) is some kind of Discuss!
database. Another type of database is
BUYER'S GUIDE Related Resources
a Word document or a simple .ini file.
• free DB Course.TOC
To access an .ini file we generally use
• Delphi DB articles
What's New and Hot routines and techniques for typed or
untyped files.
Top Picks-Tool/VCL Elsewhere on the Web
• About Databases
Building a modern database • Database Design and
Beginners Here application requires us to think of Modeling
COM/OLE/ActiveX data in a relational way. The basic • Fundamentals of Relational
idea behind the relational model is Database Design
Database that a database consists of a series of
Distrubuted comp. tables (or relations) that can be
manipulated using operations that return tables or so-called
Mathematics
To fully address the concepts of database design and relational
Multimedia model we would need an extra online course. For a great
overview check out the Fundamentals of Relational Database
Delphi Pascal/IDE
Design.
Screen saver dev.
VCL Using New...Database
Since this course will primarily focus on ADO/Access Delphi
VCL Write/Enhance approach to database programming we will now see how to
Web Services create a new .mdb database in MS Access.
If you have never built a database with MS Access, go see MS
Windows/Shell/API Access tutorials for a great info.
Kylix (D on Linux)
I hope you know that on this site there is a Members Area where
Coding standards Delphi developers can upload their free code applications and
components. Each member has it's name, an email address and
Books/Publications
a possibly a web page. If we would like to keep track of every
Dev. Utilities application posted to this community we could assemble a
database of three tables: Applications (general information about
FAQs/Tips/Tricks an application), Authors (who made the application) and Types
Free Code Projects (what kind of app is it). Let's see how to do just that:
The Types table contains only one field: TypeName which is the
Stay up-to-date! primary key for this table. This table will be used to store the
Subscribe to our type of application (graphical, multimedia, database, ...)
newsletter.
Enter Email Go! We now only have to set up a relation in the relationships
window and the database is ready.
Advertising
> Free Credit Report
> Free Psychics
More Delphi
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Connecting to a database. BDE? ADO?
Page 1: Delphi database connectivity.
· A Beginner’s Guide to More of this Feature
Delphi Programming As shown in the previous chapter of • Page 2: the BDE
• Page 3: ADO, ADO Objects
· Free course: Delphi this course, a database is a collection
• Page 4: Connecting to a
of one or more tables that store data
ADO DB programming database
in a structured format. These tables,
· Delphi for .NET contain data that is represented by
rows and fields. When a database Join the Discussion
· Free code APPs & consists of two or more tables, these "Post your views and
tables generally contain separate yet comments to this chapter of
VCL
related data. MS Access, Interbase or the free Delphi database
· A-Z Site Index SQL Server use a single file (Access, Programming Course"
Discuss!
the *.mdb file) that represents the
BUYER'S GUIDE entire database. On the other hand, Related Resources
Paradox and dBase databases are
• free DB Course.TOC
defined with separate tables and files • Delphi DB articles
What's New and Hot that represent indexes and table
Top Picks-Tool/VCL relations. All the files needed to
describe a Paradox database are
usually stored in a single directory.
Beginners Here Delphi, of course, has means of working with both approaches.
COM/OLE/ActiveX
Database With Delphi, we can connect to different types of databases:
local or client/server (remote server) database. Local databases
Distrubuted comp. are stored on your local drive or on a local area network. Remote
database servers usually reside on a remote machine. Types of
Game Programming local databases are Paradox, dBase and MS Access. Types of
client/server databases are MS SQL Server, Interbase or Oracle.
Graphics Local databases are often called single-tiered databases. A single-
Internet/Intranet tiered database is a database in which any changes, such as
editing the data, inserting records, or deleting records - happen
Mathematics immediately. Single-tiered databases are limited in how much
Multimedia data the tables can hold and the number of users your
application can support. When the database information includes
Delphi Pascal/IDE complicated relationships between several tables, or when the
number of clients grows, you may want to use a two-tiered or
Screen saver dev.
multi-tiered application. Client applications run on local
VCL Using machines; the application server is typically on a server, and the
database itself might be on another server. The idea behind the
VCL Write/Enhance
multi-tier architecture is that client applications can be very
Web Services small because the application servers do most of the work. This
enables you to write what are called thin-client applications.
Windows/Shell/API
Kylix (D on Linux) When we write a database application in Delphi, we need to use
some database engine to access a data in a database. The
Coding standards database engine permits you to concentrate on what data you
want to access, instead of how to access it. From the first
Books/Publications version, Delphi provides database developers with the BDE
(Borland Database Engine). Beside the BDE, Delphi from the fifth
Dev. Utilities
version supports Microsoft ADO database interface.
FAQs/Tips/Tricks
Free Code Projects This course will primarily focus on MS Access local database
producing the single-tiered application.
Humor and Fun
Icons and Glyphs Next page > The BDE > Page 1, 2, 3, 4
Jobs and Offers
All graphics (if any) in this feature created by Zarko Gajic.
Training/CD/Video
VCL & Tools More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
Subject Library · Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
All articles on this TOPIC.
topic · NEXT ARTICLE: "The Big Brother" Delphi code toolkit.
Going undercover: hiding from the task list, disabling task-switch, removing
from the TaskBar, disabling shut down, ...
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Stay up-to-date! Got some code to share? Got a question? Need some help?
Subscribe to our Recent Discussions
newsletter. Delphi Programming
Enter Email Go! Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Connecting to a database. BDE? ADO?
Page 2: The Borland Database Engine
· A Beginner’s Guide to More of this Feature
Delphi Programming The BDE is a common data access • Page 1: Delphi database
connectivity
· Free course: Delphi layer for all of Borland's products,
• Page 3: ADO, ADO Objects
including Delphi and C++Builder. The
ADO DB programming • Page 4: Connecting to a
BDE consists of a collection of DLLs
database
· Delphi for .NET and utilities. The beauty of the BDE is
the fact that all of the data
· Free code APPs & manipulation is considered Join the Discussion
"transparent" to the developer. BDE "Post your views and
VCL
comes with a set of drivers that comments to this chapter of
· A-Z Site Index enables your application to talk to the free Delphi database
several different types of databases. Programming Course"
Discuss!
BUYER'S GUIDE These drivers translate high-level
database commands (such as open or Related Resources
post) and tasks (record locking or • free DB Course.TOC
What's New and Hot SQL construction) into commands • BDE and Delphi
Top Picks-Tool/VCL specific to a particular database type:
Paradox, dBASE, MS Access or any
Elsewhere on the Web
ODBC data source. The BDE API
Beginners Here • BDE Alternative
(Application Programming Interface)
COM/OLE/ActiveX consists of more than 200 procedures
and functions, which are available through the BDE unit.
Database Fortunately, you almost never need to call any of these routines
Distrubuted comp. directly. Instead, you use the BDE through the VCL's data access
components, which are found on the Data Access page of
VCL Using
Delphi applications that use the BDE to access databases require
VCL Write/Enhance that you distribute the BDE with the application. When deploying
the BDE with an application, you must use InstallShield Express
Web Services or another Borland certified installation program.
Windows/Shell/API
The BDE has several advantages as well as disadvantages as a
Kylix (D on Linux)
database engine. It's not my intention to discuss about why and
when you should (or not) use the BDE approach over some non-
Coding standards BDE technique.
Books/Publications
Since this course is about ADO/MSAccess the rest of the course
Dev. Utilities will focus on this non-BDE database approach.
FAQs/Tips/Tricks
Next page > The ADO > Page 1, 2, 3, 4
Free Code Projects
Humor and Fun
All graphics (if any) in this feature created by Zarko Gajic.
Icons and Glyphs
Jobs and Offers More Delphi
· Learn another routine every day - RTL Quick Reference.
Training/CD/Video · Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
VCL & Tools
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
Subject Library TOPIC.
· NEXT ARTICLE: "The Big Brother" Delphi code toolkit.
Going undercover: hiding from the task list, disabling task-switch, removing
All articles on this from the TaskBar, disabling shut down, ...
Stay informed with all new and interesting things about Delphi (for free).
topic
Subscribe to the About Programming Newsletter
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Connecting to a database. BDE? ADO?
Page 3: The ADO programming model.
· A Beginner’s Guide to More of this Feature
Delphi Programming As stated in the Introducing ADO in • Page 1: Delphi database
connectivity
· Free course: Delphi Delphi article, ADO is a set of COM
• Page 2: the BDE
components (DLLs) that allow you to
ADO DB programming • Page 4: Connecting to a
access databases as well as e-mail database
· Delphi for .NET and file systems. Applications built
with ADO components don't require
· Free code APPs & the BDE. Join the Discussion
VCL To access any kind of database with "Post your views and
ADO, you'll of course need to have comments to this chapter of
· A-Z Site Index ADO/OLE DB libraries. Everything you the free Delphi database
Programming Course"
need to use ADO is probably already
Discuss!
BUYER'S GUIDE on your computer: the files are
distributed by Microsoft as a part of Related Resources
Windows 98/2000. If you or your • free DB Course.TOC
What's New and Hot
client use Windows 95 or Windows NT • Delphi DB articles
Top Picks-Tool/VCL you will probably need to distribute
and install the ADO engine. Delphi 5's Elsewhere on the Web
CD includes an installation of MDAC -
Beginners Here • MS Data Access Page
Microsoft Data Access Components.
• Data access dilemma -
COM/OLE/ActiveX You should always make sure to have
BDE/ADO
the latest version, which is available
Database from Microsoft. The Microsoft Data
Distrubuted comp. Access Components are the key technologies that enable
Universal Data Access. They include ActiveX Data Objects (ADO),
More Delphi
Stay up-to-date! · Learn another routine every day - RTL Quick Reference.
Subscribe to our · Download free source code applications and components.
newsletter. · Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
Enter Email Go!
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
Advertising
· NEXT ARTICLE: "The Big Brother" Delphi code toolkit.
> Free Credit Report
Going undercover: hiding from the task list, disabling task-switch, removing
> Free Psychics from the TaskBar, disabling shut down, ...
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Connecting to a database. BDE? ADO?
Page 4: Connecting to a database with ADOExpress.
· A Beginner’s Guide to More of this Feature
Delphi Programming Before going on to the brief explanation of • Page 1: Delphi database
each component in AdoExpress collection, connectivity
· Free course: Delphi • Page 2: the BDE
let's first see how to connect to an Access
ADO DB programming database. Of course, we will be connecting • Page 3: ADO, ADO Objects
to our AboutDelphi.mdb sample database. Printer friendly version
· Delphi for .NET
· Free code APPs & Delphi (5) ADO support is concentrated in Join the Discussion
VCL the ADOExpress components on the ADO "Post your views and
tab of the component palette. Several other comments to this chapter of
· A-Z Site Index the free Delphi database
database enabled components will be used Programming Course"
through this course. For the moment we Discuss!
BUYER'S GUIDE will focus on the minimal set of components
needed to access an Access database with Related Resources
What's New and Hot ADO. • free DB Course.TOC
• Delphi DB articles
Top Picks-Tool/VCL
Start Delphi, this will open a new
application with one blank form. Elsewhere on the Web
Beginners Here • MS Data Access Page
In order to be able to access data in an • UDL Files — Microsoft Data
COM/OLE/ActiveX
Link Files
Access database with ADO and Delphi, you
Database must add at least three data aware
Distrubuted comp. components to our project. First, the DBGrid on the DataControls
component page - used to browse through the records retrieved from
Game Programming a table or by a query. Second, the DataSource (DataAccess Page)
used to provide a link between a dataset and DBGrid component on a
Graphics
form that enable display, navigation, and editing of the data
Internet/Intranet underlying the dataset. And finally the ADOTable (ADO page) that
represents a table retrieved from an ADO data store. Drop all of them
Mathematics on a form. Let the names be the default one. The form should look
Multimedia something like:
Delphi Pascal/IDE
Screen saver dev.
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards If you run the application now, nothing is displayed in a Grid - of
course, we did nothing to really connect to a database. Note just one
Books/Publications more thing: only the Grid is displayed, the rest two component are
Dev. Utilities controls - unvisible to the user.
FAQs/Tips/Tricks
Link between components
Free Code Projects In order to display some data from a database we have to link all
three components together. Using the Object Inspector, set the
Humor and Fun following:
Icons and Glyphs
Jobs and Offers DBGrid1.DataSource = DataSource1
DataSource1.DataSet = ADOTable1
Training/CD/Video
VCL & Tools We have now reached the hard part, to really get the data from our
database we have to build a ConnectionString. This string indicates
where the database is physically stored and how we are accessing it.
Subject Library When you double click the ellipsis button at the ConnectionString
property of the AdoTable component you get the next dialog box:
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics
When building a connection string we have two choices: use the Data
Link File (.UDL) or build a connection string by hand. Let's build it.
Press the Build button - this pops up the Data Link Properties dialog.
This dialog has 4 pages. The Provider tab allows you to specify the
provider - select the Microsoft Jet 4.0 OLE DB Provider. The Next
button leads us to the second page: Connection. Select the ellipsis
button to browse for our database (AboutDelphi.mdb). Press the Test
Connection button to see if the connection is successful - it should be.
Leave all the other pages as they are. Finally, click on OK to close the
Data Link Properties dialog, again OK to close the ConnectionString
dialog - the connection string is stored in the ConnectionString
property of the ADTTable component. The connection string should
look something like:
Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\!gajba\About\aboutdelphi.mdb;
Persist Security Info=False
ADOTable1.TableName = Applications
If you want to see the data at design time use the ADOTable Active
property - set it to True.
Ha! If you have done all the steps you now see the only one record
(row) in the Applications table. When you start the application you can
even change the data in the database. Of course, you cannot do much
more - this is the simplest ADO example I could think of.
This concludes this chapter. In the next chapter we will address all the
ADO component provided with Delphi and how they communicate with
the rest data-aware components to crate a powerfull Delphi database
application.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: "The Big Brother" Delphi code toolkit.
Going undercover: hiding from the task list, disabling task-switch, removing from
the TaskBar, disabling shut down, ...
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy
| Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Pictures inside a database
Page 1: Working with BLOBs. Storing pictures in Access.
· A Beginner’s Guide to More of this Feature
Delphi Programming These days developing database • Page 2: DBImage.NOT
applications requires more than just • Page 3: Streaming JPG
· Free course: Delphi • Page 4: JPG SOI marker
operating with textual or numeric
ADO DB programming data. If you are, for example, • Page 5: Project's Code
developing an Internet/intranet or
· Delphi for .NET multimedia based application,
Join the Discussion
"Post your views and
· Free code APPs & frequently there is a need to display comments to this chapter of
pictures along with text from a the free Delphi database
VCL
database. Programming Course"
· A-Z Site Index Discuss!
Delphi Pascal/IDE
If you scroll right to the last column of the DBGrid you'll see
Screen saver dev. something like:
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
When using MS Access, we can store images (and other large
FAQs/Tips/Tricks data objects such as sound or video) in a field that has the OLE
Free Code Projects object type. This type of data is referred to as a Binary Large
Object Bitmap (BLOB).
Humor and Fun
Icons and Glyphs Naturally when working with images, several types of picture
formats are available. The most commonly used include JPEG,
Jobs and Offers
GIF and BMP. JPEG format has proven to be widely accepted by
Training/CD/Video Web masters because of the small amount of storage required
(in other words JPEGs are smaller than BMPs in bytes).
VCL & Tools
Delphi, of course, has means of handling BMP, GIF and JPEG
Subject Library graphic formats. The rest of this article will deal with JPEG file
formats.
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
To add an image do the following:
> Free Psychics
Next page > Pulling the Jpeg with DBImage - the wrong way >
Page 1, 2, 3, 3, 5
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: Owner and Parent.
The differences between a component Owner and its Parent - briefly
explained.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Pictures inside a database
Page 2: Pulling the Jpeg with DBImage - the wrong way.
· A Beginner’s Guide to More of this Feature
Delphi Programming The DBImage - take one • Page 1: BLOBs in Access
The first thing I do when trying to do • Page 3: Streaming JPG
· Free course: Delphi • Page 4: JPG SOI marker
something new with Delphi is to "ask"
ADO DB programming Delphi Help for help. This is what the • Page 5: Project's Code
Help system replies: TDBImage (Data
· Delphi for .NET Controls page on the component
Join the Discussion
"Post your views and
· Free code APPs & palette) represents a graphic image comments to this chapter of
from a BLOB (binary large object) the free Delphi database
VCL
field of the current record of a Programming Course"
· A-Z Site Index dataset. Use TDBImage to represent Discuss!
the value of graphic fields. TDBImage
Related Resources
BUYER'S GUIDE allows a form to display graphical
data from a dataset. The DBImage is • free DB Course.TOC
nothing more than a TImage • Delphi DB articles
What's New and Hot component with some data aware
Top Picks-Tool/VCL properties. The two most important
ones are: DataSource and Field. The DataSource property links
the image component to a dataset. We have a DataSoure
Beginners Here component named DataSource1 on our form that represent a
COM/OLE/ActiveX dataset. The Field property indicates the field (in a table) that
holds the image.
Database
Distrubuted comp. All clear, put a DBImage on form and leave the DBImage1
name. To actually link a DBImage with a BLOB field in a Table
Game Programming we simply need to do the following assignment (using the Object
Inspector):
Graphics
Internet/Intranet DBImage1.DataSource = DataSource1
DBImage1.Field = Picture
Mathematics
Multimedia This should do the trick of displaying the JPEG image stored in
Delphi Pascal/IDE the Picture field of the Applications table.
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Now what? Why does it say "Bitmap image is not valid." We
Free Code Projects have a JPEG picture not the BMP - is this the problem? Let's go
Humor and Fun back to the Help.
Icons and Glyphs After a few clicks through the Help the conclusion is: to get the
Jobs and Offers JPG inside a database we need to use the TJpegImage object. To
display the picture we need the simple, non-data aware, version
Training/CD/Video of the Image component. Even more we'll need to use streams
VCL & Tools to load a picture from a BLOB object. The Help states that we
should use TADOBlobStream to access or modify the value of a
BLOB or memo field in an ADO dataset.
Subject Library
Next page > Streaming the Jpeg - the wrong way > Page 1, 2,
3, 4, 5
All articles on this
topic All graphics (if any) in this feature created by Zarko Gajic.
More Delphi
Stay up-to-date! · Learn another routine every day - RTL Quick Reference.
Subscribe to our · Download free source code applications and components.
newsletter. · Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
Enter Email Go!
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
Advertising
· NEXT ARTICLE: Owner and Parent.
> Free Credit Report
The differences between a component Owner and its Parent - briefly
> Free Psychics explained.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Pictures inside a database
Page 3: Streaming the Jpeg - the wrong way.
· A Beginner’s Guide to More of this Feature
Delphi Programming Pulling the Jpeg - take two! • Page 1: BLOBs in Access
Since we can do nothing with the DBImage - • Page 2: DBImage.NOT
· Free course: Delphi • Page 4: JPG SOI marker
remove it from the form and place an ordinary
ADO DB programming TImage component (Additional palette) on it. • Page 5: Project's Code
Name it ADOImage. Unfortunately the Image
· Delphi for .NET component does not have any data-aware
Join the Discussion
"Post your views and
· Free code APPs & properties, so all the code needed to show a comments to this chapter of
picture from a table inside it will require a the free Delphi database
VCL
separate procedure. The easiest thing to do is Programming Course"
· A-Z Site Index to put a Button on a form and place all the Discuss!
code inside it's OnClick event. Name the
Related Resources
BUYER'S GUIDE button 'btnShowImage'.
• free DB Course.TOC
• Delphi DB articles
To use the ADOBLOBStream the Help suggests
What's New and Hot
to create an instance of TADOBlobStream, use
Top Picks-Tool/VCL the methods of the stream to read from a
graphic field in a dataset, and then free the BLOB stream. Somewhere
"in the middle" we'll need to use LoadFromStream to load a Jpeg image
Beginners Here
from a TADOBlobStream object. The Image's component Picture.Graphic
COM/OLE/ActiveX property will be used to actually store and display the picture.
Database
Distrubuted comp.
Game Programming
Graphics
Internet/Intranet
Windows/Shell/API
The TADOBlobStream Create method creates an instance of
Kylix (D on Linux)
TADOBlobStream for reading from or writing to a specific BLOB field
object, which is in our case the ADOTable1Picture field.
Coding standards
Books/Publications We will place the code in the OnClick event for a btnShowImage button.
The code should read the picture from the Picture field of the currently
Dev. Utilities selected row. This is how the code should look like:
FAQs/Tips/Tricks
Free Code Projects
uses jpeg;
Humor and Fun
...
Icons and Glyphs procedure TForm1.btnShowImageClick(Sender: TObject);
Jobs and Offers var
bS : TADOBlobStream;
Training/CD/Video Pic : TJpegImage;
VCL & Tools begin
bS := TADOBlobStream.Create
(AdoTable1Picture, bmRead);
Subject Library
try
Pic:=TJpegImage.Create;
All articles on this try
topic Pic.LoadFromStream(bS);
ADOImage.Picture.Graphic:=Pic;
finally
Stay up-to-date!
Pic.Free;
Subscribe to our
newsletter. end;
finally
Enter Email Go!
bS.Free
end;
Advertising
> Free Credit Report end;
> Free Psychics
Ok, let's run the project now. Of course set the ADOTable1.Active
property to True. The form is displayed and after clicking on a button this
is what we got:
Hm, what now? The code in the procedure is 100% correct but the image
doesn't get displayed! Remember the "Never give up, never surrender"?
Let's go down to byte level to see what's happening!
Next page > Seeking the start of Jpeg in the BLOB - the correct way >
Page 1, 2, 3, 4, 5
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Owner and Parent.
The differences between a component Owner and its Parent - briefly explained.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
Beginners Here
COM/OLE/ActiveX
Database
Distrubuted comp.
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Free Code Projects
Humor and Fun
Icons and Glyphs
Jobs and Offers
Training/CD/Video
VCL & Tools
Subject Library
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
{
Article: Pictures inside a database
http://delphi.about.com/library/weekly/aa030601a.htm
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ExtCtrls, StdCtrls, Db, ADODB, Grids, DBCtrls, DBGrids;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
btnShowImage: TButton;
ADOImage: TImage;
ADOTable1Name: TWideStringField;
ADOTable1Description: TWideStringField;
ADOTable1Author: TWideStringField;
ADOTable1Type: TWideStringField;
ADOTable1Size: TFloatField;
ADOTable1Cost: TBCDField;
ADOTable1DateUpl: TDateTimeField;
ADOTable1Picture: TBlobField;
DBGrid1: TDBGrid;
procedure btnShowImageClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
JPEGstarts = 'FFD8';
BMPstarts = '424D'; //BM
var
Form1: TForm1;
implementation
uses jpeg;
{$R *.DFM}
end;
finally
bS.Free
end;
end;
ADOTable1.ConnectionString := sCons;
ADOTable1.TableName := 'Applications';
DataSource1.DataSet := ADOTable1;
DBGrid1.DataSource := DataSource1;
ADOTable1.Active:=True;
end;
SPicFileName := 'C:\!gajba\cdcovers\cdcover1.jpg';
SaveJpegToTable(ADOTable1, ADOTable1Picture, SPicFileName);
}
var
fS : TFileStream;
begin
fs:=TFileStream.Create(sPicPath, fmOpenRead);
try
Table.Edit;
PicField.LoadFromStream(fs);
Table.Post;
finally
fs.Free;
end;
end;
end.
{
********************************************
Zarko Gajic, BSCS
About.com Guide to Delphi Programming
http://delphi.about.com
email: delphi.guide@about.com
free newsletter: http://delphi.about.com/library/blnewsletter.htm
forum: http://forums.about.com/ab-delphi/start/
********************************************
}
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Data browsing and navigation
Page 1: Set and Connect
· A Beginner’s Guide to More of this Feature
Delphi Programming Welcome to the fourth chapter of a • Page 2: Browse and
free DB Delphi Course! So far, this navigate
· Free course: Delphi
course has provided enough
Join the Discussion
ADO DB programming information to connect to an Access
"Post your views and
· Delphi for .NET database and even to display a comments to this chapter of
graphical data inside a database the free Delphi database
· Free code APPs & table. In the last chapter we were Programming Course"
Discuss!
VCL discussing some *advanced*
database programming techniques - Related Resources
· A-Z Site Index let's go back to more *for beginners* • free DB Course.TOC
level now. • Coloring DBGrid
BUYER'S GUIDE
• Database Form Wizard
This time, you will see how to build a • Selecting Fields.howto
What's New and Hot form (the real one) that can be used
to browse through the records of a
Top Picks-Tool/VCL
database table.
All the examples presented in the previous chapters have used
Beginners Here several data-enabled (ADOTable, DBGrid, ...) components
without to much explaining what each component is designed
COM/OLE/ActiveX
for, and how all those data components link together.
Database
Distrubuted comp. Working together...
When developing ADO-based Delphi database applications, the
Game Programming components on the Data Controls page, the ADO page, and the
Data Access page of the component palette allow our application
Graphics to read from and write information to databases.
Internet/Intranet
Every (ADO) data-aware Delphi form, in general, consist of
Mathematics
· several data-aware controls (Data Controls tab) that create a
Multimedia visual user interface (the look of the data form).
· one DataSource component (Data Access tab) that represents
Delphi Pascal/IDE
an interface between a dataset component and data-aware
Screen saver dev. controls on a form.
· one or more dataset components (ADO tab) that provide
VCL Using access to the data residing in a database table or query.
VCL Write/Enhance · a connection component (ADO tab) that points all the dataset
components to a specific data store.
Web Services
Windows/Shell/API Data Controls
Delphi's data-aware components are components that normally
Kylix (D on Linux) reside on a Standard palette tab but have been modified to
display and manipulate the content of data in a dataset (table or
Coding standards query). The choice of controls is determined by how we want to
present the information and how we want to let users browse
Books/Publications
(and manipulate - add or edit) through the records of datasets.
Dev. Utilities DBEdit and DBMemo, for example, are used to represent an
individual record from a dataset. The DBGrid, on the other hand,
FAQs/Tips/Tricks is generally used when representing the contents of an entire
Free Code Projects dataset. Since all the data-aware controls are counterparts to
the standard Windows controls - with a few extra properties,
Humor and Fun building a functional database application should be a relatively
Icons and Glyphs familiar task.
All the data-aware components share one common property:
Jobs and Offers Data Source.
Training/CD/Video
Data Source
VCL & Tools Simply put, the DataSource component provides a mechanism to
hook dataset components to the visual data-aware components
that display the data. You generally will need one datasource
Subject Library component for each dataset component to present a link to one
or more data-aware controls.
All articles on this
Datasets
topic To create an ADO based application, Delphi provides us with four
dataset components: TAdoDataSet, TAdoTable, TAdoQuery and
TAdoStoredProc. All of the components are designed to retrieve,
present and modify the data. All those components can connect
directly (as like in the previous chapter's examples) to an ADO
data store (such as data in an Access database) through it's
ConnectionString property or they can chare a single connection.
When connecting through a TAdoConnection the Connection
specifies an ADO connection object to use to connect to an ADO
Now, when we know the theory it's time to see some action. The
next step is to build a data form. Before we move on, it'll be a
good idea to open the database with Access and add some
"dummy" data (3-4 records) to a database just to have some
operational data.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: Spell Checking with MS Word.
Why buy spell checking components or write them from scratch when you
can easily use MS Word? Find out how to add spell checking and thesaurus
capabilities to your Delphi application using the MS Word Object Library.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Data browsing and navigation
Page 2: Browse and navigate
· A Beginner’s Guide to More of this Feature
Delphi Programming There are two different ways of • Page 1: Set - Connect
COM/OLE/ActiveX
Before you start, close any open projects. Then use the following
Database steps:
Distrubuted comp.
● Select File|New Application. This creates a new project
components like:
Coding standards
DBNavigator1.DataSource = DataSource1
Books/Publications DBGrid1.DataSource = DataSource1
Dev. Utilities DataSource1.DataSet = ADOTable1
ADOTable1.Connection = ADOConnection1
FAQs/Tips/Tricks ADOConnection1.ConnectionString = ...
Free Code Projects ADOConnection1.LoginPrompt = False
ADOTable1.Table = 'Applications'
Humor and Fun
Icons and Glyphs Note: as discussed in the second chapter, the ConnectionString
property indicates where the data is physically stored and how
Jobs and Offers
we are accessing it. You can use the same connection string as
Training/CD/Video in the second chapter, or you can build one by invoking the
connection string editor.
VCL & Tools Setting the LoginPrompt property of the ADOConnection
component to False suppresses the database login from showing.
Since we have not set any password for our database we don't
Subject Library need the login prompt.
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics
Fields
The DBGrid component is generally used when we want to
present the entire recordset to the user (data in a table). Even
though we can use the DBGird to let the user add, edit and
delete records in a table - better approach is to use Field objects
for all the fields in a table. Field objects are mostly used to
control the display and editing of data in your applications. By
using the Fields Editor we can set the list of persistent field
object for every column in a table. The Field Editor is invoked by
double clicking the DataSet component (ADOTable1). To add
fields to the list of persistent fields for a dataset right-click the
list and choose Add Fields.
Rather than presenting all the data in a table to the user (within
the DBGrid), we might want to use field-oriented data aware
components, such as edit boxes. The DBEdit component for
example, is a data-aware version of the TEdit class. DBEdit is the
building block of any data entry application.
When you drop the Name field on the tabsheet, Delphi places
one Label and one DBEdit component on it. The Caption of the
Label component is the same as the DisplayLabel property of the
dragged field. The DBEdit component is linked to the dataset's
datasource through it's DataSource property.
If you select more than one filed from the Fields Editor and drag
it on the form, Delphi will set as much Label/DBEdit components
as you have dropped on the form.
It's alive
Ok, all set up. Everything we have to do now is to activate the
connection and scroll through the records. The Active property of
a dataset component (ADOTable) indicates whether we have a
live connection to a table or not. Setting the Active to True or
calling the Open method sets the Connected property of the
ADOConnection to True - and displays the data in related data-
aware controls.
Using the button set we are able to skip to the last record or
move to the previous one. For example, clicking on the Last
button sets the current record to the last record in the recordset
and disables the Last and Next buttons. Clicking the Last button
is functionally the same as calling the Last method of a dataset.
Note that one of the navigational operations that the
DBNavigator cannot process is moving forward or backward in a
recordset by a number or records. The MoveBy method of a
dataset is used to position the cursor on a record relative to the
active record in the recordset.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
Spell Checking with MS Word.
Why buy spell checking components or write them from scratch when you
can easily use MS Word? Find out how to add spell checking and thesaurus
capabilities to your Delphi application using the MS Word Object Library.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Behind data in datasets
Page 1: The State of Data
· A Beginner’s Guide to
Delphi Programming More of this Feature
When developing database • Page 2: From BOF to EOF
· Free course: Delphi
applications with Delphi and ADO,
Join the Discussion
ADO DB programming most of the work is done with the
"Post your views and comments
· Delphi for .NET help of dataset components. To
to this chapter of the free Delphi
create an ADO based application, database Programming Course"
· Free code APPs & Delphi provides us with several Discuss!
dataset components. TAdoTable,
VCL
TAdoQuery and others are all Related Resources
· A-Z Site Index designed to retrieve, present and • free DB Course.TOC
modify the data inside a database • Database tutorials
BUYER'S GUIDE table or query. • Selecting Fields.howto
In this fifth chapter of the free
database course we'll see exactly
What's New and Hot how to present, navigate and read the data - by looking at some
Top Picks-Tool/VCL of the most interesting datasets properties, events and methods.
Game Programming The only (ADO) dataset component we used, by now, was
TAdoTable. It's important to know that both TADOQuery and
Graphics
TADODatSet (as dataset components) share the same set of
Internet/Intranet common methods and events.
Mathematics
Open Sesame ; Close Sesame
Multimedia One of the great features of Delphi database development is that
Delphi Pascal/IDE Delphi enables us to work directly with the data while in design-
mode. If you recall - in the previous chapters we used the Active
Screen saver dev. property at design time to open the live connection with the
data.
VCL Using
It's understandable, that prior to working with the data in a
VCL Write/Enhance table, an application must first open a dataset. Delphi has two
methods of performing this function. As we already saw, the
Web Services Active property can be set to True at design or run time. We can
Windows/Shell/API also call the Open method at run time. For example, add the
following code to the form's OnCreate event handler to get the
Kylix (D on Linux) data from the ADOTable1 component:
ADOTable1.Close;
Subject Library
Before moving on, it's crucial to know that working with
All articles on this dataset's methods and properties relies on knowing the current
state of the data. Simply put, the State property of a dataset
topic determines what actions can and cannot occur at any moment
on a dataset.
Stay up-to-date! data is in. For example, when we connect a dataset to a DBGrid,
Subscribe to our the user is able to see the underlying dataset (or recordset), but
newsletter. to be able to change some of the data the State must be
Enter Email Go! changed to Edit.
Advertising It's important to know that the dataset state constantly changes
> Free Credit Report as an application processes data. If, for example, while browsing
the data in a DBGrid (Browse state) the user starts editing the
> Free Psychics
records the state will automatically change to Edit. Of course,
this is the default behaviour of the data-aware controls (DBGrid,
DBEdit) with their AutoEdit property set to True.
But, how do we get the state? The ADOTable (nor any other
dataset component) doesn't have an event that triggers when
the State changes.
Ok, let's see: for each dataset component we generally use one
datasource component to present a link to one or more data-
aware controls. That's it.
procedure TForm1.DataSource1StateChange
(Sender: TObject);
var ds: string;
begin
case ADOTable1.State of
dsInactive: ds:='Closed';
dsBrowse : ds:='Browsing';
dsEdit : ds:='Editing';
dsInsert : ds:='New record inserting';
else
ds:='Other states'
end;
Caption:='ADOTable1 state: ' + ds;
end;
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: Easter Eggs.
Looking for some hidden fun in Delphi? Find out what are Easter Eggs and
how to add them to your applications. See how to add cheat codes to your
Delphi games.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Behind data in datasets
Page 2: From BOF to EOF and back in the Middle
· A Beginner’s Guide to
Delphi Programming More of this Feature
In the last chapter we used the • Page 1: The State of Data
· Free course: Delphi
DBNavigator component to navigate Printer friendly version
ADO DB programming through the dataset. This
· Delphi for .NET component presents a visual tool for Join the Discussion
navigating through a dataset. As "Post your views and comments
· Free code APPs & stated, the DBNavigator has buttons to this chapter of the free Delphi
VCL that the user can click to move database Programming Course"
among dataset's records at run- Discuss!
· A-Z Site Index time.
Related Resources
BUYER'S GUIDE • free DB Course.TOC
Moving on from BOF to EOF • Database tutorials
To iterate through a recordset and • Selecting Fields.howto
What's New and Hot to sum some values we'll need to
use methods of a dataset
Top Picks-Tool/VCL component. Take a look at the following code:
Beginners Here
COM/OLE/ActiveX
Database
Distrubuted comp.
ADOTable1Type.Value
ADOTable1.Fields[x].Value
ADOTable1.FieldByName('Type').Value
Note: All fields of a dataset are stored in the Fields array. x represents the
position of the field in the fields array.
The Value property for a field object holds the data value. Since
Value is a varian type it's preferable to cast fields value to a type
that we currently need. In other words an application should use
the AsString property to convert a value (date, integer,
currency, ...) in a field to a string when the string representation
of the fields value is needed.
That's it for the fifth chapter. Next time we'll see how to add,
delete and insert recordset to a database table.
More Delphi
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Data modifications
Chapter six of the free Delphi Database Course for beginners.
· A Beginner’s Guide to Learn how to add, insert and delete records from a database
Delphi Programming table.
COM/OLE/ActiveX
To follow this article you'll need to create a data form similar to ones
Database we were creating in the previous chapters. Use the standard set
(DataSource, ADOTable and ADOConnection) of components to
Distrubuted comp.
connect to our Access database. This time we will be exploring the
Game Programming Authors table. Recall that the Authors table has three fields (columns):
AuthorName, Email and Web. All three are text fields, in the first
Graphics chapter we added one "dummy" record.
Internet/Intranet
Mathematics
Multimedia
Delphi Pascal/IDE
Screen saver dev.
VCL Using
VCL Write/Enhance
Web Services
Start a new Delphi project and on the default new form place all the
Windows/Shell/API data access components and a DBGrid and a DBNavigator. Use the
Kylix (D on Linux) Object Inspector to set the link between all those components. Set the
Table name of the ADOTable1 component to point to the Authors
table. You should already be familiar with the steps to achieve the
Coding standards connection. Use the Active property of the ADOTable to activate the
Books/Publications connection at design time. Or use the OnCreate/OnClose pair of event
handlers for the form to Open and Close the dataset at run-time.
Dev. Utilities
FAQs/Tips/Tricks One of the great advantages of database development with Delphi is
in the existance of the TField object. As already stated, in the previous
Free Code Projects chapters, database fields can be persistent or created dynamically. It
Humor and Fun is recommended to set the persistent list of fields for a (known)
dataset. By using the Object Inspector add all three fields to the list.
Icons and Glyphs Use dragging and dropping (as explained in the 5th chapter) to link a
Jobs and Offers data-aware DBEdits to fields in a database table.
Training/CD/Video
VCL & Tools
Subject Library
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go! Posting
When linking components in a way that the DBNavigator is used with
Advertising the data-aware components like the DBGrid operations like editing,
> Free Credit Report deleting and inserting new records to a table are done semi-
automatically. For example, suppose you are browsing the recordset
> Free Psychics
with the DBGrid. When you start retyping the text in some cell (editing
the value of the underlying field) the data is not modified until the
Post method is called. The Post method (of a dataset) plays the
central role in a Delphi database application.
When the dataset is in the Edit state, a call to Post modifies the
current record. The DBNavigator has the Post button (the one with the
check mark on it) that calls the Post method when clicked. You should
be aware of the fact that Post is called implicitly (for example) when
you move to the next record - just by pressing the down key while
editing in a DBGrid.
Editing a record
To be able to edit the data returned by a dataset the dataset must be
in the Edit state. The default behaviour of the data-aware controls
(DBGrid, DBEdit) with their AutoEdit property set to True is that once
the user starts editing the values in DBEdit controls the state changes
(from Browse) to Edit. No error occurs if we try to put a dataset in the
Edit state while the dataset is already in the Edit state.
ADOTable1.Edit;
ADOTable1AuthorName.AsString := 'Delphi Guide';
ADOTable1.Post;
The first line simply puts the dataset in the Edit state. The last one
Posts the data to the database. The second one assigns the string
value 'Delphi Guide' to the AuthorName field.
ADOTable1BeforeEdit
DataSource1StateChange
DataSource1DataChange
ADOTable1AfterEdit
ADOTable1AuthorNameValidate
ADOTable1AuthorNameChange
DataSource1DataChange
DataSource1StateChange
ADOTable1BeforePost
DataSource1StateChange
ADOTable1AfterPost
Note: the DBGrid and the appropriate DBEdit component are refreshed
to show the new value for the AuthorName field.
Note: the ADOTable component has the InsertRecord method that can
be used to create a new, empty record at in the dataset, fill fields with
values, and post the values to the database - all that with just one line
of code. The previous example could look like:
ADOTable1.InsertRecord('Zarko Gajic',
'gzarko@sf.hr',
'http://sf.hr')
"Undo" changes
While in the Edit (the user is changing the data) or in the Insert state
(a new record is to be added), the application can call the Cancel
method. The DBNavigator has the X sign on the appropriate button. If
the record is being edited the call to Cancel returns the original values
to connected data-aware components. If the insertion was canceled
the empty row is "deleted". Cancel returns dataset to Browse state.
Deleting a record
The button with the minus sign on the DBNavigator calls the Delete
method for the dataset. There is no need to call the Post method after
Delete. You can use the BeforeDelete event to attempt to prevent the
user from deleting the record from table. Note that the DBNavigator
has the ConfirmDelete property to help prevent the user from
accidentally deleting a record from the dataset. If you don't have the
DBNavigator connected to a dataset - pressing Ctrl+Delete in a
DBGrid calls the Delete method. If while executing the Delete method
an error occurs the OnDeleteError is triggered.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Compiler version directives.
Preparing to code with no barriers. See how to overcome the compiler version
problem: compiling Delphi code with various Delphi versions.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy
| Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
with Zarko Gajic Your Guide to one of hundreds of Search in this topic
sites
Home · Articles · Forums · Chat · Classifieds · Newsletters · Help
Shop for Holiday Gifts from merchants like Old Navy, Eddie Bauer, Spiegel, and more!
ESSENTIALS
Queries with ADO
Chapter seven of the free Delphi Database Course for beginners. Take a look
· A Beginner’s Guide to at how you can take advantage of the TADOQuery component to boost your
Delphi Programming ADO-Delphi productivity.
VCL Write/Enhance To make a Delphi form capable of retrieving the data from an Access database with
Web Services the ADOQuery component simply drop all the related data-access and data-aware
components on it and make a link as described in the previous chapters of this
Windows/Shell/API course. The data-access components: DataSource, ADOConnection along with
Kylix (D on Linux) ADOQuery (instead of the ADOTable) and one data-aware component like DBGrid is
all we need.
As already explained, by using the Object Inspector set the link between those
Coding standards components as follows:
Books/Publications
DBGrid1.DataSource = DataSource1
Dev. Utilities
DataSource1.DataSet = ADOQuery1
FAQs/Tips/Tricks ADOQuery1.Connection = ADOConnection1
//build the ConnectionString as described in the second chapter.
Free Code Projects ADOConnection1.ConnectionString = ...
Humor and Fun ADOConnection1.LoginPrompt = False
The above code, at run-time, closes the dataset, empties the SQL string in the SQL
property, assigns a new SQL command and activates the dataset by calling the Open
method.
Note that obviously creating a persistent list of field objects for an ADOQuery
component does not make sense. The next time you call the Open method the SQL
can be so different that the whole set of filed names (and types) may change. Of
course, this is not the case if we are using ADOQuery to fetch the rows from just one
table with the constant set of fields - and the resulting set depends on the WHERE
part of the SQL statement.
Dynamic queries
One of the great properties of the TADOQuery components is the Params property. A
parameterized query is one that permits flexible row/column selection using a
parameter in the WHERE clause of a SQL statement. The Params property allows
replacable parameters in the predefined SQL statement. A parameter is a placeholder
for a value in the WHERE clause, defined just before the query is opened. To specify a
parameter in a query, use a colon (:) preceding a parameter name.
At design-time use the Object Inspector to set the SQL property as follows:
When you close the SQL editor window open the Parameters
window by clicking the ellipsis button in the Object
Inspector.
At run-time, the parameters can be changed and the query re-executed to refresh
the data. In order to execute a parameterized query, it is necessary to supply a value
for each parameter prior to the execution of the query. To modify the parameter
value, we use either the Params property or ParamByName method. For example,
given the SQL statement as above, at run-time we could use the following code:
In general ADOQuery component should not be used when editing takes place. The
SQL based queries are mostly used for reporting purposes. If your query returns a
result set, it is sometimes possible to edit the returned dataset. The result set must
contain records from a single table and it must not use any SQL aggregate functions.
Editing of a dataset returned by the ADOQuery is the same as editing the ADOTAble's
dataset.
An example
To see some ADOQuery action we'll code a small example. Let's make a query that
can be used to fetch the rows from various tables in a database. To show the list of
all the tables in a database we can use the GetTableNames method of the
ADOConnection component. The GetTableNames in the OnCreate event of the form
fills the ComboBox with the table names and the Button is used to close the query
and to recreate it to retrieve the records from a picked table. The () event handlers
should look like:
Note that all this can be done by using the ADOTable and it's TableName property -
much easily.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Converting WAV to MP3 and back.
A brief introduction to the windows Audio Compression Manager API.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of
About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Data filtering
Chapter eight of the free Delphi Database Course for beginners.
· A Beginner’s Guide to Using Filters to narrow the scope of data that is presented to the
Delphi Programming user.
Mathematics TADOQuery), it can be set at both design and run time. Filter property
represents a string that defines the filter criteria.
Multimedia For example, if you want to limit the displayed data (from the
Delphi Pascal/IDE Applications table) to freeware applications (cost $0.00), a filter such as
the following will only display records that meet the condition:
Screen saver dev.
VCL Using
ADOTable1.Filter := 'Cost = 0';
VCL Write/Enhance
Web Services
Windows/Shell/API You can also add a value for Filter based on the text entered in a control.
If the filtered dataset should only display free applications and you want
Kylix (D on Linux) to enable users to supply the type of the applications, a filter could be
set as follows:
Coding standards
Books/Publications ADOTable1.Filter :=
Dev. Utilities 'Cost = 0 AND
Type = ' + QuotedStr(Edit1.Text);
FAQs/Tips/Tricks
Free Code Projects
Humor and Fun By using combinations of the following operators, you can create quite
Icons and Glyphs sophisticated filters.
Stay up-to-date!
Filtered, FilterOptions, FilterGroup, OnFilterRecord
Subscribe to our
The Filtered property is a Boolean value (True or False) that determines
newsletter.
if the string in the Filter property is used to filter the dataset. When
Enter Email Go! Filtered is False, the filtering is ignored and the complete dataset is
available to the application.
Advertising
> Free Credit Report The FilterOptions is a set of two values - both used when filtering string
> Free Psychics fields. If the foCaseInsensitive is included in the FilterOptions,
comparison between the literal in the Filter property string and the field
values are case-insensitive. The foNoPartialCompare forces Delphi to
treat the asterisks (*) as a literal character rather than as wildcard. By
default, FilterOptions is set to an empty set.
The OnFilterRecord event fires each time the filtering is enabled and a
new record becomes the current one. You will generally use this event to
filter records using a criterion that can't be (easily) implemented using
the Filter property.
procedure TForm1.ADOTable1FilterRecord
(DataSet: TDataSet; var Accept: Boolean);
var AppZipSize : Single;
begin
AppZipSize := ADOTable1.FieldByName('size').Value;
Accept := (AppZipSize < 10);
end;
The key element here is the Accept parameter. You set the Accept
parameter to True for any rows that you want to show. The preceding
code sets Accept to True for any rows in which the Size field contains a
value that is less than 10 (all apps whose download size is less than 10
Kb).
statement.
● you can have multiple conditions, specified in the Filter property,
small. A filter is done on the fly, and may or may not use the current
index (filters are applied to every record retrieved in a dataset).
● filters are rarely used with client/server databases, a SQL query
(TADOQuery) should be used to achieve the same effect that filters have
on local databases.
● you should generally not use filtering with datasets on data modules.
In a specific situation when filtering a table that is never viewed from any
other form, or a table that makes use of a range, or sort order that is not
used anywhere else in the application - data modules *should* be
avoided.
● to search a filtered dataset, you can use the FindFirst, FindNext,
FindPrior, and FindLast methods. These methods are the best way to
search a filtered dataset because the filter is reapplied each time one of
these methods is called. Therefore, if records that previously did not
match the filter have been modified so that they now match the filter,
they will be included in the dataset before the search is performed.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Quick Reports Tutorial.
Extensive tutorial on printing with Quick Report components and Delphi.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Searching for data.
Chapter nine of the free Delphi Database Course for beginners.
· A Beginner’s Guide to Walking through various methods of data seeking and locating
Delphi Programming while developing ADO based Delphi database applications.
What's New and Hot Note: the rest of this chapter deals with the
aboutdelphi.mdb MS Access database that
Top Picks-Tool/VCL was introduced in the first chapter of this course. To use the code
examples presented in this chapter, set up the data form with the core
Beginners Here components (data-access and data-aware) as described in the previous
chapters. The following code examples will assume that you are working
COM/OLE/ActiveX with the ADOTable component pointing to the Applications table in our
Database database.
Distrubuted comp.
When you think of it, a searching algorithm could look like: start at the
Game Programming top of the table, examine the field in each row - to see if it matches the
criteria, stop the loop on the selected record or at the bottom row -
Graphics whichever comes first.
Internet/Intranet Hopefully, Delphi hides those *steps* from us. There are several ways
to locate a record in a dataset retrieved by an ADODataset (Table or
One advantage of the Locate and Lookup methods is that they don't
require the table to be indexed. However, the Locate function will use
the fastest method available to search the table; if a table is indexed,
Locate will use the index.
Indexing
When working with a Table component and the BDE (not ADO) Delhi
provides us with a number of functions that will search for values in a
database table. Some of these are Goto, GoToKey, GoToNearest, Find,
FindKey, Find Nearest, etc. For a complete reference see Delphi's help,
topic: Searching for records based on indexed fields. The ADO approach
does not support those methods, instead it introduces a Seek method.
Seek
The ADO datasets Seek method uses an index when performing a
search. If you don't specify an index and you are working with an Access
database, the database engine will use the primary key index.
Seek is used to find a record with a specified value (or values) in the
field (or fields) on which the current index is based. If Seek does not
find the desired row, no error occurs, and the row is positioned at the
end of the dataset. Seek returns a boolean value reflecting the success
of the search: True if a record was found or False if no matching record
was found.
ADOTable1.GetIndexNames(ComboBox1.Items);
table.
SeekOption Meaning
Record pointer positioned at the first matching record, if one is found, or
soFirstEQ
at the end of the dataset if one is not found
Record pointer positioned at the last matching record, if one is found, or
soLastEQ
at the end of the dataset if one is not found.
Record pointer positioned at matching record, if found, or just after
soAfterEQ
where that matching record would have been found.
Record pointer positioned just after where a matching record would
soAfter
have been found.
Record pointer positioned at matching record, if found, or just before
soBeforeEQ
where that matching record would have been found.
Record pointer positioned just before where a matching record would
soBefore
have been found.
Note 2: when you use the Seek method on multiple fields, the Seek
fields must be in the same order as the fields in the underlying table. If
they are not, the Seek method fails.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: A first look at Kylix<.
Taking a short trip to Linuxland - find out what Kylix has to offer to a Delphi developer
preparing to code cross-platform applications.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
ADO Cursors
Page 1: How ADO uses cursors as a storage and access
· A Beginner’s Guide to mechanism.
Delphi Programming
· Free course: Delphi More of this Feature
ADO DB programming Welcome to the chapter ten of the • Page 2: Cursor properties
free Delphi ADO Database Course
· Delphi for .NET Join the Discussion
for beginners. In the past nine
"Post your views and comments
· Free code APPs & chapters you were presented with to this chapter of the free Delphi
some of the basic techniques when database Programming Course"
VCL
developing ADO-based Delphi Discuss!
· A-Z Site Index applications. We've seen how
several data-access components are Related Resources
BUYER'S GUIDE used to connect and retrieve data • free DB Course.TOC
from an Access database. One thing
is for sure: ADOExpress components Elsewhere on the Web
What's New and Hot fit quite nicely into the Delphi data • Choosing and Managing
Top Picks-Tool/VCL access model and map very closely Cursors
to the basic data objects that ADO
uses to access data.
Beginners Here
COM/OLE/ActiveX However, the way you use ADOExpress components is quite
different from the traditional Delphi programming with the BDE
Database
based TTable, and TQuery components. If you're accustomed to
Distrubuted comp. working with the BDE dataset components, there are a number
of things you'll find different when you use ADO. The available
Web Services
Cursor?!
Windows/Shell/API The simplest definition would be: a query result set where
browsing is enabled and the current position is known.
Kylix (D on Linux)
Stay up-to-date!
All graphics (if any) in this feature created by Zarko Gajic.
Subscribe to our
newsletter.
More Delphi
Enter Email Go!
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
Advertising · Talk about Delphi Programming, real time. Start a chat now!
> Free Credit Report · Link to the Delphi Programming site from your Web pages.
> Free Psychics · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: Web Site inside a Delphi EXE .
How to store Web-style content inside a Delphi application.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
ADO Cursors
Page 2: CursorType, CursorLocation, LockType properties.
· A Beginner’s Guide to What you should do to choose the best cursor for your
Delphi Programming Delphi ADO application.
Game Programming Allows you to view additions, changes and deletions by other
users, and allows all types of movement through the Recordset
Graphics that don't rely on bookmarks; allows bookmarks if the provider
Internet/Intranet supports them. The Supports method of an ADODataset
indicates whether a recordset supports certain types of
Mathematics operations. The following statement can be used to check if the
Multimedia provider supports bookmarks:
if ADOTable1.Supports(coBookmark) then ...
Delphi Pascal/IDE Choose dynamic cursors if multiple users insert, update, and
delete rows in the database at the same time.
Screen saver dev.
VCL Using ctKeyset
VCL Write/Enhance Behaves like a dynamic cursor, except that it prevents you from
seeing records that other users add, and prevents access to
Web Services records that other users delete. Data change by other users will
Windows/Shell/API still be visible. It always supports bookmarks and therefore
allows all types of movement through the Recordset.
Kylix (D on Linux)
ctStatic
Coding standards Provides a static copy of a set of records for you to use to find
data or generate reports. Always allows bookmarks and
Books/Publications therefore allows all types of movement through the Recordset.
Dev. Utilities Additions, changes, or deletions by other users will not be
visible. A static cursor behaves like the result set from a BDE
FAQs/Tips/Tricks Query component with its RequestLive property set to False.
Free Code Projects
ctForward-only
Humor and Fun
Behaves identically to a dynamic cursor except that it allows you
Icons and Glyphs to scroll only forward through records. This improves
performance in situations where you need to make only a single
Jobs and Offers pass through a Recordset.
Training/CD/Video
Note: only ctStatic is supported if the CursorLocation property of
VCL & Tools
the ADO dataset component is set to clUseClient.
Subject Library Note: if the requested cursor type is not supported by the
provider, the provider may return another cursor type. That is, if
you try to set CursorLocation to clUseServer and CursorType to
All articles on this ctDynamic, on an Access database, Delphi will change the
topic CursorType to ctKeyset.
CursorLocation
The CursorLocation property defines where the recordset is
created when it's opened — on the client or the server.
Stay up-to-date! it (into the ADO cursor). After you make changes to your
Subscribe to our Recordset, the ADO translates those changes into an action
newsletter. query and submits that query to your database through the OLE
Enter Email Go! DB provider. The client-side cursor behaves like a local cache.
In most cases, a client-side cursor is preferred, because scrolling
and updates are faster and more efficient, although returning
Advertising data to the client increases network traffic.
> Free Credit Report
> Free Psychics
Using the server-side cursor means retrieving only the required
records, requesting more from the server as the user browses
the data. Server-side cursors are useful when inserting,
updating, or deleting records. This type of cursor can sometimes
provide better performance than the client-side cursor,
especially in situations where excessive network traffic is a
problem.
LockType
The LockType property tells the provider what type of locks
should be placed on records during editing. Locking can prevent
one user from reading data that is being changed by another
user, and it can prevent a user from changing data that is about
to be changed by another user.
ltOptimistic
Optimistic locking locks the record only when it's physically
ltPessimistic
Pessimistic locking locks each record while it's being edited. This
option tells ADO to get an exclusive lock on the row when the
user makes any change to any column in the record. The
ADOExpress components don't directly support pessimistic
record locking because ADO itself does not have any way to
arbitrarily lock a given record and still support navigating to
other records.
ltReadOnly
Read only locking simply does not allow data editing. This lock is
useful in conditions where your application must temporarily
prevent data changes, but still can allow unrestricted reading.
Read only locking with CursorType set to ctForwardOnly is ideal
for reporting purposes.
ltBatchOptimistic
BatchOptimistic locking is used with disconnected recordsets.
These recordsets are updated locally and all modifications are
sent back to the database in a batch.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
From Paradox to Access with ADO
Page 1: Focusing on the TADOCommand components and using
· A Beginner’s Guide to the SQL DDL language.
Delphi Programming
More of this Feature
· Free course: Delphi
Chapter 5 of this course (Free Delphi • Page 2: Porting a table
ADO DB programming Database Course for Beginners - focus on
Join the Discussion
· Delphi for .NET ADO techniques) featured the ADOQuery
"Post your views and comments
component designed to enable Delphi
to this chapter of the free Delphi
· Free code APPs & developers to use the SQL language with database Programming Course"
ADO. The SQL statements can either be Discuss!
VCL
DDL (Data Definition Language) statements
· A-Z Site Index such as CREATE TABLE, ALTER INDEX, and Related Resources
so forth, or they can be DML (Data • free DB Course.TOC
BUYER'S GUIDE Manipulation Language) statements, such • Queries with ADO
as SELECT, UPDATE, and DELETE. • SQL with Delphi
• more Database articles
What's New and Hot
In this chapter, I'll focus on the
Top Picks-Tool/VCL TADOCommand components and using the SQL DDL language to help
port your BDE/Paradox data to ADO/Access.
Beginners Here
Data definition language
COM/OLE/ActiveX
Creating a database programmatically isn't something most developers
Database do every day - we all use some kind of visual tool, like MS Access for
maintaining a MDB file. Unfortunately, sometimes you'll need to create
Distrubuted comp. and destroy databases and database objects from code. The most basic
Game Programming technique in use today is the Structured Query Language Data
Definition Language (SQL DDL). Data definition language (DDL)
Graphics statements are SQL statements that support the definition or
Internet/Intranet declaration of database objects (for example, CREATE TABLE, DROP
VCL Write/Enhance
CREATE TABLE PhoneBook(
Web Services Name TEXT(50)
Tel TEXT(50)
Windows/Shell/API
);
Kylix (D on Linux)
This DDL statemnt (for MS Access), when executed, will create a new
Coding standards table named PhoneBook. The PhoneBook table will have two fields,
Name and Tel. Both fields are of the string (TEXT) type and the size of
Books/Publications the fields is 50 characters.
Dev. Utilities
TFieldDef.DataType
FAQs/Tips/Tricks
Obviously, the data type that represents a string in Access is TEXT. In
Free Code Projects Paradox it's STRING. In order to port Paradox tables to Access we'll
have to know what data types are available and what are their names.
Humor and Fun When working with the BDE and Paradox tables, the
Icons and Glyphs TFieldDef.DataType determines the type of a physical field in a
(dataset) table. To successfully migrate Paradox tables to Access you
Jobs and Offers need to have a function that "transforms" a Paradox field type to an
Training/CD/Video Access type.
The next function checks the type of the field (fd) and returns the
VCL & Tools corresponding Access type along with a field size when needed for a
CREATE TABLE DDL statement.
Subject Library
function AccessType(fd:TFieldDef):string;
begin
All articles on this case fd.DataType of
topic ftString: Result:='TEXT('+IntToStr(fd.Size)+')';
ftSmallint: Result:='SMALLINT';
Stay up-to-date!
ftInteger: Result:='INTEGER';
Subscribe to our ftWord: Result:='WORD';
newsletter. ftBoolean: Result:='YESNO';
Enter Email Go! ftFloat : Result:='FLOAT';
ftCurrency: Result := 'CURRENCY';
Advertising ftDate, ftTime, ftDateTime: Result := 'DATETIME';
> Free Credit Report ftAutoInc: Result := 'COUNTER';
> Free Psychics ftBlob, ftGraphic: Result := 'LONGBINARY';
ftMemo, ftFmtMemo: Result := 'MEMO';
else
Result:='MEMO';
end;
end;
ADOX
ADO Extensions for Data Definition Language and Security (ADOX) is an
extension to the ADO objects and programming model. ADOX gives
developers a rich set of tools for gaining access to the structure,
security model, and procedures stored in a database.
The top-level object in the ADOX object model is the Catalog object. It
provides access to the Tables, Views, and Procedures collections, which
are used to work with the structure of the database, and also provides
the Users and Groups collections, which are used to work with security.
Each Catalog object is associated with only one Connection to an
underlying data source.
We'll leave ADOX (at least for now) and stick to ADOExpress.
TADOCommand
In ADOExpress, the TADOCommand component is the VCL
representation of the ADO Command object. The Command object
represents a command (a query or statement) that can be processed by
the data source. Commands can then be executed using the
ADOCommand's Execute method. TADOCommand is most often used
for executing data definition language (DDL) SQL commands. The
CommandText property specifies the command to execute. The
CommandType property determines how the CommandText property is
interpreted. The cmdText type is used to specify the DDL statement.
Although it makes no sense to use the ADOCommand component to
retrieve a dataset from a table, query, or stored procedure, you can do
so.
Next page > Project to port your BDE/Paradox data to ADO/Access. >
Page 1, 2
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: An introduction to hook procedures.
This document describes what Windows hooks are and how to use them within a
Delphi application. Sample project, to trap keystrokes, included.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
From Paradox to Access with ADO
Page 2: Project to port your BDE/Paradox data to ADO/Access.
· A Beginner’s Guide to
Delphi Programming
More of this Feature
· Free course: Delphi • Page 1: DDL ADOCommand
The following project will demonstrate how
ADO DB programming to: • Download Code
as they are - for example the Memo should have the default name:
Mathematics
Memo1):
Multimedia
Button1.Caption = 'Construct Create command'
Delphi Pascal/IDE
Button2.Caption = 'Create Table and copy data'
Screen saver dev. ComboBox.Name = cboBDETblNames;
Code
Coding standards
To retrieve a list of the tables associated with a given database
Books/Publications (DBDEMOS) we use the next code (OnCreate for the form):
Dev. Utilities
procedure TForm1.FormCreate(Sender: TObject);
FAQs/Tips/Tricks
begin
Free Code Projects Session.GetTableNames('DBDEMOS',
Humor and Fun '*.db',False, False,
cboBDETblNames.Items);
Icons and Glyphs
end;
Jobs and Offers
Training/CD/Video
VCL & Tools When you start the project the ComboBox has all the (Paradox) table
names in the DBDEMOS alias directory. In the code that follows, we'll
pick the Country table.
Subject Library
The next task is to create a CREATE TABLE DDL statement. This gets
All articles on this done in the 'Construct Create command' button's OnClick procedure:
topic
procedure TForm1.Button1Click(Sender: TObject);
//'Construct Create command' button
Stay up-to-date! var i:integer;
Subscribe to our
s:string;
newsletter.
begin
Enter Email Go!
BDETable.TableName:=cboBDETblNames.Text;
BDETable.FieldDefs.Update;
Advertising
> Free Credit Report
s:='CREATE TABLE ' + BDETable.TableName + ' (';
> Free Psychics
with BDETable.FieldDefs do begin
for i:=0 to Count-1 do begin
s:=s + ' ' + Items[i].Name;
s:=s + ' ' + AccessType(Items[i]);
s:=s + ',';
end; //for
s[Length(s)]:=')';
end;//with
Memo1.Clear;
Memo1.lines.Add (s);
end;
The above code simply parses the field definitions for the selected table
(cboBDETblNames) and generates a string that will be used by the
CommandText property of the TADOCommand component.
For example, when you select the Country table the Memo gets filled
with the next string:
And finally, the code for the 'Create Table and copy data' button drops
a table (DROP..EXECUTE), creates a table (CREATE..EXECUTE), and then
copies data into the new table (INSERT...POST). Some error handling
code is provided, but the code will fail if, for example, the (new) table
does not already exist (since it first gets dropped).
//refresh
Button1Click(Sender);
ADOCommand.CommandText:=Memo1.Text;
ADOCommand.Execute;
ADOTable.TableName:=tblName;
//copy data
BDETable.Open;
ADOTable.Open;
try
while not BDETable.Eof do begin
ADOTable.Insert;
for i:=0 to BDETable.Fields.Count-1 do begin
ADOTable.FieldByName
(BDETable.FieldDefs[i].Name).Value :=
BDETable.Fields[i].Value;
end;//for
ADOTable.Post;
BDETable.Next
end;//while
finally
BDETable.Close;
ADOTable.Close;
end;//try
end;
That's it. Check out your Access database now...voila there is a Country
table with all the data from DBDEMOS.
Now you can port all your Paradox tables to Access (download code).
Few questions, however, stay unanswered. The first one is: how to add
index definitions (CREATE INDEX ON ...) to tables. The second one is: how
to create an empty Access database. I'll leave those (and others you
can think of) for the Forum or for some future article - Chapter 13
precisely.
More Delphi
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Master-detail relationships ADO and
· A Beginner’s Guide to Delphi
Page 1: One-to-Many relationships - why and when?
Delphi Programming
· Free course: Delphi More of this Feature
Master-detail data relationships are • Page 2: Realtions in Access
ADO DB programming
a fact of life for every Delphi • Page 3: ADO master-detail
· Delphi for .NET database developer; just as data
Join the Discussion
relationships are a fundamental
· Free code APPs & "Post your views and comments
feature of relational databases.
to this chapter of the free Delphi
VCL database Programming Course"
In the previous chapters of this Discuss!
· A-Z Site Index
course, we've invariably used only Related Resources
BUYER'S GUIDE one table from our "demo"
• free DB Course.TOC
aboutdelphi.mdb MS Access
• more Database articles
database. In real time database
What's New and Hot
programming, the data in one table
Top Picks-Tool/VCL is related to the data in other tables. In general, tables can be
related in one of three different ways: one-to-one, one-to-many
or many-to-many. This chapter will show you how to use one-to-
Beginners Here
many database relationships to deal effectively with the problem
COM/OLE/ActiveX of joining two database tables to present information.
Database
A one-to-many relationship, often referred to as a "master-
Distrubuted comp. detail" or "parent-child" relationship, is the most usual
relationship between two tables in a database.
Game Programming
Common scenarios include customer/purchase data,
Graphics patient/medical-record data, and student/course-result data. For
Internet/Intranet example, each customer is associated with at least one order
record. Valued customers have many order records involving
Mathematics significant sums and often a user needs to view one in
Multimedia connection with the other. In a one-to-many relationship, a
record in Table A can have (none or one or) more than one
Delphi Pascal/IDE matching record in Table B, but for every record in Table B there
is exactly one record in Table A.
Screen saver dev.
VCL Using A typical master-detail data browsing form displays the results of
VCL Write/Enhance a one-to-many relationship, where one DBGrid displays (or set of
data enabled controls) the results of the first or master table. It
Web Services then tracks a selection in the first DBGrid to filter the results of a
Windows/Shell/API second table used to display the details of the selection in the
second DBGrid.
Kylix (D on Linux)
When working with the BDE and Delphi, the simplest way to
Coding standards assemble a master-detail form is to use the Database Form
Wizard. Wizard simplifies the steps needed to create a tabular or
Books/Publications
data-entry form by use of an existing database, unfortunately it
Dev. Utilities is designed to use the BDE versions of TTable and TQuery
FAQs/Tips/Tricks components. Everything the wizard does, we can do by hand.
Free Code Projects Since, through this course, we are working with the ADOExpress
Humor and Fun set of Delphi components, we'll need to set all the components
step by step. Firstly we have to make sure that we have two
Icons and Glyphs tables in a master-detail relationship.
Jobs and Offers
Next page > One-to-many in MS Access > Page 1, 2, 3
Training/CD/Video
VCL & Tools DB Course Next Chapter >>
>> New...Access Database from Delphi
Subject Library
All graphics (if any) in this feature created by Zarko Gajic.
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Master-detail relationships ADO and
· A Beginner’s Guide to Delphi
Page 2: MS Access relationships and referential integrity
Delphi Programming
· Free course: Delphi
More of this Feature
ADO DB programming
MS Access relationships • Page 1: Data relationships
· Delphi for .NET Our focus will be on the following two • Page 3: ADO master-detail
tables: Customers and Orders. Both
· Free code APPs & tables are a part of the DBDEMOS
Join the Discussion
"Post your views and comments
VCL database that comes with Delphi.
to this chapter of the free Delphi
Since both tables are Paradox tables, database Programming Course"
· A-Z Site Index we'll use the code from the previous Discuss!
Graphics any kind) we should set that relation with the MS Access.
Internet/Intranet
Customers-Orders relation
Mathematics To set up the relationship, you add the field or fields that make up
the primary key on the "one" side of the relationship to the table
Multimedia
on the "many" side of the relationship. In our case, you would add
Delphi Pascal/IDE the CustNo field from the Customers table to the Orders table,
because one customer has many orders. Note that you have to
Screen saver dev.
set the CustNo in Customers to be the primary key for the table.
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
When creating a relation between two tables MS Access provides
FAQs/Tips/Tricks us with the Referential Integrity feature. This feature prevents
adding records to a detail table for which there is no matching
Free Code Projects
record in the master table. It will also cause the key fields in the
Humor and Fun detail table to be changed when the corresponding key fields in
the master are changed - this is commonly referred to as a
Icons and Glyphs cascading update. The second options is to enable cascading
Jobs and Offers deletes. This causes the deletion of all the related records in a
detail table when the corresponding record in the master table
Training/CD/Video gets deleted. These events occur automatically, requiring no
VCL & Tools intervention by a Delphi application using these tables.
Now, when we have all the relations set up, we simply link few
Subject Library data components to create a master-detail data browsing Delphi
form.
More Delphi
Stay up-to-date! · Learn another routine every day - RTL Quick Reference.
Subscribe to our · Download free source code applications and components.
newsletter. · Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
Enter Email Go!
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Real-time 2D particle systems (with gravitation!).
Advertising
This tutorial is going to discuss a library of Delphi routines that will help you
> Free Credit Report create your own particle systems. The term system is defined to mean, 'A
> Free Psychics group of interacting, interrelated, or interdependent elements forming a
complex whole'. You can use the particle to represent a cannonball being shot
out of a cannon - in trajectory games.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo
is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Master-detail relationships ADO and
· A Beginner’s Guide to Delphi
Page 3: Master-detail with AdoExpress components and
Delphi Programming
Delphi
· Free course: Delphi
More of this Feature
ADO DB programming
Setting up Master/Detail with • Page 1: Data relationships
· Delphi for .NET ADOExpress • Page 2: Realtions in Access
Creating a master-detail data form
· Free code APPs & Printer friendly version
is not to much complicated. Have an
VCL empty Delphi form, and just follow Join the Discussion
the steps:
· A-Z Site Index "Post your views and comments
to this chapter of the free Delphi
1. Select the ADO page on the database Programming Course"
BUYER'S GUIDE
Discuss!
Component palette. Add two
TADOTable components and one Related Resources
What's New and Hot TADOConnection to a form.
• free DB Course.TOC
2. Select the Data Access page on
Top Picks-Tool/VCL • more Database articles
the Component palette. Add two
TDataSource components to a form.
Beginners Here 3. Select Data Controls page on the
COM/OLE/ActiveX Component palette. Place two TDbGrid components on a form.
Add two DBNavigator components, too.
Database 4. Use the ADOConnection, the ConnectionString property, to
link to the aboutdelphi.bdb MS Access database, as explained in
Distrubuted comp.
the first chapter of this course.
5. Connect DBGrid1 with DataSource1, and DataSource1 with
Game Programming ADOTable1. This will be the master table. Connect DBNavigator1
with DataSource1.
Graphics
6. Connect DBGrid2 with DataSource2, and DataSource2 with
Internet/Intranet ADOTable2. This will be the detail table. Connect DBNavigator2
with DataSource2.
Mathematics 7. Set ADOTable1.TableName to point to the Customers table
Multimedia (master).
8. Set ADOTable2.TableName to point to the Orders table
Delphi Pascal/IDE (detail).
Screen saver dev.
If you, at this moment, set the Active property of both ADOTable
VCL Using components to true, you'll notice that the entire Orders table is
VCL Write/Enhance displayed - this is because we haven't set up the master-detail
relationship yet.
Web Services
Windows/Shell/API Your form should look something like:
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Free Code Projects
Humor and Fun
Icons and Glyphs
Jobs and Offers
Training/CD/Video
VCL & Tools
Subject Library
Each time you highlight a row and select a new customer, the
second grid displays only the orders pertaining to that customer.
Simple as that!
ADO Shaping
Shaped recordsets are an alternative to master-detail
relationships. Beginning with ADO 2.0, this method is available.
Shaped recordsets allow the developer to retrieve data in a
hierarchical fashion. The shaped recordset adds a special "field"
that is actually a recordset unto itself. Essentially, data shaping
gives you the ability to build hierarchical recordsets. For
instance, a typical hierarchical recordset might consist of a
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: Real-time 2D particle systems (with gravitation!).
This tutorial is going to discuss a library of Delphi routines that will help you
create your own particle systems. The term system is defined to mean, 'A
group of interacting, interrelated, or interdependent elements forming a
complex whole'. You can use the particle to represent a cannonball being
shot out of a cannon - in trajectory games.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Delphi Database Programming Course
Free online database programming course for beginner Delphi
· A Beginner’s Guide to developers. Focus on ADO techniques.
Delphi Programming
· Free course: Delphi About the Course: Related Resources
• A Beginners Guide To
ADO DB programming Delphi Programming
This free online course is perfect for Delphi
· Delphi for .NET database beginners as well as for those who want
• BOOK: Advanced Delphi
a broad overview of the art of database
· Free code APPs & Developer's Guide to ADO
programming with Delphi. Developers will learn
• Before you buy ADO VCL
VCL how to design, develop and test a database
• More ADO articles
application using ADO with Delphi. This course • Full (free) code apps and
· A-Z Site Index focuses on the most common uses of ADO in a components
Delphi application: Connecting to a database using • More tutorials and articles
BUYER'S GUIDE TADOConnection, work with Tables and Queries,
handle database exception, create reports, etc. From Other Guides
What's New and Hot • About Databases
Prerequisites:
Top Picks-Tool/VCL Elsewhere on the Web
Readers should have at a working knowledge of
the Windows operating system, as well as some • AdoAnywhere
Beginners Here decent level of Delphi Programming knowledge
base. New developers should first explore A
COM/OLE/ActiveX
Beginner's Guide to Delphi Programming
Database
Distrubuted comp. Chapters:
The chapters of this course are being created and updated dynamically on
Game Programming this site. Chapters (for now) include:
Graphics
CHAPTER 1:
Internet/Intranet Fundamentals of Database Development (with Delphi)
Mathematics Delphi as the database programming tool, Data Access with Delphi...just a few
words, Building a new MS Access database.
Multimedia Discuss about questions, comments, problems and solutions related to this chapter!
Delphi Pascal/IDE
CHAPTER 2:
Screen saver dev. Connecting to a database. BDE? ADO?
Connecting to a database. What is the BDE? What is ADO? How to connect to an
VCL Using
Access database - the UDL file? Looking forward: the smallest ADO example.
VCL Write/Enhance Discuss about questions, comments, problems and solutions related to this chapter!
Web Services
CHAPTER 3:
Windows/Shell/API Pictures inside a database
Kylix (D on Linux) Displaying images (BMP, JPEG, ...) inside an Access database with ADO and Delphi.
Discuss about questions, comments, problems and solutions related to this chapter!
Coding standards
CHAPTER 4:
Books/Publications Data browsing and navigation
Building a data browsing form - linking data components. Navigating through a
Dev. Utilities recordset with a DBNavigator.
Discuss about questions, comments, problems and solutions related to this chapter!
FAQs/Tips/Tricks
Free Code Projects
CHAPTER 5:
Humor and Fun Behind data in datasets
What is the state of data? Iterating through a recordset, bookmarking and reading
Icons and Glyphs the data from a database table.
Discuss about questions, comments, problems and solutions related to this chapter!
Jobs and Offers
Training/CD/Video
CHAPTER 6:
VCL & Tools Data modifications
Learn how to add, insert and delete records from a database table.
Discuss about questions, comments, problems and solutions related to this chapter!
Subject Library
CHAPTER 7:
Queries with ADO
All articles on this Take a look at how you can take advantage of the TADOQuery component to boost
topic your ADO-Delphi productivity.
Discuss about questions, comments, problems and solutions related to this chapter!
Advertising CHAPTER 9:
> Free Credit Report Searching for data
> Free Psychics Walking through various methods of data seeking and locating while developing
ADO based Delphi database applications.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 10:
ADO Cursors
How ADO uses cursors as a storage and access mechanism, and what you should
do to choose the best cursor for your Delphi ADO application.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 11:
From Paradox to Access with ADO and Delphi
Focusing on the TADOCommand components and using the SQL DDL language to
help porting your BDE/Paradox data to ADO/Access.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 12:
Master detail relationships
How to use master-detail database relationships, with ADO and Delphi, to deal
effectively with the problem of joining two database tables to present information.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 13:
New...Access Database from Delphi
How to create an MS Access database without the MS Access. How to create a
table, add an index to an existing table, how to join two tables and set up
referential integrity. No MS Access, only Pure Delphi code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 14:
Charting with Databases
Introducing the TDBChart component by integrating some basic charts into a
Delphi ADO based application to quickly make graphs directly for the data in
recordsets without requiring any code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 15:
Lookup!
See how to use lookup fields in Delphi to achieve faster, better and safer data
editing. Also, find how to create a new field for a dataset and discuss some of the
key lookup properties. Plus, take a look at how to place a combo box inside a
DBGrid.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 16:
Compacting an Access database with ADO and Delphi
While working in a database application you change data in a database, the
database becomes fragmented and uses more disk space than is necessary.
Periodically, you can compact your database to defragment the database file. This
article shows how to use JRO from Delphi in order to compact an Access database
from code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 17:
Database reports with Delphi and ADO
How to use QuickReport set of components to create database reports with Delphi.
See how to produce database output with text, images, charts and memos - quickly
and easily.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 18:
Data Modules
How to use the TDataModule class - central location for collecting and
encapsulating DataSet and DataSource objects, their properties, events and code.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 19:
Handling database errors
Introducing error handling techniques in Delphi ADO database application
development. Find out about global exception handling and dataset specific error
events. See how to write an error logging procedure.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 20:
From ADO Query to HTML
How to export your data to HTML using Delphi and ADO. This is the first step in
publishing your database on the Internet - see how to create a static HTML page
from an ADO query.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 21:
Using ADO in Delphi 3 and 4 (before AdoExpress)
How to import Active Data Objects (ADO) type-libraries in Delphi 3 and 4 to create
a wrapper around components that encapsulate the functionality of ADO objects,
properties and methods.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 22:
Transactions in Delphi ADO database development
How many times have you wanted to insert, delete or update a lot of records
collectively wanting that either all of them get executed or if there is an error then
none is executed at all? This article will show you how to post or undo a series of
changes made to the source data in a single call.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 23:
Deploying Delphi ADO database applications
It is time to make your Delphi ADO database application available for others to run.
Once you have created a Delphi ADO based solution, the final step is to successfully
deploy it to the user's computer.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 24:
Delphi ADO/DB programming: Real Problems - Real Solutions
In real world situations, really doing database programming is much more complex
than writing about. This chapter points to some great Delphi Programming Forum
threads initiated by this Course - discussions that solve problems on the field.
CHAPTER 25:
TOP ADO programming TIPS - DB/25
Collection of frequently asked questions, answers, tips and tricks about ADO
programming.
Discuss about questions, comments, problems and solutions related to this chapter!
CHAPTER 26:
Quiz: Delphi ADO Programming - DB/26
What would it look like: Who Wants to be a Delphi ADO Database Programming
Guru - the trivia game.
Discuss about questions, comments, problems and solutions related to this chapter!
Before this course started, there was an online poll asking for you to decide: what type of
data access mechanism are you most interested in. After more than 9000 votes it seems
that most of you are primarily interested in ADO/MS Access approach. From the fifth version
Delphi supports ADO with ADOExpress. AdoExpress components are available with the
Enterprise version of Delphi 5 and can be bought by the owners oh the Professional version.
Prior to version 5 Delphi does not support ADO. In order to participate in this course you'll
have to get your hands on AdoExpress or some other ADO enabled component set. Some of
the third-party ADO data-components can be found here: ADO Delphi VCL components. Most
of the techniques that are to be addressed in the following chapters to this course should be
easily translated and used with Paradox/dBase or Interbase users.
Those are the poll results ("What approach would you like to learn?"):
. ADO/MSAccess 4625 votes (51%)
. Paradox - BDE 167 votes (2%)
. dBase - BDE 66 votes (1%)
. Interbase 4227 votes (47%)
Get informed when the next chapter of this course becomes available online:
Name Email
subscribe
Of course, don't forget to join the Forum where all the questions are
answered and beginners are treated as experts:
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
New...Access Database from Delphi
Page 1: Delphi, ADOX and ADOExpress against MS Access.
· A Beginner’s Guide to
Delphi Programming More of this Feature
Chapter 11 of this course (Free • Page 2: Create.Database
· Free course: Delphi
Delphi Database Course for Join the Discussion
ADO DB programming Beginners - focus on ADO
"Post your views and comments
· Delphi for .NET techniques) featured the to this chapter of the free Delphi
ADOCommand component which is database Programming Course"
· Free code APPs & most often used for executing data Discuss!
VCL definition language (DDL) SQL
commands. We've presented a way Related Resources
· A-Z Site Index of porting your existing • free DB Course.TOC
Paradox/BDE tables to MS Access. • Queries with ADO
BUYER'S GUIDE However few questions have stayed • SQL with Delphi
unanswered: how to create an • more Database articles
empty Access database, how to add
What's New and Hot
an index to an existing table, how to join two tables with
Top Picks-Tool/VCL referential integrity, ....
Beginners Here Many of the attendees of this course have complained that they
do not have MS Access installed on their computer - and are
COM/OLE/ActiveX unable to create a sample database (aboutdelphi.mdb) that is
Database presented in the first chapter and used through this course.
Distrubuted comp.
In this chapter, we'll again focus on the TADOCommand and the
Game Programming ADOX to see how set up an empty MS Access database from
"nothing".
Graphics
Internet/Intranet ADOX
As stated in the mentioned chapter, ADO Extensions for Data
Mathematics
Definition Language and Security is an extension to the ADO
Multimedia objects and programming model. ADOX gives developers a rich
set of tools for gaining access to the structure, security model,
Delphi Pascal/IDE
and procedures stored in a database.
Screen saver dev.
VCL Using Even though ADOX is part of ADO, Delphi does not wrap it inside
ADOExpress. To use ADOX with Delphi, you should establish a
VCL Write/Enhance reference to the ADOX type library. The description of the ADOX
library is "Microsoft ADO Ext. for DDL and Security." The ADOX
Web Services
library file name is Msadox.dll. You'll have to import the ADOX
Windows/Shell/API library into the IDE.
Kylix (D on Linux)
To use ADOX in Delphi, you should establish a reference to the
ADOX type library.
Coding standards 1. Select Project | Import Type Library
Books/Publications 2. Choose "Microsoft ADO Ext 2.x for DDL and Security (Version
2.x)"
Dev. Utilities 3a. Change "TTable" to "TADOXTable"
FAQs/Tips/Tricks 3b. Change "TColumn" to "TADOXColumn"
3c. Change "TIndex" to "TADOXIndex"
Free Code Projects 3d. Change "TKey" to "TADOXKey"
3e. Change "TGroup" to "TADOXGroup"
Humor and Fun
3f. Change "TUser" to "TADOXUser"
Icons and Glyphs 3g. Change "TCatalog" to "TADOXCatalog"
4. Press Install button (rebuilding packages)
Jobs and Offers 5. Press OK once and Yes twice
Training/CD/Video 6. File | Close All | Yes
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: A more powerful Delphi Form.
Messing with the creation process of a form object, or how to change the
default style of a window when it gets created to suit your particular needs.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
New...Access Database from Delphi
Page 2: The Delphi Project to create a new MS Access database, add
· A Beginner’s Guide to tables, create indexes, set referential integrity.
Delphi Programming
· Free course: Delphi More of this Feature
ADO DB programming The Delphi Project • Page 1: ADO + ADOX
Our task is to
· Delphi for .NET Printer friendly version
have Delphi
· Free code APPs & do all the Join the Discussion
work. We
VCL "Post your views and comments
want to to this chapter of the free Delphi
· A-Z Site Index create a new database Programming Course"
database Discuss!
BUYER'S GUIDE from code,
add all three Related Resources
tables from • free DB Course.TOC
What's New and Hot code, add indexes from code and even set up a • Queries with ADO
referential integrity between those tables - • SQL with Delphi
Top Picks-Tool/VCL
again from code. • more Database articles
Beginners Here
As usual, have an empty Delphi form. Add two
COM/OLE/ActiveX button component. Add a TADOConnection, TADOCommand. We'll use
TADOCommand with a DDL language to create and link tables. Add a
Database
TADOXCatalog component (ActiveX page). The TADOXCatalog will do the
Distrubuted comp. trick of creating a new database. Let the name of the first button be
btnNewDatabase (caption: 'Create database'), the second one should be
Game Programming called btnAddTables (caption: 'Create and link tables'). All the other
Graphics components should have the default name.
In this chapter we'll link those components from code. Therefore, you do
Internet/Intranet not need to set up a ConnectionString for the ADOConnection component
Mathematics and the Connection property for the ADOCOmmand component now.
Multimedia New...Database
Before we move on to creating tables and linking them we have to create a
Delphi Pascal/IDE
new (empty) database. This is the code:
Screen saver dev.
VCL Using procedure TForm1.btnNewDatabaseClick(Sender: TObject);
VCL Write/Enhance var
DataSource : string;
Web Services
dbName : string;
Windows/Shell/API begin
Kylix (D on Linux) dbName:='c:\aboutdelphi.mdb';
DataSource :=
Coding standards
'Provider=Microsoft.Jet.OLEDB.4.0' +
Books/Publications ';Data Source=' + dbName +
Dev. Utilities ';Jet OLEDB:Engine Type=4';
FAQs/Tips/Tricks ADOXCatalog1.Create1(DataSource);
Free Code Projects end;
Humor and Fun
Icons and Glyphs
Would you belive - simple as that. Obviously the ADOXCatalog has a
Jobs and Offers method called Create1 that creates a new database. Pretty unusual since
Training/CD/Video we've accustomed that Create methods are used to create an object from a
class. The ADOXCatalog really has a Create method which has nothing in
VCL & Tools common to Create1.
Subject Library The variable DataSource looks pretty much like a standard connection string
for the TADOConnection component. There is only one addition, the Jet
OLEDB:Engine Type=X part. Engine type 4 is used to create an MS Access
All articles on this 97 database, type 5 is for MS Access 2000.
topic
Note that the above code does not check for the existance of the
c:\aboutdelphi.mdb database. If you run this code twice it will complain that
Stay up-to-date! the databae already exists.
Subscribe to our
newsletter. Add table, create index, set referential integrity
Enter Email Go! The next step is to create all tables (three of them), add indexes, and
create referential integrity. Even though we could use ADOX, that is,
TADOXTable, TADOXKey, etc. I'm somehow more familiar with the
Advertising
(standard) DDL language and the TADOCommand component. Back in the
> Free Credit Report
chapter 11 of this course we discussed database tables porting issues. This
> Free Psychics time we'll create tables from nothing.
The following peaces of code are to be placed inside the button's
btnAddTables OnClick even handler, I'll slice the code and add some
explanations in between.
ADOConnection1.ConnectionString := DataSource;
ADOConnection1.LoginPrompt := False;
ADOCommand1.Connection := ADOConnection1;
...
Second, we create both Types and Authors tables, the structures are given
in the first chapter. To build a new table with DDL by using the Jet SQL, we
use the CREATE TABLE statement by providing it the name the table, name
the fields, and fiedl type definitions. Then, the Execute method of the
ADOCommand component is used.
...
cs:='CREATE TABLE Types (typename TEXT(50))';
ADOCommand1.CommandText := cs;
ADOCommand1.Execute;
Next, we add indexes to those two tables. When you apply an index to a
table, you are specifying a certain arrangement of the data so that it can be
accessed more quickly. To build an index on a table, you must name the
index, name the table to build the index on, name the field or fields within
the table to use, and name the options you want to use. You use the
CREATE INDEX statement to build the index. There are four main options
that you can use with an index: PRIMARY, DISALLOW NULL, IGNORE NULL,
and UNIQUE. The PRIMARY option designates the index as the primary key
for the table.
...
cs:='CREATE INDEX idxPrimary '+
'ON Types (typename) WITH PRIMARY';
ADOCommand1.CommandText := cs;
ADOCommand1.Execute;
Finally, we add the last table. Applications table is linked with both Types
and Authors in a master detail relationship. Back in the last chapter we
were discussing one-to-many relationships that define the following: for
every record in the master table, there are one or more related records in
the child table. In our case, one Author (Authors table) can post more
Applications; and the Application can be of some type.
When defining the relationships between tables, we use the CONSTRAINT
declarations at the field level. This means that the constraints are defined
within a CREATE TABLE statement.
...
cs:='CREATE TABLE Applications ('+
' Name TEXT(50),'+
' Description TEXT(50),'+
' Author TEXT(50) CONSTRAINT idxauthor '+
'REFERENCES Authors (authorname),'+
' Type TEXT(50) CONSTRAINT idxtype '+
'REFERENCES Types (typename),'+
' Size FLOAT,'+
' Cost CURRENCY,'+
' DateUpl DATETIME,'+
' Picture LONGBINARY)';
ADOCommand1.CommandText := cs;
ADOCommand1.Execute;
end;//btnAddTablesClick
That's it. Now run the project, click the btnNewDatabase button, click the
btnAddTables button and you have a new (empty) aboutdelphi.mdb
database in the root of the C disk. If you have MS Access installed on your
system you can open this database with it and check that all thje tables are
here and in the Relationships window all the tables are linked.
I've told you that we could use ADOX, that is, TADOXTable, TADOXKey, etc.
After a few days of convincing ADOX to understand what I want to do with
it, I've finally managed to get the code working. However, since you already
have the database created using DDL, and I'm not going to reinvent the
wheel here, here's the link to Delphi Pascal code that uses ADOX to create
an Access database (along with referential integrity, indexex, etc...) This
code demonstrates some of the ways ADOX can be used with Object Pascal,
as well as pointing out some traps and pitfalls.
Create an Access database with ADOX
First page > Delphi, ADO and ADOX against MS Access > Page 1, 2
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: A more powerful Delphi Form.
Messing with the creation process of a form object, or how to change the default style of a
window when it gets created to suit your particular needs.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Charting with Databases
Page 1: Introducing the TDBChart.
· A Beginner’s Guide to
Delphi Programming
More of this Feature
· Free course: Delphi • Page 2: Connect ... Graph
In most modern database
ADO DB programming applications some kind of graphical
Join the Discussion
data representation is preferable or
· Delphi for .NET even required. For such purposes "Post your views and comments
to this chapter of the free Delphi
· Free code APPs & Delphi includes several data aware database Programming Course"
components: DBImage, DBChart, Discuss!
VCL
DecisionChart, etc. The DBImage is
· A-Z Site Index an extension to an Image Related Resources
component that displays a picture • free DB Course.TOC
BUYER'S GUIDE inside a BLOB field. Chapter 3 of this • Coloring DBGrid
database course discussed • Using Data Controls
• more Database articles
displaying images (BMP, JPEG, etc.)
What's New and Hot
inside an Access database with ADO
Top Picks-Tool/VCL and Delphi. The DBChart is a data Elsewhere on the Web
aware graphic version of the TChart • Tee Chart
component.
Beginners Here
COM/OLE/ActiveX Our goal in this chapter is to introduce the TDBChart by
Database showing you how to integrate some basic charts into your
Delphi ADO based application.
Distrubuted comp.
TeeChart
Game Programming The DBChart component is a powerful tool for creating database
charts and graphs. It is not only powerful, but also complex. We
Graphics
wont be exploring all of its properties and methods, so you'll
Internet/Intranet have to experiment with it to discover all that it is capable of and
how it can best suite your needs. By using the DBChart with the
Mathematics TeeChart charting engine you can quickly make graphs directly
Multimedia for the data in datasets without requiring any code. TDBChart
connects to any Delphi DataSource. ADO recordsets are natively
Delphi Pascal/IDE supported. No additional code is required - or just a little as
Screen saver dev. you'll see. The Chart editor will guide you through the steps to
connect to your data - you don't even need to go to the Object
VCL Using Inspector.
VCL Write/Enhance Runtime TeeChart libraries are included as part of Delphi
Professional and Enterprise versions. TChart is also integrated
Web Services with QuickReport with a custom TChart component on the
QuickReport palette. Delphi Enterprise includes a DecisionChart
Windows/Shell/API
control in the Decision Cube page of the Component palette.
Kylix (D on Linux)
Let's chart! - Prepare
Coding standards Our task will be to create a simple Delphi form with a chart filled
with values from a database query. To follow along, create a
Books/Publications Delphi form as follows:
Dev. Utilities
1. Start a a new Delphi Application - one blank form is created
FAQs/Tips/Tricks
by default.
Free Code Projects 2. Place the next set of components on the form:
ADOConnection, ADOQuery, DataSource, DBGrid and a DBChart.
Humor and Fun 3. Use the Object Inspector to connect ADOQuery with
Icons and Glyphs ADOConnection, DBGrid with DataSource with ADOQuery.
4. Set up a link with our demo database (aboutdelphi.mdb) by
Jobs and Offers using the ConnectionString of the ADOConnection component.
Training/CD/Video 5. Select the ADOQuery component and assign the next string to
the SQL property:
VCL & Tools
SELECT TOP 5 customer.Company,
SUM(orders.itemstotal) AS SumItems,
Subject Library COUNT(orders.orderno) AS NumOrders
FROM customer, orders
WHERE customer.custno = orders.custno
All articles on this GROUP BY customer.Company
topic ORDER BY SUM(orders.itemstotal) DESC
This query uses two tables: orders and customer. Both tables
were imported from the (BDE/Paradox) DBDemos database to
our demo (MS Access) database back in the chapter 11. This
query results in a recordset with only 5 records. The first field is
the Company name, the second (SumItems) is a sum of all the
orders made by the company and the third field (NumOrders)
represents the number of orders that were made by the
Stay up-to-date! company. Note that those two tables are linked in a master-
Subscribe to our detail relationship.
newsletter.
Enter Email Go! 6. Create a persistent list of database fields. (To invoke the
Fields Editor double click the ADOQuery component. By default,
the list of fields is empty. Click Add to open a dialog box listing
Advertising
the fields retrieved by the query (Company, NumOrders,
> Free Credit Report
SumItems). By default, all fields are selected. Select OK.) Even
> Free Psychics though you don't need a persistent set of fields to work with a
DBChart component - we'll create it now. The reasons will be
explained later.
7. Set ADOQuery.Active to True in the Object Inspector to see
the resulting set at design time.
Next page > Data Charts with no code - or just a little > Page
1, 2
More Delphi
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Charting with Databases
Page 2: Connect, Set, Code ... Graph
· A Beginner’s Guide to
Delphi Programming
More of this Feature
· Free course: Delphi • Page 1: Intro to TDBChart
Let's chart! - Connect
ADO DB programming In most cases, connecting a recordset with a
Printer friendly version
DBChart and setting various properties can be
· Delphi for .NET
done using the specific Chart editor. Join the Discussion
· Free code APPs & "Post your views and comments
VCL Using the fields of a recordset for the source, to this chapter of the free Delphi
the chart becomes a dynamic display that is database Programming Course"
· A-Z Site Index Discuss!
updated as the recordset if modified. You
have a wide variety of chart type options to Related Resources
BUYER'S GUIDE choose from and all of the parameters of the
• free DB Course.TOC
display can be controlled within an
• Coloring DBGrid
application.
What's New and Hot • Using Data Controls
• more Database articles
Top Picks-Tool/VCL In general, you fill a chart with data
designated in one or more series; each series Elsewhere on the Web
Beginners Here consists of categories and values. For • Tee Chart
example, to fill a chart with data about
COM/OLE/ActiveX customer orders, you could add a series that
Database charts customer names as the categories and order amounts as the
values.
Distrubuted comp.
Game Programming The Chart editor is a one stop shop for all Chart and Series specific
parameters. Once you have the DBChart component on a form, you should
Graphics
create one or more series. To accomplish this, open the Chart Component
Internet/Intranet Editor: select the component, right-click it, and choose the Edit Chart
menu item. Use the Chart tab to define all you general chart parameters.
Mathematics Select the Series tab and you may choose from your list of series to
Delphi Pascal/IDE
Screen saver dev.
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Free Code Projects
Humor and Fun
Icons and Glyphs We'll add two chart series. One that presents the sum of all the orders per
Jobs and Offers company and second that will plot the total number of orders.
Training/CD/Video
Chart tab
VCL & Tools To add a data series press the Add button in the Series
tab section of the Chart page. Now simply choose the
graph you want to add from Gallery - we'll use the
Subject Library Horizontal Bar. Once we've added the Series to the Chart
some random values are displayed, in the Chart at
design-time, to easily follow any changes you are
All articles on this making.
topic Note that a chart can have multiple series; if they are all of the same type
they will integrate better, as in the case of multiple bars.
Now add a second series - again use the Horizontal Bar.
Stay up-to-date!
Subscribe to our Series tab
newsletter. Selecting the Series tab (or double clicking the desired Series) allows you
Enter Email Go! to edit your Series. Select Series1. Select the DataSource tab. Select
"Dataset" from the drop down list. Select AdoQuery1 for the dataset. The
Advertising next set of choices determine the way how the data form the datasource
> Free Credit Report will appear on the graph (different kinds of charts have different properties
and methods). The exact contents of the page will change depending on
> Free Psychics
the Series type you have chosen. The Bar property determines what value
each bar is representing - pick SumItems from the list. The Labels
property is used to draw labels for each of the bars in the graph. Note that
Lables drop down does not list the Company field from the recordset!
BUG! When working with ADO recordset the Chart Editor does not list
fields of the WideString type (for the XLabels property). This bug is
present in TeeChart v4.xx STANDARD that ships with Delphi 5 and Delphi
6. This is what I got as a reply from the authors of the TeeChart:
"Well, all Delphi versions use the same TeeChart version (v4 STANDARD, I
think D4-D6 and CB4-CB5 use the same version). We discovered this bug
only when Delphi 5 was released. We fixed it, but not for TeeChart v4
STANDARD version (only for new v5 PRO version).
The good news is user can still connect ADOQuery to specific series at
runtime (via code):"
Series1.DataSource := ADOQuery1;
Series1.XLabelsSource := ADOQuery1WideStringField1.FieldName;
Series1.XValues.ValueSource := ADOQuery1FloatField1.FieldName;
Series1.YValues.ValueSource := ''; { no YValues }
Series1.CheckDataSource;
ADOQuery1.Close;
DBChart1.Legend.Visible:=False;
with DBChart1.SeriesList.Series[0] do begin
DataSource := ADOQuery1;
XLabelsSource := ADOQuery1Company.FieldName;
XValues.ValueSource := ADOQuery1SumItems.FieldName;
YValues.ValueSource := '';
Marks.Style := smsXValue;
CheckDataSource;
end; //with
with DBChart1.SeriesList.Series[1] do begin
DataSource := ADOQuery1;
XLabelsSource := '';
XValues.ValueSource := ADOQuery1NumOrders.FieldName;
YValues.ValueSource := '';
CheckDataSource;
end; //with
ADOQuery1.Open;
That's it. It's not to easy, it's not to hard. Explore the Project's Code to
find and learn more.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Screen Shuffling with Delphi.
Delphi code that divides the current desktop into blocks and then swaps the blocks. It
includes an option that lets you adjust the shuffling speed, and the size of the blocks.
Great intro to sliding puzzle game or to screen saver development.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Lookup!
Page 1: Why and when to use lookup fields; Creating a
· A Beginner’s Guide to data entry form
Delphi Programming
More of this Feature
· Free course: Delphi
Back in the master-detail • Page 2: New...lookup
ADO DB programming • Page 3: DBLookupCombo
relationships chapter of this course,
• Page 4: DBGrid.PickList
· Delphi for .NET we've seen that in most cases one
database table is related to the data Join the Discussion
· Free code APPs & in one or more other tables. "Post your views and comments
VCL to this chapter of the free Delphi
Consider the next example. In our database Programming Course"
· A-Z Site Index Discuss!
sample aboutdelphi.mdb database,
BUYER'S GUIDE Applications table lists Delphi Related Resources
applications uploaded by the visitors • free DB Course.TOC
to this site. Among other fields, the • Coloring the DBGrid
What's New and Hot Author and Type fields are linked • Using Data Controls
with the corresponding fields in the • more Database articles
Top Picks-Tool/VCL
Authors and Types tables. Only
values from the AuthorName field in
Beginners Here the Authors table can appear in the Author field of the
Applications table. The same rule is applied to the TypeName
COM/OLE/ActiveX
field (Types table) and the Type field (Applications table).
Database Another situation: consider an application data entry form whose
fields are connected to the Applications table. Let's say that this
Distrubuted comp.
table has only one information related to the author of the
application, an AuthorNo field corresponding to authors unique
Game Programming number. The Authors table, on the other hand, contains an
AuthorNo field corresponding to authors UN, and also contains
Graphics additional information, such as the authors name, email and a
Internet/Intranet web page. It would be convenient if the data entry form enabled
a user to select the author by its name (and email) instead by its
Mathematics UN.
Multimedia
Lookup!
Delphi Pascal/IDE
If you have a Delphi form with data controls designed to allow
Screen saver dev. editing the Applications table, you have to make sure that only
TypeName values from the Types table can be applied to the
VCL Using Types field of the Application table. You also have to make sure
VCL Write/Enhance that only AuthorName values from the Authors table can be
applied to the Author field of the Application table. The best way
Web Services to make this sure is to provide users with a string list to select
Windows/Shell/API the values from rather than having them enter values manually.
Stay up-to-date!
Creating a data entry form
Subscribe to our
Creating a data editing form by hand is not to much complicated,
newsletter.
as we already know. When developing database applications with
Enter Email Go! Delphi (and ADO), most of the work is done inside the IDE by
simply connecting various components together, thus having to
Advertising write no code. A typical data browsing/editing form presents a
> Free Credit Report database table inside a DBGrid. Another way is to add several
> Free Psychics data aware controls to a form and link them to the data source.
We'll place both a DBGrid and several data aware controls.
Have a new Delphi project with an empty form, then add the
next set of components: one ADOConnection, one DataSource
and two ADOTables.
Use the Object Inspector and connect all those components in
the following way:
First set the name of the ADOConnection component to be
ADOConnection. Use ConnectionString property to link to our
aboutdelphi.mdb database (LoginPrompt = False). Set
ADOTable1.Name = ApplicationTable, ADOTable2.Name =
AuthorsTable. Set DataSource1.Name = ApplicationsSource. Set
the Connection property of all ADOTable components to point to
ADOConnection component. Set ApplicationSource.DataSet =
ApplicationsTable. Finally, set ApplicationTable.Table =
Applications, AuthorsTable.Table = Authors. Finally, add a
DBGrid (DBGrid1) to a form and Connect it with
ApplicationsSource.
Here is a list of relevant values, as can be seen in the dfm file for
a form.
All set up (at least for now). It's time to see the first approach to
lookup fields.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: NO GUI Delphi applications.
Creating a console mode application with Delphi; a text-mode program that
runs without a graphical interface. Even more: see how to capture the output
of a console application in a GUI Delphi program.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Lookup!
Page 2: New...lookup field.
· A Beginner’s Guide to
Delphi Programming
More of this Feature
· Free course: Delphi • Page 1: On lookup fields
New ... lookup field
ADO DB programming To crete a new field object you have to • Page 3: DBLookupCombo
invoke the Fields editor for a dataset. • Page 4: DBGrid.PickList
· Delphi for .NET
Double click the ApplicationsTable and
Join the Discussion
· Free code APPs & right click it to have a pop up menu
"Post your views and comments
displayed. Pick "New field..."
VCL to this chapter of the free Delphi
database Programming Course"
· A-Z Site Index Discuss!
Beginners Here
COM/OLE/ActiveX
Database
Distrubuted comp.
Game Programming
Graphics
Internet/Intranet The idea is to set the value for the Author field by picking it's email. I
know this does not make much sense, but it will bring the lookup
Mathematics idea closer. In the New field form fill the boxes as on the picture
Multimedia below. We create a new AEmail field for the ApplicationTable dataset.
As you can see from the picture, there are few very important
Delphi Pascal/IDE properties you have to understand prior to working with lookup
Screen saver dev. fields.
VCL Using
.Field Name is the name of the lookup field. Set it to AEmail.
VCL Write/Enhance .Dataset identifies the dataset that contains lookup values (Authors).
.KeyFields is a field in the Applications dataset we are setting through
Web Services a lookup.
Windows/Shell/API .Lookup Keys is a field in the lookup dataset (Authors) to match
against the KeyFields.
Kylix (D on Linux) .ResultField is a field in the lookup dataset to return as the value of
the lookup field you are creating.
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Free Code Projects
Humor and Fun
Icons and Glyphs
Jobs and Offers
Training/CD/Video
VCL & Tools
Subject Library
Advertising
> Free Credit Report
> Free Psychics
Note: the combo box in the cell of a DBGrid has nothing with the
PickList property of Grid's column. This will be explained later in this
chapter.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: NO GUI Delphi applications.
Creating a console mode application with Delphi; a text-mode program that runs
without a graphical interface. Even more: see how to capture the output of a
console application in a GUI Delphi program.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy
| Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Lookup!
Page 3: The DBLookupComboBox and DBLookuplistBox
· A Beginner’s Guide to
Delphi Programming More of this Feature
Lookup with DBLookupComboBox • Page 1: On lookup fields
· Free course: Delphi
As stated above, when your data entry • Page 2: New...lookup
ADO DB programming form is made of more data controls • Page 4: DBGrid.PickList
Distrubuted comp.
Game Programming
Graphics
Internet/Intranet
topic
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics That's it. Again, no code required. When the user selects an item from
the combo box, an appropriate value of the KeyField field changes the
value of the DataField. At run time, the form looks like:
Note 2 : If you drag AEmail field from a Field Editor to a form, Delphi
will connect it with a DBLookupComboBox automatically. Of course, key
lookup properties will look different since we don't need another data
source for this link to work - lookup field is already defined "inside" the
ApplicationsTable/Source.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Lookup!
Page 4: DBGrid.Columns.PickList as a lookup list.
· A Beginner’s Guide to
Delphi Programming
More of this Feature
· Free course: Delphi • Page 1: On lookup fields
Lookup inside a PickList of a
ADO DB programming DBGrid Column • Page 2: New...lookup
The last approach to having a lookup • Page 3: DBLookupCombo
· Delphi for .NET
values displayed inside a DBGrid is to • Project's CODE
· Free code APPs & use the PickList property of a DBGrid
Column object. You'll usually add Printer friendly version
VCL
Columns to a DBGird when you want to
· A-Z Site Index define how a column appears and how Join the Discussion
the data in the column is displayed. A "Post your views and comments
BUYER'S GUIDE customized grid enables you to to this chapter of the free Delphi
database Programming Course"
configure multiple columns to present
Discuss!
different views of the same dataset
What's New and Hot
(different column orders, different field Related Resources
Top Picks-Tool/VCL choices, and different column colors and • free DB Course.TOC
fonts, for example). • Coloring the DBGrid
Beginners Here • Using Data Controls
I will not discuss this topic briefly here. • more Database articles
COM/OLE/ActiveX Let's just see what are the steps to add
Database columns to a DBGrid.
1. Right-click the DBGgrid component. This pops up the Columns
Distrubuted comp. Editor.
2. Right-click the Columns Editor to invoke the context menu and
Game Programming
choose Add All Fields. This creates one column for each field in a
Graphics dataset and connects them - the FieldName property determines the
Internet/Intranet connection.
Mathematics
While you have the Columns Editor displayed, see that each column
Multimedia has a PickList property. We'll use this String List to fill a list of lookup
values. Take a look at the AEMail column, its FieldName points to a
Delphi Pascal/IDE
lookup field - therefore displaying a combo box inside a DBGrid as
Screen saver dev. we saw at the beginning of this article. However its PickList is empty.
What I want to show you here is how to fill that String List with
VCL Using values from another dataset at run time - without creating a new
VCL Write/Enhance lookup field. In general, a pick list column looks and works like a
lookup list, except that the drop-down list is populated with the list
Web Services of values in the column's PickList property instead of from a lookup
Windows/Shell/API table. The reason to show how to use PickList to mimic the lookup
list is just to show that the same task can be done in several ways
Kylix (D on Linux) when you have a great toll like Delphi.
Coding standards What we want to do is to fill a PickList with the values from another
dataset at run time - this time using Pascal code. We'll use the
Books/Publications
Form's OnCreate event.
Dev. Utilities
FAQs/Tips/Tricks procedure TForm1.FormCreate(Sender: TObject);
Free Code Projects var AuthorsList:TStringList;
i:integer;
Humor and Fun
begin
Icons and Glyphs AuthorsList:=TStringList.Create;
Jobs and Offers try
AuthorsTable.First;
Training/CD/Video
AuthorsTable.DisableControls;
VCL & Tools while not AuthorsTable.EOF do begin
AuthorsList.Add(
AuthorsTable.FieldByName(
Subject Library
'authorname').AsString);
AuthorsTable.Next;
All articles on this end; //while
topic finally
//place the list it the correct column
for i:=0 to DBGrid1.Columns.Count-1 do begin
Stay up-to-date!
if DBGrid1.Columns[i].FieldName = 'Author'
Subscribe to our
newsletter. then begin
DBGrid1.Columns[i].PickList:=AuthorsList;
Enter Email Go!
Break;
Advertising
end;//if
> Free Credit Report end; //for
> Free Psychics AuthorsTable.EnableControls;
AuthorsList.Free;
end; //try
end;
The code simply fills the AuthorsList with the values of AuthorName,
by iterating through the Authors table. It then assigns the contents
of the AuthorsList to the PickList whose FiledName point to the
Author field. Since we can change the order of columns at design and
run time you have to make sure that the correct PickList get's the
values.
That's all for this chapter. Make sure you download code for this
project.
First page > Why and when to use lookup fields; Creating a data
entry form > Page 1, 2, 3, 4
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: NO GUI Delphi applications.
Creating a console mode application with Delphi; a text-mode program that runs
without a graphical interface. Even more: see how to capture the output of a
console application in a GUI Delphi program.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
with Zarko Gajic Your Guide to one of hundreds Search in this topic
of sites
Home · Articles · Forums · Chat · Classifieds · Newsletters · Help
Shop for Holiday Gifts from merchants like Old Navy, Eddie Bauer, Spiegel, and
more!
ESSENTIALS
Compacting an Access database with ADO and
· A Beginner’s Guide to Delphi
While working in a database application you change data in a database,
Delphi Programming
the database becomes fragmented and uses more disk space than is
· Free course: Delphi necessary. Periodically, you can compact your database to defragment
the database file. This article shows how to use JRO from Delphi in
ADO DB programming order to compact an Access database from code.
· Delphi for .NET
More of this Feature
· Free code APPs & Printer friendly version
Why compacting
VCL While you add and delete records from database
tables, your database becomes more and more Join the Discussion
· A-Z Site Index fragmented and uses disk space inefficiently. "Post your views and comments
to this chapter of the free Delphi
Compacting a database makes a copy of the
BUYER'S GUIDE database Programming Course"
database, rearranging how the database file is Discuss!
stored on disk. The compacted database is usually
What's New and Hot smaller and often runs faster. Related Resources
This chapter of the free database course for • free DB Course.TOC
Top Picks-Tool/VCL
Delphi beginners shows how to use JRO from • ADOX
Delphi in order to compact an Access database • DB Utilities
Beginners Here from code. • more Database articles
COM/OLE/ActiveX
JRO TLB Elsewhere on the Web
Database • JRO (Microsoft)
Distrubuted comp.
Game Programming
Graphics
Internet/Intranet
Mathematics
Multimedia
Delphi Pascal/IDE
Subject Library Note: Delphi 6 users will not succeed in importing JRO type library. If you have
Delphi 6, while trying to install the library in a package, an error will pop up
indicating that ActiveConnection in the JRO_TLB file doesn't exist (along with
All articles on this some other errors). The problem lies in Delphi 6 TLB importer. There are two
topic options to overcome the problem: 1. Use Delphi 5 to import JRO an then install
it in Delphi 6. 2. Manually declare the missing ActiveConnection property and
change property declarations to make them writeable.
Stay up-to-date!
Subscribe to our Compact Delphi Project
newsletter. It's time to see some code. Create a new Delphi application with one form. Add
Enter Email Go! two Edit controls and a Button. From the ActiveX component page pick
JetEngine. The first Edit should be renamed to edSource, the second one to
edDest. The button should be renamed to btnComapct. The JetEngine should be
Advertising renamed to JE. It should all look like:
> Free Credit Report
> Free Psychics
The TJetEngine class has a CompactDatabase method. The method takes two
parameters: the ADO connection string for the source as well for the destination
database. CompactDatabase method compacts a database and gives you the
option of changing its version, password, collating order and encryption.
Encrypting a database makes it indecipherable by a utility program or word
processor. Encrypted databases can still be opened by Access or through Delphi
code. The proper way to protect a database is to set a password for it. Collation
order is used for string comparison in the database. Changing a database
version gives you the way to "upgrade" it.
In our form, the edSource is used to specify the database we want to compact.
The edDest specifies the destination database. Within the connection strings,
you specify various connection properties to determine how the source database
is opened and how the destination database is compacted. At a minimum, you
must use the Data Source property in each connection string to specify the path
and name of the database.
When you use the CompactDatabase method, you can't save the compacted
database to the same name as the original database. CompactDatabase also
requires that the destination database does not exist.
if FileExists(edDest.Text) then
DeleteFile(edDest.Text);
JE.CompactDatabase(dbSrc,dbDest);
end;
Note that the above code presumes an Access 2000 database. Microsoft Jet
OLEDB 4.0 is the default data engine for Access 2000.
In many cases you'll want to have the same database name after the compact
operation. Since edSource and edDest can't be the same your code should
replace the original file with the compacted version. The next function takes
only one parameter - the name of the database you want to compact:
function DatabaseCompact
(const sdbName: WideString) : boolean;
var
JE : TJetEngine; //Jet Engine
sdbTemp : WideString; //TEMP database
sdbTempConn : WideString; //Connection string
const
SProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=';
begin
Result:=False;
sdbTemp := ExtractFileDir(sdbName) +
'TEMP' +
ExtractFileName(sdbName);
sdbTempConn := SProvider + sdbtemp;
if FileExists(sdbTemp) then
DeleteFile(sdbTemp);
JE:= TJetEngine.Create(Application);
try
try
JE.CompactDatabase(SProvider + sdbName, sdbTempConn);
DeleteFile(sdbName);
RenameFile(sdbTemp, sdbName);
except
on E:Exception do
ShowMessage(E.Message);
end;
finally
JE.FreeOnRelease;
Result:=True;
end;
end;
The DatabaseCompact receives a sdbName string parameter with the full name
of the database you want to compact. The function returns True if compact is
successful False otherwise. The sdbName is compacted in sdbTemp, the
sdbName is then deleted and sdbTemp renamed to sdbName. The
DatabaseCompact could be called as:
DatabaseCompact('C:\ADP\aboutdelphi.mdb');
The DatabaseCompact function is ideal to be called from within your Delphi ADO
application as an external application. It could also be written as a console
mode application that takes one command line parameter (or more) since it
requires no GUI.
If you need any kind of help so far, please post to the Delphi Programming
Forum where all the questions are answered and beginners are treated as
experts.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: A more powerful Delphi Form.
Messing with the creation process of a form object, or how to change the default style of a
window when it gets created to suit your particular needs.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark
of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Database reports with Delphi and ADO
How to use QuickReport set of components to create database
· A Beginner’s Guide to reports with Delphi. See how to produce database output with
Delphi Programming charts, images and memos - quickly and easily.
Subject Library
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report The simplest way to create a report is to use the QuickReport Wizard
> Free Psychics located on the Forms page (Delphi 5) of the New Items dialog. We'll pick
the QuickReport List - this creates a new form with the main reporting
component TQuickRep. This component acts as a container for several
TQrBand components containing TQrLabels. There is also a TTable
component on that form.
We are not going into details about QuickReport here, since there is a
comprehensive tutorial on using the QuickReport set of
components with Delphi available on this site.
We'll now create a simple list report containing data from the
Applications table. First make sure the newly created form is the default
for the project (Project | Options | Forms). Second add the TADOTable
component on a form, set it's Connection property to point to the
aboutdelphi.mdb database (this time were not going to use
ADOConnection) and set the Table property to Application. Third,
remove the TitleBand1 (TQrBand), PageFooterBand1 (TQrBand) and the
ColumnHeaderBand1 (TQrBand). Also, remove the QRLabel2 from the
DetailBand1. This leaves us with only ADOTable1, QuickRep1 and
DetailBand1. To link QuickReport1 with ADOTable1 set it's Dataset
property to point to ADOTable1.
DetailBand1, one for each field we want to print, and set their Dataset
property to ADOTable1. Add three QRDBText components, let them point
to Author, Type and Description fields of the Applications table.
To see the report at design time set ADOTable1.Active to True, right
click the QuickRep1 component and select Preview. This is something
similar to what you should see:
To show this preview window at run time, we need to call the Preview
method of the TQuickRep component.
Note that when previewing the report, Delphi (QuickReport) uses the
standard QuickReport preview form. If you want to change the
appearance or behaviour of this form you can create your own preview
form with the TQRPreview component.
inside Access you should consider the Pictures inside a database chapter.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: A first look at Delphi 6.
Read about exciting new features in the latest incarnation of today's best RAD
environment for writing cross platform applications - Delphi 6.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Data Modules
How to use the TDataModule class - central location for
· A Beginner’s Guide to collecting and encapsulating data access objects, their
Delphi Programming properties, events and code.
Game Programming modules can contain only nonvisual components and are
generally used in database and Web development. They provide
Graphics
Delphi developers a visual way to manipulate and code non-
Internet/Intranet visual components of an application.
Mathematics
Generally, a TDataModule class is used for some of the
Multimedia purposes:
Delphi Pascal/IDE
- Sharing data access components and code
Screen saver dev. Use a TDataModule to provide a location for centralized handling
VCL Using of nonvisual components. Typically these are data access
components (TADOConnection, TADOTable, TADOQuery,
VCL Write/Enhance TADOCommand, etc), but they can also be other nonvisual
components. This is convenient when an application has multiple
Web Services
forms that share the same data access provider - if your
Windows/Shell/API application operates on only one database file (one mdb) then
you'll need only one TADOConnection component for all the
Kylix (D on Linux)
dataset components.
Stay up-to-date! and OnDestroy. Use the Name property when referring to
Subscribe to our module's objects from other units.
newsletter.
Enter Email Go! DataModules are not limited to data access components, they
can also contain other nonvisual components, such as
Advertising TMainMenu, TTimer, TSaveDialog or TPopUpMenu).
> Free Credit Report
> Free Psychics
When you select the Data Diagram page (for the first time), you
are presented with an empty container, in which you can drag
any object from the Tree View and then link those objects.
Relationships include parent/child, datasource/dataset and
similar. For example, after moving a TADOTable and
TADOConnection to the Diagram view, you select the Property
connector icon, click the ADOTable and drag to the
ADOConnection. The connection will be made:
TADOTable.Connection property will point to ADOConnection
component - as can be seen in the Object Inspector.
More Delphi
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
with Zarko Gajic Your Guide to one of hundreds of sites Search in this topic
ESSENTIALS
Handling database errors
Introducing error handling techniques in Delphi ADO database application
· A Beginner’s Guide to development. Find out about global exception handling and dataset specific error
Delphi Programming events. See how to write an error logging procedure.
VCL Using a call to the Execute statement of the ADOQuery object is another way to trap a possible
exception.
VCL Write/Enhance
Web Services EDatabaseError, EADOError, OLE exceptions
When developing Delphi ADO based database solutions you should be aware of the several
Windows/Shell/API
try
Subject Library
ADOTable.Open;
except
All articles on this on E:Exception do
topic begin
MessageDlg('Error Opening Table ' + E.ClassName,
mtError, [mbOK], 0);
Stay up-to-date! LogError(E);
Subscribe to our
newsletter.
end;
end;
Enter Email Go!
Advertising
> Free Credit Report In the except block, you use a series of on/do statements to check for different exceptions.
> Free Psychics When using the Exception for E your code will handle all exceptions that occur. In the
MessageDlg we display the error message and the exception class (E.ClassName). For
example, if you try to open a table that is exclusively opened by some other user (Table
design in MS Access) you'll get an EOLEError.
When handling dataset's specific events (for example OnPostError for ADOTable dataset)
we write code for the appropriate events.
procedure TForm1.ADOTablePostError(
DataSet: TDataSet;
E: EDatabaseError;
var Action: TDataAction);
begin
LogError (E); //custom error loggin procedure
{
Show some message to the user
about the failure of the the post operation..
}
Action := daAbort;
end;
The Action parameter indicates how an application should respond to a database error
condition. If you are able to determine the cause of the error and fix it, you use the
daRetry action - Delphi will try to re-execute the Post method. The daAbort action should
be specified when you handle the error (show some meaningful message) and there is no
need for the exception to "go" the the global exception handler (Application.OnException).
The daFial is the default action.
If your application provides the event handler for the OnException event of the
ApplicationEvents component, all the exceptions can be handled in one place:
procedure TForm1.ApplicationEventsException
(Sender: TObject; E: Exception);
begin
LogError (E); //custom error logging procedure
end;
The message property (of the Exception object) can be used to show a message on the
screen, save the message in some log file, or combine some specific message information
with our own custom message.
procedure LogError(E:Exception);
var sFileName : string;
errLogList : TStringList;
begin
sFileName := ExtractFilePath(Application.EXEName) + 'error.log';
errLogList := TStringList.Create;
try
if FileExists(sFileName) then
errLogList.LoadFromFile(sFileName);
with errLogList do
begin
Add('Error Time Stamp: ' +
FormatDateTime('hh:nn am/pm', Now) +
' on ' +
FormatDateTime('mm/dd/yy', Now));
Add('Error Class: ' + E.ClassName);
Add('Error Message: ' + E.Message);
SaveToFile(sFileName);
end; //with
finally
errLogList.Free;
end;
end;
When you open the error.log file with some text editor, you'll get something like:
...
Error Time Stamp: 02:49 pm on 10.30.01
Error Class: EOleException
Error Message: Table 'djelatnici' is exclusively locked by user...
...
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: TASPObject - ASP programming with Delphi.
Introducing the TASPObject. See how to create a real application using Delphi that incorporates the
TASPObject - by creating an ASP page counter to see how many times your ASP has been called.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc.
All rights reserved.
Delphi Programming
with Zarko Gajic Your Guide to one of hundreds of Search in this topic
sites
Home · Articles · Forums · Chat · Classifieds · Newsletters · Help
Shop for Holiday Gifts from merchants like Old Navy, Eddie Bauer, Spiegel, and more!
ESSENTIALS
From ADO Query to HTML
How to export your data to HTML using Delphi and ADO. This is the first step
· A Beginner’s Guide to in publishing your database on the Internet - see how to create a static
Delphi Programming HTML table from an ADO query.
Multimedia
This is how your form should look at design time (in the middle of the form there is a
Delphi Pascal/IDE WebBrowser component)
Screen saver dev.
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Free Code Projects The first thing you need to do when working with a database in Delphi and ADO, is to
set relations between data access components then open a database connection. Just
Humor and Fun to test your knowledge we'll link all DB related components from code (no need to
Icons and Glyphs use the Object Inspector). You place the code in the OnCreate event for the form
(plus some extra code to pre-set other components):
Jobs and Offers
Training/CD/Video procedure TForm1.FormCreate(Sender: TObject);
VCL & Tools var ConStr: widestring;
begin
ConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;'+
Subject Library 'Data Source=C:\!gajba\About\aboutdelphi.mdb;'+
'Persist Security Info=False';
All articles on this
topic DBGrid1.DataSource := DataSource1;
DataSource1.DataSet := ADOQuery1;
ADOQuery1.Connection := ADOConnection1;
Stay up-to-date! ADOConnection1.ConnectionString := ConStr;
Subscribe to our ADOConnection1.LoginPrompt:=False;
newsletter.
Enter Email Go! Edit1.Text:='SELECT * FROM [tablename]';
Memo1.Text:='';
Advertising end;
> Free Credit Report
> Free Psychics
The next step is to get the recordset by opening a query so we can get access to the
data. The query text is in the Edit1 components Text property. The code should be
placed in the OnClick event of a Button1 (as described below).
ADOQuery1.SQL.Text:=Edit1.Text;
ADOQuery1.Open;
HTML code
HTML is the most widely spread format for content on the Web. If your
knowledge on HTML is low, please consider visiting About's HTML site.
Here's a really quick info on html: in general, a HTML page consists of
text, plain ASCII text. An HTML file can contain many, so called, tags
which determine the style of the font, formating of the paragraph, ...
You use special tags to create a table with rows and columns.
After we've opened up a recordset, we loop through the records creating a table for
each entry. Prior to generating a HTML table, we create the HTML header, title and
body. We first loop through the field names to create a table header, then loop
through the recordset to create and fill table rows.
//html header
shtml:= '<html> <head> <title>';
shtml:= shtml + Edit1.Text;
shtml:= shtml + '</title></head>' + #13#10;
shtml:= shtml + '<body>' + #13#10;
shtml:= shtml + 'Table created from query: <i>'
+ Edit1.Text + '</i>' + #13#10;
//table header
shtml:= shtml + '<table border="1" width="100%">' + #13#10;
shtml:= shtml + '<tr>' + #13#10;
for i:=0 to AdoQuery1.FieldCount-1 do
begin
if ADOQuery1.Fields[i].DataType in AvailableFields then
begin
shtml:= shtml + '<td>';
shtml:= shtml +
'<b>' +
ADOQuery1.Fields[i].DisplayName +
'</b>';
shtml:= shtml + '</td>' + #13#10;
end;
end;{for}
shtml:= shtml + '</tr>' + #13#10;
//table body
while not adoquery1.Eof do
begin
shtml:= shtml + '<tr>' + #13#10;
for i:=0 to AdoQuery1.FieldCount-1 do
begin
if ADOQuery1.Fields[i].DataType in AvailableFields then
begin
shtml:= shtml + '<td>';
shtml:= shtml + ADOQuery1.Fields[i].AsString;
shtml:= shtml + '</td>' + #13#10;
end;
end;{for}
shtml:= shtml + '</tr>' + #13#10;
ADOQuery1.Next;
end;{while}
shtml:= shtml + '</table>' + #13#10;
Note: for the sake of simplicity, we'll allow only string, number and date fields to be
converted and inserted in a html table. The AvailableFields variable is a set of
TFieldTypes declared as: AvailableFields: set of TFieldType; in the VAR section and
assigned like: AvailableFields:=[ftWideString, ftDate, ftFloat];
Once you have the shtml string variable filled with the HTML, we simply show it in the
Memo, save the html string to the disk (in the text file that has the applications
name, extension is set to htm), and finally navigate to the saved file in a
WebBrowser.
end;{Button1.OnClick}
Now start the project, write some valid query string in the Edit component, like
SELECT * FROM authors, click the Button1, and this is what you should get:
It is clear that you can easily configure this code to determine which fields to include
and which not, how to sort the database, which filters to apply (you can use WHERE
in your SQL statement), and set the HTML file look (Colors, Fonts, etc). Download the
projects code and start exporting your data to HTML.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of
About, Inc. All rights reserved.
Delphi Programming
with Zarko Gajic Your Guide to one of hundreds Search in this topic
of sites
Home · Articles · Forums · Chat · Classifieds · Newsletters · Help
Shop for Holiday Gifts from merchants like Old Navy, Eddie Bauer, Spiegel, and
more!
ESSENTIALS
Using ADO in Delphi 3 and 4 (before
· A Beginner’s Guide to AdoExpress)
How to import Active Data Objects (ADO) type-libraries in Delphi 3
Delphi Programming
and 4 to create a wrapper around components that encapsulate the
· Free course: Delphi functionality of ADO objects, properties and methods.
ADO DB programming
· Delphi for .NET More of this Feature
Article submitted by: Richard Sutcliffe. Printer friendly version
· Free code APPs &
VCL Join the Discussion
Chapter 21 of the free Delphi ADO DB Couse "Post your views and comments
· A-Z Site Index for beginners. to this chapter of the free Delphi
database Programming Course"
BUYER'S GUIDE Discuss!
With the advent of Delphi 5 Enterprise, Borland
introduced ADO Express, the first time Delphi has Related Resources
What's New and Hot ever provided database access without the BDE. • free DB Course.TOC
The reason behind this whas simple, the BDE had • more Database articles
Top Picks-Tool/VCL its day. COM development was becoming the • TOP ADO wrappers
norm and the BDE was unfortunately
Beginners Here incompatible. Elsewhere on the Web
• Download MS ADO
COM/OLE/ActiveX
Unfortunately, the ADO Express components
Database aren't without their flaws aither. One of the main (now fixed) bugs was the
dreaded 'either BOF or EOF is true or the record has been deleted error. On
Distrubuted comp. top of this, the components were uncomfortably shoe-horned into BDE-style
Game Programming component interfaces.
Graphics
Which leaves us with a quandry over what to do if we want to use Active Data
Internet/Intranet Objects (ADO) in our Delphi applications; after all there are many benefits -
ADO is faster, with native support for some of the more common Microsoft
Mathematics
database engines, and you don't have to live with the old BDE distribution
Multimedia problem as all recent versions of Windows have support built right in.
Delphi Pascal/IDE Delphi does provide an answer, however, in its amazing support for type-
Screen saver dev. libraries and all things COM, by allowing you to import the type-library and
automatically creating a wrapper.
VCL Using
VCL Write/Enhance MSADOxx.TLB - Ado Type Library
To import the ADO type library go to the File menu and select Open... From
Web Services the Files of type combo select Type Library, and browse to the ADO folder
Windows/Shell/API (usually found in \PROGRAM FILES\COMMON FILES\SYSTEM\). The ADO type-
libraries are named MSADOxx.TLB. The number on the end will depend on the
Kylix (D on Linux) version of Windows you have installed (ADO is also installed by Office and
many other programs). The latest version as of writing is 2.7, which you can
Coding standards download from Microsoft.
Books/Publications
Once Delphi has finished processing the MSADOxx.TLB file, it will present you
Dev. Utilities with an editor showing all the types, interfaces, etc it has read from the type-
library. Pressing F12 at this point will display the Pascal wrapper unit
FAQs/Tips/Tricks
ADODB_TLB.PAS (if the file-path isn't the BORLAND\DELPHIx\IMPORTS\ folder
Free Code Projects you may wish to move this so subsequent projects can find it).
Humor and Fun
You can at this point use the ADODB_TLB unit by adding it into your projects
Icons and Glyphs USES clause, however there are some problems to be overcome.
Jobs and Offers
Microsoft's VARIANT type
Training/CD/Video The first is how to handle Microsoft's VARIANT type. Delphi's equivalent is
VCL & Tools OLEVARIANT, though most programmers will be used to the native STRING,
INTEGER and the like. Again this is something Delphi handles with ease with
an array of functions such as VarCast. Below is an example of a function that
Subject Library allows us to cast variants into something easier to swallow:
varStrArg,
varString: result := value;
varBoolean:
if value then
result := 'True'
else result := 'False';
varDispatch, // do not remove IDispatch!
varVariant,
varUnknown,
varTypeMask:
begin
VarAsType(value, varOleStr);
result := value;
end;
else
if VarIsArray(value) then
begin
VarArrayLock(value);
index := VarArrayDimCount(value);
lowVal := VarArrayLowBound(value, index);
highVal := VarArrayHighBound(value, index);
oleArray := TVariantArg(value).pArray;
VarArrayUnlock(value);
Delete(result, length(result) - 1, 2);
end
else
result := ''; //varAny, varByRef
end;
except
// do nothing, just capture
end;
end;
Once you know how to import type-libraries & handle variant types, Microsoft's
MSDN site will become your best friend. There is no way Borland could keep
up with the new type-libraries and technologies churned out by Microsoft,
however by utilizing MSDN you can find out exactly what each method expects
and returns and the wrapper unit will allow you to see exactly how this
converts into Object Pascal.
function adoConnect(
connectionStr: string;
userName: string = '';
password: string = ''
): oleVariant;
begin
result := CreateOleObject('ADODB.Connection');
The example above uses what is termed late-binding, the disadvantage of this
approach being that Delphi cannot interpret what is being called until runtime,
however it does allow you better support as the automatic type-library
conversion process cannot convert every method available. The alternative,
early-binding, utilizes the classes & methods as defined in the Delphi wrapper
unit and as such allow you to use features such as code-completion, although
is much more restrictive. An example of early-binding is shown below:
function adoGetDisconnectedRecordset(
adoCon: oleVariant;
adoSQL: string
): oleVariant;
var
data: RecordSet;
begin
data := CoRecordset.Create;
try
data.CursorLocation := adUseClient;
data.Open(
adoSQL,
adoCon.ConnectionString,
adOpenKeyset,
adLockBatchOptimistic,
adCmdText
);
data.Set_ActiveConnection(nil);
result := data;
finally
data := nil;
end;
end;
Now that you know how to interpret type-libraries you can apply your
knowledge to other Microsoft and third-party technologies, such as XML and
MTS.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: System Tray Delphi application - quick and easy.
Placing Delphi applications in the System Tray in easy steps. The perfect place form programs
that are left running for long periods of time with no user interaction.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark
of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Transactions in Delphi ADO database
· A Beginner’s Guide to development
How many times have you wanted to insert, delete or update a
Delphi Programming
lot of records collectively wanting that either all of them get
· Free course: Delphi executed or if there is an error then none is executed at all? This
article will show you how to post or undo a series of changes
ADO DB programming made to the source data in a single call.
· Delphi for .NET
· Free code APPs & More of this Feature
VCL The general idea behind a transaction is Printer friendly version
that several steps can be performed in
· A-Z Site Index series, with the capability to undo all of the Join the Discussion
steps at once if needed. In addition, the "Post your views and comments
BUYER'S GUIDE to this chapter of the free Delphi
transaction should happen inside an
database Programming Course"
isolated world where other transactions Discuss!
What's New and Hot cannot change data while your transaction
is running. Related Resources
Top Picks-Tool/VCL • free DB Course.TOC
For example, to transfer money between • more Database articles
Beginners Here two bank accounts, you subtract an
COM/OLE/ActiveX amount from one account and add the same amount to the other. If
either update fails, the accounts no longer balance. Treating these
Database changes as a single event ensures either all or none of the changes
apply.
Distrubuted comp.
Game Programming In this chapter of the free Delphi ADO database course we'll see how to
Graphics enable transaction processing in Delphi ADO development.
Internet/Intranet
Advertising
> Free Credit Report
> Free Psychics
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Deploying Delphi ADO database
· A Beginner’s Guide to applications
It is time to make your Delphi ADO database application
Delphi Programming
available for others to run. Once you have created a
· Free course: Delphi Delphi ADO based solution, the final step is to successfully
deploy it to the user's computer.
ADO DB programming
· Delphi for .NET More of this Feature
Once you have created a Delphi Printer friendly version
· Free code APPs &
ADO based solution, the final step is
VCL to successfully deploy it to the Join the Discussion
user's computer. This is the topic "Post your views and comments
· A-Z Site Index will cover in this chapter of the free to this chapter of the free Delphi
database Programming Course"
Delphi ADO database course. Discuss!
BUYER'S GUIDE
Game Programming
Applications that access databases involve special installation
Graphics considerations beyond copying the application’s executable file
onto the target computer.
Internet/Intranet
Mathematics When deploying database applications that use ADO, you need
to be sure that MDAC version 2.1 or later is installed on the
Multimedia
system where you plan to run the application. MDAC is
Delphi Pascal/IDE automatically installed with software such as Windows 98 / 2000
and Internet Explorer version 5 or later. No other deployment
Screen saver dev.
steps are required.
VCL Using
VCL Write/Enhance ADO on Windows 95
If your client's computer has Windows 95 you may get a warning
Web Services indicating that you need DCOM95 to install MDAC, since there is
Windows/Shell/API no support for ADO in Windows 95. Once you install DCOM95,
you'll can proceed and install MDAC. Here's a tip how to find the
Kylix (D on Linux) OS version.
Stay up-to-date!
Subscribe to our Is that all? This seams to easy
newsletter. Yes, when described by words it seems very easy, just copy the
exe file, the mdb file and be sure the client computer has MDAC.
Enter Email Go! Of course, the first time you try to deploy your state-of-the-art
database solution you'll bump into a wall. How to copy a file on
Advertising another computer to a folder like '\Program Files\YOUR
> Free Credit Report COMPANY\PROJECT NAME\ApplicationName.exe'? There is an
> Free Psychics answer that might solve most of the problems, the installation
tools. The Install Sheild Express that comes with some Delphi
versions can be used to create an installation application. This
tool gives your users the ability to select where to install your
application, let's the user decide what parts of the application
would be installed (exe, help, mdb, ...) and makes the process of
creating a Project group in the Start menu easy. Creating
insulation applications with IE Express is not hard nor is it trivial.
I'll leave this for some future article.
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: Transparency in Delphi 6.
How to create a transparent form with Delphi 6 - allowing windows behind
the form to completely show through.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Delphi ADO/DB programming: Real
· A Beginner’s Guide to Problems - Real Solutions
In real world situations, really doing database
Delphi Programming
programming is much more complex than writing about.
· Free course: Delphi This chapter points to some great Delphi Programming
Forum threads initiated by this Course - discussions that
ADO DB programming solve problems on the field.
· Delphi for .NET
· Free code APPs & Related Resources
Hello, and welcome to the 24th
• free DB Course.TOC
VCL chapter of the free Delphi ADO
• more Database articles
database course. Only two more
· A-Z Site Index chapters and the course is over. The
intention of the course was to bring database development with
BUYER'S GUIDE
ADO more closer to Delphi developers. I hope that we managed
to learn some valuable techniques in the last 23 chapters of this
What's New and Hot course.
Top Picks-Tool/VCL
The Course focused on the most common uses of ADO in a
Delphi application: connecting to a database using
Beginners Here TADOConnection, work with Tables and Queries, handle
COM/OLE/ActiveX database exception, create reports, etc. We've managed to cover
most of the situations that arise in real world database
Database application situations. Of course, some topics were not
discussed, covering everything you can do with Delphi and ADO
Distrubuted comp.
could hardly be placed in a single book. As stated in the first
chapters, this free online course is targeted towards Delphi
Game Programming database beginners as well as for those who want a broad
overview of the art of database programming with Delphi.
Graphics
Internet/Intranet My intention, it this chapter, is to point you to some great Delphi
Mathematics Programming Forum threads initiated by the topics we covered
through the Course. In most cases, Forum discussions are real
Multimedia solutions to your real problems!
Delphi Pascal/IDE
Real Problem 1
Screen saver dev. Delphi, MS Access... "Should we use Delphi / ADO combination
VCL Using when doing database applications? Are there a big differences in
the Delphi program which we are going to create by using
VCL Write/Enhance different databases? Maybe not everybody do have Access. On
Web Services the other hand Lotus Approach and Interbase 6 are free
meanwhile."
Windows/Shell/API Real Solution 1
Kylix (D on Linux)
Real Problem 2
ADOExpress / dbGo, BDE, ODBC... "I only can use the ADO
Coding standards
when I have Delphi 5 Enterprise Edition / Delphi 6 Professional!
Books/Publications Is it possible to use Delphi 4/3 as a front end to a local Access
database?"
Dev. Utilities
Real Solution 2 A
FAQs/Tips/Tricks Real Solution 2 B
Free Code Projects
Real Problem 3
Humor and Fun Using TADOConnection, TADOQuery, TADOTable and
Icons and Glyphs similiar... "I'm using Delphi 5 with ADO connected to MS-SQL
server 7. I designed and coded a program using TADOQuery and
Jobs and Offers DBGrid to view all of the records from 7x,xxx records view with
Training/CD/Video joining from 2 tables but the response is very slow (about 2
minutes return). Do you have any others method to improve the
VCL & Tools speed?"
Real Solution 3 A
Subject Library
"Wouldn't it be nice, to have opportunity to manipulate
"Connection String" after the application is compiled? For
All articles on this example if MDB is in a different path or you want to switch to
another version of it. That's a question mostly of the application
topic support..."
Real Solution 3 B
Real Problem 4
Seeking, Locating and Searching for data ... "I am working
with a Access 97 database using Windows 2000 and Delphi 5. I
have a problem with the ADO datasets Seek method. I am
unable to use the Seek method, I get an error about my
database does not support the operation?"
Real Solution 4 A
"Is there any way I can apply a filter to a detail table? I get an
error when I try to do that, but it's really important to me right
now. Is there any way to "fool Delphi" and do it anyway? "
Real Solution 4 B
Real Problem 5
Using data modules... "I have set up a data module using an
ADOConnection, ADOTable and a Datasource. On my TabSheet, I
have dropped a dbGrid component and connected it up to my
datasource, set everything to live and the data displays.
However, as soon as I run the project the data does NOT
display..."
Real Solution 5
Real Problem 6
Creating a database from code... "How to create an MS
Access database without the MS Access. How to add an index to
an existing table, how to join two tables and set up referential
integrity?"
Real Solution 6
Real Problem 7
Deploying Delphi ADO solutions "Here are some problems
when I build my 1-st db-application: AutoNumber as a key filed
and the 'The key value for this row has been changed or deleted
at the data source. The local row is now deleted.'..."
Real Solution 7
Real Problem 8
Delphi, ADO, Access and the rest of the MS Office family "I
have a problem, I receive multiple price lists from a bunch of
companies each week in Microsoft Excel spreadsheets. I need to
put these prices into a database. I need to read the data as I see
fit, cell by cell, row by row..."
Real Solution 8
Real Problem 9
Database reports with Delphi and ADO "I have two forms ....
the first one I used ADOQuery to search the Table and put the
result in the DBGrid .... the second form is to print the result in
the DBGrid to the QReport .... the question is how could I get
the data from the DBGrid to the QReport ??? "
Real Solution 9
Real Problem 10
I'm a newbie! "Where can I find about/learn database
programming with ADO and Delphi for free?"
Real Solution 10
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
TOPIC.
· NEXT ARTICLE: The fastest path to Delphi localization.
How to change the captions on [Yes], [No], [Cancel] and similar buttons that
appear on dialog and message boxes in Delphi applications. Plus how to
personalize error, warning and other messages in those dialogs.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
with Zarko Gajic Your Guide to one of hundreds Search in this topic
of sites
Home · Articles · Forums · Chat · Classifieds · Newsletters · Help
Shop for Holiday Gifts from merchants like Old Navy, Eddie Bauer, Spiegel, and
more!
ESSENTIALS
TOP ADO programming TIPS
Collection of frequently asked questions, answers, tips and tricks
· A Beginner’s Guide to about ADO programming.
Delphi Programming
· Free course: Delphi More of this Feature
ADO DB programming This chapter of free Delphi/ADO DB course offers Printer friendly version
specific recommendations to help improve and
· Delphi for .NET Join the Discussion
speed up the development of your database
· Free code APPs & applications made with Delphi and ADO. "Post your views and comments
to this chapter of the free Delphi
VCL database Programming Course"
Our intention is to update this chapter Discuss!
· A-Z Site Index dynamically with new tips, and code suggestions.
If you have a tip (or a question) on (Delphi) ADO Related Resources
BUYER'S GUIDE programming feel free to add it to this page. • free DB Course.TOC
• more Database articles
Note that some of the questions you might ask
What's New and Hot are most likely already answered through the
chapters of this Course.
Top Picks-Tool/VCL
Access, ADOExpress, dbGo
Beginners Here
COM/OLE/ActiveX My clients do not have Access on their machines, will my Delphi / ADO
application work?
Database
In general: what ever database you create (Paradox or Access) the users of
Distrubuted comp. your software do not need to have MS Access or Paradox on their machines.
When using Access with ADO, MS provides MDAC (components to access an
Game Programming Access database). Note that Microsoft Jet Database Engine is not included with
Graphics MDAC 6.0 and above. MDAC and MS Jet Engine can be downloaded from
www.microsoft.com/data.
Internet/Intranet
Mathematics I have Delphi 5 Professional, where is ADOExpress?
Either you'll need to buy at least Delphi 6 Professional, or try with some third
Multimedia
party ADO VCL components
Delphi Pascal/IDE
Screen saver dev. Connecting to data stores
VCL Using
How do I connect to a MS Access 2000 database?
VCL Write/Enhance ADOConnection.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\MyDatabase.mdb;Persist
Web Services Security Info=False';
Windows/Shell/API
How do I connect to a password protected MS Access 2000 database?
Kylix (D on Linux)
ADOConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Jet
OLEDB:Database Password=XXXXXX;DataSource=C:\MyDatabase.mdb;Persist
Coding standards Security Info=False';
Books/Publications
What provider should I use for MS Access
Dev. Utilities For MS Access 97 use Microsoft.Jet.OLEDB.3.51
FAQs/Tips/Tricks For MS Access 2000 use Microsoft.Jet.OLEDB.4.0
I'm using AutoNumber for Primary Key field to make every record
unique. If I want to read or Edit some ADOTable record after one was
appended (and Post-ed) I get en error: "The specified row could not
be located for updating. Some values may have been changed since it
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Delphi dot NET.
As Borland unveils product strategy for Microsoft's NET platform, a Delphi developer should
find out what .NET is and what the future of Delphi will be.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark
of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Quiz: Delphi ADO Programming
Who Wants to be a Delphi ADO Database Programming
· A Beginner’s Guide to Guru - the trivia game.
Delphi Programming
· Free course: Delphi Join the Discussion
Finally, the last chapter of the Free "Post your views and comments
ADO DB programming online database programming to this chapter of the free Delphi
· Delphi for .NET course for beginner Delphi database Programming Course"
Discuss!
developers - focus on ADO
· Free code APPs & techniques. Since you have come to Related Resources
VCL the end, it is now time to test your
• free DB Course.TOC
Delphi/ADO knowledge. • more Database articles
· A-Z Site Index • Quiz: general Delphi
In the more than 25 chapters of this programming
BUYER'S GUIDE
course you were presented with
some of the most common uses of
What's New and Hot ADO in a Delphi application: Connecting to a database using
TADOConnection, working with Tables and Queries, handling
Top Picks-Tool/VCL database exception, creating reports, etc.
Beginners Here Let's see whether you have learned something or you need to go
COM/OLE/ActiveX back to the beginning and read each chapter once more.
Database
Distrubuted comp. START THE DELPHI / ADO QUIZ
Game Programming
All graphics (if any) in this feature created by Zarko Gajic.
Graphics
Internet/Intranet More Delphi
· Learn another routine every day - RTL Quick Reference.
Mathematics
· Download free source code applications and components.
Multimedia · Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
Delphi Pascal/IDE · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by
Screen saver dev. TOPIC.
· NEXT ARTICLE: Introducing Borland Delphi.
VCL Using A Beginner’s Guide to Delphi Programming: Chapter 1. What is Borland
VCL Write/Enhance Delphi? Where to download a free version, how to install and configure it.
Stay informed with all new and interesting things about Delphi (for free).
Web Services
Subscribe to the About Programming Newsletter
Windows/Shell/API
Name Email
Kylix (D on Linux)
subscribe
Coding standards Got some code to share? Got a question? Need some help?
Recent Discussions
Books/Publications
Delphi Programming
Dev. Utilities Join these forum conversations
FAQs/Tips/Tricks
Extracting digital audio from cd
Free Code Projects Delphi disadvantages compared to VS.Net
Humor and Fun Keep An Application Always On Top
Delphi7 adoblob problem
Icons and Glyphs
Searching in a text file or wide string
Jobs and Offers
Training/CD/Video
VCL & Tools
Email this page!
Subject Library
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Quiz: Delphi ADO Programming
Question: 1
· A Beginner’s Guide to
Delphi Programming
· Free course: Delphi
Simply put, a database is
ADO DB programming best described as...
· Delphi for .NET
a) a collection b) a collection
· Free code APPs & of all files on a of files in a
VCL system directory
Top Picks-Tool/VCL
Beginners Here
COM/OLE/ActiveX Email this page!
Database
Distrubuted comp.
Game Programming
Graphics
Internet/Intranet
Mathematics
Multimedia
Delphi Pascal/IDE
Screen saver dev.
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
FAQs/Tips/Tricks
Free Code Projects
Humor and Fun
Icons and Glyphs
Jobs and Offers
Training/CD/Video
VCL & Tools
Subject Library
Stay up-to-date!
Subscribe to our
newsletter.
Enter Email Go!
Advertising
> Free Credit Report
> Free Psychics
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy
Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About
logo is a trademark of About, Inc. All rights reserved.
Delphi Programming
ESSENTIALS
Pictures inside a database
Page 4: Seeking the start of Jpeg in the BLOB.
· A Beginner’s Guide to More of this Feature
Delphi Programming OLE object type format - take three! • Page 1: BLOBs in Access
All this leaves us with nothing but to store the • Page 2: DBImage.NOT
· Free course: Delphi • Page 3: Streaming JPG
picture to a disk (as an ordinary binary file)
ADO DB programming and see what's inside it. • Page 5: Project's Code
One nice thing with picture files (formats) is Printer friendly version
· Delphi for .NET that all have some header that uniquely
· Free code APPs & identifies the image. The JPG picture file starts Join the Discussion
with the, so called, SOI marker that has the "Post your views and
VCL
value of $FFD8 hex. comments to this chapter of
· A-Z Site Index the free Delphi database
Programming Course"
This next line of code stores the value of the Discuss!
BUYER'S GUIDE Picture field to a file (BlobImage.dat) in the
working directory. Assign this code in the Related Resources
OnCreate event for the form, start the project • free DB Course.TOC
What's New and Hot
and remove the code. • Delphi DB articles
Top Picks-Tool/VCL
ADOTable1Picture.SaveToFile('BlobImage.dat');
Beginners Here
COM/OLE/ActiveX
Database Once we have the file, we can use some Hex editor to see it's content.
Distrubuted comp.
Game Programming
Graphics
Internet/Intranet
Mathematics
Multimedia
Delphi Pascal/IDE
Screen saver dev.
VCL Using
VCL Write/Enhance
Web Services
Windows/Shell/API
Kylix (D on Linux)
Coding standards
Books/Publications
Dev. Utilities
Would you believe this! MS Access stores the path of a linked OLE object
FAQs/Tips/Tricks as part of the object's definition in the OLE object field. Because the
Free Code Projects definition of OLE object storage is not documented (!? this is straight
from MS) there is no way to know what gets written before the actual
Humor and Fun image data.
Icons and Glyphs
Think about this twice. First: we'll need to seek to the 'FFD8' and read
Jobs and Offers the image from there. Second, the 'FFD8' might not always be at the
Training/CD/Video same position in the file. Conclusion: we need a function that returns the
position of the SOI marker for the JPG file stored as OLE object in an
VCL & Tools Access database.
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := bS.Position - 2
else if hx = 'FF' then
bS.Position := bS.Position-1;
end; //if
end; //while
finally
bS.Free
end; //try
end;
uses jpeg;
...
procedure TForm1.btnShowImageClick(Sender: TObject);
var
bS : TADOBlobStream;
Pic : TJpegImage;
begin
bS := TADOBlobStream.Create
(AdoTable1Picture, bmRead);
try
bS.Seek(JpegStartsInBlob(AdoTable1Picture),
soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(bS);
ADOImage.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
bS.Free
end;
end;
Note: in real code application we would have the code to read and
display the image from the current row in the AfterScroll event of a
TDataSet (that is in the ADOTable1AfterScroll event procedure).
AfterScroll occurs after an application scrolls from one record to another.
Take five!
That's it for this chapter. You can now store and display all your favorite
JPG pictures. In the last page of this article I have provided you with the
entire code (form1's unit); all the data assignment is placed in the
OnCreate event of the form. This ensures that all three components are
correctly linked - you don't need to use the Object Inspector at design-
time.
I agree, the chapter was not designed for beginners, but hey the World is
cruel. Another thing: did you mentioned that at the end you don't know
how to change (or add some new) picture in a table! We'll, that's whole
another story!
More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Owner and Parent.
The differences between a component Owner and its Parent - briefly explained.
Stay informed with all new and interesting things about Delphi (for free).
Name Email
subscribe
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy |
Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a
trademark of About, Inc. All rights reserved.