⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bde.htm

📁 对于学习很有帮助
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>UDDF - BDE</TITLE>
<META NAME="Description" CONTENT=" BDE section of the Delphi Developers FAQ" >
<META NAME="KeyWords" CONTENT="" >

</HEAD>

<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#ffffff">

<CENTER>
<IMG SRC="../images/uddf.jpg"> </CENTER>

<P><HR SIZE=6 color="#00FF00"></P>
<FONT FACE="Arial Black" SIZE=7 COLOR="#ff0000"><P ALIGN="CENTER">BDE Information</FONT> </P>


<p><H1><A NAME="bde0">Defining a BDE Alias in Code <img src="../images/new.gif" width=28 height=11 border=0 </A></H1>
alt=" [NEW]"></H1></p>

This Technical Information document will help step thru concepts regarding
the creation and use of ALIASES within your Delphi Applications.<p>

Typically, you use the BDE Configuration Utility BDECFG.EXE to create and
configure aliases outside of Delphi.  However, with the use of the TDatabase
component, you have the ability to create and use this ALIAS within your
application-- not pre-defined in the IDAPI.CFG.<p>

The ability to create Aliases that are only available within your
application is important.  Aliases specify the location of database tables
and connection parameters for database servers.
Ultimately, you can gain the advantages of using ALIASES within your
applications-- without having to worry about the existance of a
configuration entry in the IDAPI.CFG when you deploy your 
application.  <p>

<B>Summary of Examples:</B><p>

<I>Example #1: </I> <p>
	Example #1 creates and configures an Alias to use 
	STANDARD (.DB, .DBF) databases.  The Alias is
    	then used by a TTable component.<p>
<I>Example #2:</I><p>
	Example #2 creates and configures an Alias to use
 	an INTERBASE database (.gdb).  The Alias is then
	used by a TQuery component to join two tables of
	the database.<p>
<I>Example #3:</I><p>
	Example #3 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.<p>


<B><I>Example #1:  Use of a .DB or .DBF database (STANDARD)</I></B><p>

 <OL>
	<LI>Create a New Project.

<LI> Place the following components on the form:  - TDatabase, TTable,
TDataSource, TDBGrid, and TButton.
 
<LI> Double-click on the TDatabase component or choose Database Editor from
the TDatabase SpeedMenu to launch the Database Property editor.

<LI>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.

<LI>Select STANDARD as the Driveer Name.

<LI> Click on the Defaults Button.  This will automatically add  a PATH= in
the Parameter Overrides section.

<LI>Set the PATH= to C:\DELPHI\DEMOS\DATA  (PATH=C:\DELPHI\DEMOS\DATA)

<LI>Click the OK button to close the Database Dialog.

<LI>Set the TTable DatabaseName Property to 'MyNewAlias'.

<LI>Set the TDataSource's DataSet Property to 'Table1'.

<LI>Set the DBGrid's DataSource Property to 'DataSource1'.

<LI>Place the following code inside of the TButton's OnClick event.

<PRE>    procedure TForm1.Button1Click(Sender: TObject);
    begin
          Table1.Tablename:= 'CUSTOMER';
          Table1.Active:= True;
    end;
</PRE>

<LI>Run the application.
</OL>

<I>***  If you want an alternative way to steps 3 - 11, place the following
code inside of the TButton's OnClick event.
</I><P>

<PRE>    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;
</PRE>

<B><I>Example #2: Use of a INTERBASE database</I></B><P>
<OL>
<LI>  Create a New Project.

<LI>  Place the following components on the form: - TDatabase, TQuery,
TDataSource, TDBGrid, and TButton.

<LI>  Double-click on the TDatabase component or choose Database Editor from
the TDatabase SpeedMenu to launch the Database  Property editor.

<LI>  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.

<LI>  Select INTRBASE as the Driver Name.

<LI>  Click on the Defaults Button.  This will automatically add  the
following entries in the Parameter Overrides section.

<PRE>	SERVER NAME=IB_SERVEER:/PATH/DATABASE.GDB
	USER NAME=MYNAME
	OPEN MODE=READ/WRITE
	SCHEMA CACHE SIZE=8
	LANGDRIVER=
	SQLQRYMODE=
	SQLPASSTHRU MODE=NOT SHARED
	SCHEMA CACHE TIME=-1
	PASSWORD=
</PRE>

<LI>  Set the following parameters

<PRE>	SERVER NAME=C:\IBLOCAL\EXAMPLES\EMPLOYEE.GDB
	USER NAME=SYSDBA
	OPEN MODE=READ/WRITE
	SCHEMA CACHE SIZE=8
	LANGDRIVER=
	SQLQRYMODE=
	SQLPASSTHRU MODE=NOT SHARED
	SCHEMA CACHE TIME=-1
	PASSWORD=masterkey
</PRE>

<LI> Set the TDatabase LoginPrompt Property to 'False'.  If you  supply the
PASSWORD in the Parameter Overrides section and set the LoginPrompt to
'False', you will not be prompted for the 
password when connecting to the database.  WARNING:  If an incorrect
password in entered in the Parameter Overrides  section and LoginPrompt is
set to 'False', you are not prompted by the Password dialog to re-enter a
valid password.

<LI>  Click the OK button to close the Database Dialog.

<LI>  Set the TQuery DatabaseName Property to 'MyNewAliias'.

<LI>  Set the TDataSource's DataSet Property to 'Query1'.

<LI>  Set the DBGrid's DataSource Property to 'DataSource1'.

<LI>  Place the following code inside of the TButton's OnClick event.

<PRE>    procedure TForm1.Button1Click(Sender: TObject);
    begin
          Query1.SQL.Clear;
          Query1.SQL.ADD(
		'SELECT DISTINCT * FROM CUSTOMER C, SALES S
		WHERE (S.CUST_NO = C.CUST_NO)
		ORDER BY C.CUST_NO, C.CUSTOMER');
          Query1.Active:= True;
    end;
</PRE>

<LI>  Run the application.
</OL>

<B><I>Example #3: User-defined Alias Configuration</I></B><P>

This example brings up a input dialog and prompts the user to enter the
directory to which the ALIAS is to be configured to.  <P>

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.<P>

<OL>
<LI> Follow the steps (1-11) in Example #1.

<LI> Place the following code inside of the TButton's  OnClick event.

<PRE>procedure TForm1.Buttton1Click(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;
</PRE>

<LI> Run the Application.
</OL>

<H1><A NAME="bde1">BDE alias info</A></H1>
<I><P>From: "Sven Lindhardt" &lt;svenlind@inet.uni-c.dk&gt;</P>

</I><PRE>&gt; 
&gt; Does anyone know how to interrogate the IDAPI configuration to get the directory 
mapping for an alias?
&gt; 
</PRE>

<P>Take a look at the GetAliasParams Method of TSession.</P>
<P>The returned stringlist will contain the path.</P>
<P>I use the following function: </P>
<P><HR></P>
<PRE>uses  DbiProcs, DBiTypes;

function GetDataBaseDir(const Alias : string): String;
(* Will return the directory of the database given the alias
  (without trailing backslash) *)
var
  sp  : PChar;
  Res : pDBDesc;
begin
  try
    New(Res);
    sp := StrAlloc(length(Alias)+1);
    StrPCopy(sp,Alias);
    if DbiGetDatabaseDesc(sp,Res) =  0
    then Result := StrPas(Res^.szPhyName)
    else Result := '';
  finally
    StrDispose(sp);
    Dispose(Res);
  end;
end;</PRE>

<HR><P>


<HR SIZE="6" color="#00FF00">
<P><A HREF="mailto:rdb@ktibv.nl">
<FONT SIZE=2>Please email me</FONT></A><FONT SIZE=2> and tell me if you liked this page.<BR>
<SCRIPT LANGUAGE="JavaScript"><!--
	document.write("Last modified " + document.lastModified);
// --></SCRIPT></FONT>
<P ALIGN="CENTER"><CENTER><TABLE CELLSPACING=0 BORDER=0>
<TR><TD VALIGN="MIDDLE">
<P><FONT SIZE=2>This page has been created with </FONT></TD>
<TD VALIGN="MIDDLE">
<P><A HREF="http://www.dexnet.com./homesite.html"><IMG SRC="../images/hs25ani.gif" WIDTH=88 HEIGHT=31 BORDER=0 ALT="HomeSite 2.5b"></A></TD>
</TR>
</TABLE>
</CENTER></P>

<P>&nbsp;</P>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -