Summary of Examples:
------- -- ---------
Example #1:
Example #1 creates and configures an Alias to use
STANDARD (.DB, .DBF) databases. The Alias is
then used by a TTable component.
Example #2:
Example #2 creates and configures an Alias to use
STANDARD (.DB, .DBF) databases. This example
demonstrates how user input can be used to
configure the Alias during run-time.
Example #1: Use of a .DB or .DBF database (STANDARD)
1. Create a New Project.
2. Place the following components on the form:
- TDatabase, TTable, TDataSource, TDBGrid, and TButton
3. Double-click on the TDatabase component or choose Database
Editor from the TDatabase SpeedMenu to launch the Database
Property editor.
4. Set the Database Name to 'MyNewAlias'. This name will
serve as your ALIAS name used in the DatabaseName Property for
dataset components such as TTable, TQuery, TStoredProc.
5. Select STANDARD as the Driver Name.
6. Click on the Defaults Button. This will automatically add
a PATH= in the Parameter Overrides section.
7. Set the PATH= to C:\DELPHI\DEMOS\DATA
(PATH=C:\DELPHI\DEMOS\DATA)
8. Click the OK button to close the Database Dialog.
9. Set the TTable DatabaseName Property to 'MyNewAlias'.
10. Set the TDataSource's DataSet Property to 'Table1'.
11. Set the DBGrid's DataSource Property to 'DataSource1'.
12. Place the following code inside of the TButton's
OnClick event.
procedure TForm1.Button1Click(Sender: TObject);
begin
Table1.Tablename:= 'CUSTOMER';
Table1.Active:= True;
end;
13. Run the application.
*** If you want an alternative way to steps 3 - 11, place the
following code inside of the TButton's OnClick event.
procedure TForm1.Button1Click(Sender: TObject);
begin
Database1.DatabaseName:= 'MyNewAlias';
Database1.DriverName:= 'STANDARD';
Database1.Params.Clear;
Database1.Params.Add('PATH=C:\DELPHI\DEMOS\DATA');
Table1.DatabaseName:= 'MyNewAlias';
Table1.TableName:= 'CUSTOMER';
Table1.Active:= True;
DataSource1.DataSet:= Table1;
DBGrid1.DataSource:= DataSource1;
end;
Example #2: User-defined Alias Configuration
This example brings up a input dialog and prompts the user to enter the
directory to which the ALIAS is to be configured to.
The directory, servername, path, database name, and other neccessary
Alias parameters can be read into the application from use of an input
dialog or .INI file.
1. Follow the steps (1-11) in Example #1.
2. Place the following code inside of the TButton's
OnClick event.
procedure TForm1.Button1Click(Sender: TObject);
var
NewString: string;
ClickedOK: Boolean;
begin
NewString := 'C:\';
ClickedOK := InputQuery('Database Path',
'Path: --> C:\DELPHI\DEMOS\DATA', NewString);
if ClickedOK then
begin
Database1.DatabaseName:= 'MyNewAlias';
Database1.DriverName:= 'STANDARD';
Database1.Params.Clear;
Database1.Params.Add('Path=' + NewString);
Table1.DatabaseName:= 'MyNewAlias';
Table1.TableName:= 'CUSTOMER';
Table1.Active:= True;
DataSource1.DataSet:= Table1;
DBGrid1.DataSource:= DataSource1;
end;
end;
3. Run the Application.
-------------------------------------
See Also:
Delphi On-line help -->
Database Properties Editor
TDatabase
HTH
Rkr
Quote
Kai Inge Buseth wrote:
> Hello,
> Now I've made a new program for my friend. He has one installed already with
> BDE and an alias.
> If I try to ship a new alias with the second program I get an error:
> Merging the configuration file has failed.
> I use Install Shield, and I have to install (partial) the dBase driver the
> second time to get able to write the latest alias.
> I assume that the trouble starts there.
> My question is then:
> How to add a new alias to an already installed DBE ?
> --
> Kind regards
> Kai Inge
> {If it's not broke - don't fix it.}