creates a persistent connection to a database. This is particularly useful with remote database servers with TDatabase components it is the AliasName
property that identifies the parmanent alias created with the Database
Desktop or the BDE configuration program that you want to connect to.
THe TDatabase component's DatabaseName property specifies the name of a temporary alias created by the TDatabase component. Assign the temporary
alias to the DatabaseName property of the other components.
Property
LoginPrompt - set to FALSE if you will supply the user name and password in the Params property
DatabaseName - temporary alias created by the Database components, this is the alias that your TTable, TQuery used sample code below show's the get password procedure or related kind of thing;
procedure TForm1.ButtonClick(Sender : TObject);
var
password : String[32];
indx : word;
begin
{ initialize the password to null }
password := '';
{ turn off connection }
Database1.Connected := false;
if InputQuery('Password Please',
'Enter a Test password up to 32 characters.',
password) then
begin
{ add the password to the database component's params property }
Database1.Params.Add('password='+password);
{ see if the password is really in the Params list now }
indx := Database1.Params.IndexOf('password='+password);
if indx >= 0 then
MessageDlg('Password stored in Params.',
mtInformation,
[mbOk],
0)
else
MessageDlg('Password not stored',
mtWarning,
[mbOk],
0);
end
else
MessageDlg('You did not enter anything',
mtError,
[mbOk],
0);
end;
|
This code begins by calling the InputQuery function to display a dialog box and to prompt you to enter a test password. InputQuery returns a True if you click the Ok button else a False otherwise.
Remember that if you are going to prompt the user for the password and add it to the Params list, you must set the TDatabase's Connected property to False when you design the form, If not there will be problems.
Remember also to set the TDatabase's LoginPrompt property to False too else Delphi will prompt you for a user name and password.
|