On the tools pallette, there are 2 applicable tabs
Therefore, this page will discuss setting the Data Access components which are used to define Data Sources.
TTable -> TDataSource -> TQuery TTable -> TDataSource -> TDBComboBox TDatabase -> TTable -> TDataSource -> TDBComboBox
TTable connects to an ODBC database, a directory for Paradox tables, or a TDatabase component. DatabaseName, TableName The pick list on TTable.DatabaseName lists available ODBC aliases and TDatabase.DatabaseName values. TDataSource - DataSet (TDataSet/TTable) Use this to handle record level processing. It keeps all related controls pointing to the same record. All data aware components must attach to a DataSource. TDBComboBox - DataSource (TDataSource), DataField more First, Next, Last (and the like) are abstract members of TDataSet. DataSet is a property of TDataSource. TTable is a desendent of TDataSet.
Use TDatabase when you are using the BDE. Explicit declaration is not necessary unless you want access to the properties and methods at run time. The main advantage is the ability to disable the username/password request dialog box and/or to supply that data programatically.
If a TTable is used without explicitly associating it to an existing TDatabase, then an implicit TDatabase is created as necessary to control the connection.
Basic Procedure to See a Table's Contents
Table1.DatabaseName | Select from the list of ODBC databases. (I am assuming that your system has at least one defined.) |
Table1.TableName | Pick a value from the list of available tables. (You will probably be prompted for a username and password.) |
Table1.Active | Set this to True. (The default is always false. True allows you to see data, False does not.) |
DataSource1.DataSet | Pick the only value from the picklist. (This will be the TTable added ealier.) |
DBGrid1.DataSource | Pick the only option from the picklist. |
In order to step through the records, double click the TTable component (this opens the Fields editor dialog box) and use the VCR buttons to step through the records.
TDatabase
Database1.AliasName | Select from the list of ODBC or BDE database aliases. (I am assuming that your system has at least one defined.) Setting this clears Database1.DatabaseName. |
Database1.DatabaseName | This is the name that TTable components will link to. This can be the same as Database1.AliasName, you may make up a name, or you may enter the fully qualified path to a Paradox database (directory). An MS Access mdb file can not be entered here. |
Database1.LoginPrompt | Set this False to disable the default dialog box. |
Database1.OnLogin | Attaching code to this event will also disable the default dialog box. (Hardcoding userID's and passwords is considered to be a security problem.) |
Database1.Params | If Database1.AliasName is blank, and Database1.DriverName
is assigned to MSACCESS, then this is how to specify
an MS Access database.
DATABASE NAME=H:\Shared\xxx\Databases\Converted.mdb ODBC DSN= |
I can not figure out how to get Microsoft Access Driver (*.mdb) to work.
Sequence to connect to an MS Access mdb file without using ODBC.
TDatabase -> TTable -> TDataSource -> TDBGrid
Field Components
There are a number of advantages to creating explicit field components.
You must use the Fields editor to add and remove presistent fields.
BDE
However, from the developer's point of view, the BDE based Data Explorer is an excelent tool that you should be very familiar with. (From inside Delphi, select Database / Explore) This tool will allow you to browse tables - you can see the data, determine the structure, and the like.
Run the BDE administrator to define aliases.
ADO
ADO is not part of Delphi 5 Professional - you must import it. Pay special attention to these installation instructions. Project / Import Type Library and select
KA DAO
The available help is pretty good, but it is not integrated into the Delphi help. Just open KADAO.HLP. Basic instructions are described via
Contents / Tips and tricks / How to make an simple application using KADao as a Table component?
In order to access an *.mdb file,
Tab Component KA DAO TKADaoDatabase KA DAO TKADaoTable Data Access TDataSource Data controls TDBEdit Data controls TDBNavigator
Component | Property | Value | Comments |
---|---|---|---|
KADaoDatabase1 | DatabaseType | Access | This is the default value |
Database | name of the *.mdb file | ||
MdbVersionAutoDetect | True | Optional, may help | |
Version |
3.5 3.6 4.0 | Access XX-97 Access 2000-2002 Access 2002 SP-1 | |
Connected | True | This connects the database | |
KADaoTable1 | Database | KADaoDatabase1 | |
TableName | Pick one from the list | ||
Active | True | ||
DataSource1 | DataSet | KADaoTable1 | |
Enabled | True | ||
DBEdit1 | DataSource | DataSource1 | |
DataField | Select any field | ||
DBNavigator1 | DataSource | DataSource1 | |
VisibleButtons | Disable those you don't need |
There are 18 related dcu's - therefore, I keep them all with the original KADAO directory and link to it.
Running from a CD-ROM
Set KADaoDatabase1.ReadOnly to True The default is False Set KADaoDatabase1.Exclusive to True The default is FalseYou can test the first step by right clicking the *.mdb file in Windows Explorer and setting its properties to ReadOnly.
Normally, when an *.mdb file is opened,
a lock file (*.ldb) is created in the same directory as the *.mdb file.
However, since a CD-ROM is
"per record" code
Errors
dbExpress
Delphi, dbExpress And MySQL
explains how to use dbExpress to connect to MySQL.
It also provides a warning -
dbExpress:
Firebird
Using the Interbase Components
In order to access an *.gdb file,
Tab Component InterBase TIBDatabase InterBase TIBTransaction InterBase TIBTable Data Access TDataSource Data controls TDBEdit Data controls TDBNavigator
Component | Property | Value | Comments |
---|---|---|---|
IBDatabase1 | DatabaseName | Set this to the *.gdb or *.fdb file | |
Connected | True | This connects the database | |
IBTransaction1 | DefaultDatabase | IBDatabase1 | |
Active | True | ||
IBTable1 | Database | IBDatabase1 | |
Transaction | IBTransaction1 | Automatically selected | |
TableName | Pick one from the list | ||
Active | True | ||
DataSource1 | DataSet | IBTable1 | |
Enabled | True | Default value | |
DBEdit1 | DataSource | DataSource1 | |
DataField | Select any field | ||
DBNavigator1 | DataSource | DataSource1 | |
VisibleButtons | Disable those you don't need |
In order to automatically connect to a Firebird database, set the following
user_name=sysdba password=masterkey
To connect to the Interbase example database distributed with Delphi, set IBDatabase1.DatabaseName to
MachineID:C:\Program Files\Common Files\Borland Shared\Data\employee.gdb
According to a newsgroup post, TIBTable should never be used with Client/Server applications - use IBDataset instead. (They are both based on TIBCustomDataSet) This partly because a TIBTable.Refresh will not return inserted items and IBDataset.Refresh will (I guess that the query is reexecuted).
ODBC/ADO
Field | Comment |
---|---|
Data Source Name | This is the name (alias) your program uses |
Database | Fully qualified path when the Network protocol is Local |
In order to access an *.gdb file via ODBC/ADO (I was never able to get this to work),
KADaoDatabase1.UserName | sysdba |
KADaoDatabase1.Password | masterkey |
KADaoDatabase1.DatabaseType | ODBC |
KADaoDatabase1.Database | Select from the list of ODBC database aliases. (I am assuming that your system has at least one defined.) |
KADaoDatabase1.LoginPrompt | Set this False to disable the default dialog box. |
KADaoDatabase1.OnLogin | Attaching code to this event will also disable the default dialog box. (Hardcoding userID's and passwords is considered to be a security problem.) |