Leslie your TDatabase is the central point for all your queries and tables. In other words your
alias is defined in the Tdatabase only.
The
alias of the TDatabase is the one defined in the BDE. I suspect that this one called
metro
Set the
DtabaseName property to
my_Metro_db
All your tables and queries must then have their databaseName property set to
my_Metro_db
For connecting I use a modal form with 2 editboxes, 2 buttons and labels. This modal form has a global function called GetLoginParms
type
TLoginFrm = class(TForm)
lblUsername: TLabel;
lblPassword: TLabel;
edtUserName: TEdit;
edtPassword: TEdit;
bbtnOK: TBitBtn;
bbtnCancel: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
end;
function GetLoginParams(ALoginParams: TStrings): Boolean;
Code:
function GetLoginParams(ALoginParams: TStrings): Boolean;
var
LoginForm: TLoginFrm;
begin
Result := False;
LoginForm := TLoginFrm.Create(Application);
try
if LoginForm.ShowModal = mrOk then
begin
ALoginParams.Values['USER NAME'] :=
LoginForm.edtUsername.Text;
ALoginParams.Values['PASSWORD'] :=
LoginForm.edtPassWord.Text;
Result := True;
end;
finally
LoginForm.Free;
end;
end;
---------------------------------
The database, queries etc. are put on a datamodule called
datamod with 4 public functions/procedures
procedure Logout;
function Login: boolean;
function Connect: boolean;
procedure disconnect;
//the login event of the tdatabase
procedure TDtaMod.my_Metro_DBLogin(Database: TDatabase;
LoginParams: TStrings);
begin
{ Calls method below to populate the loginParams strings list
GetLoginParams(LoginParams);
end;
Procedure TDtaMod.Logout;
begin
disconnect;
end;
procedure TDtaMod.disconnect;
begin
//disconnect from database
my_Metro_DB.Connected := false;
end;
Code:
function TMainDtaMod.Connect: Boolean;
{ Connects the user to the Database. When my_metro_db is set to True, its
OnLogon event handler will be invoked which will invoke the login
dialog defined in LoginForm.pas }
begin
try
dbTraps.Connected := true;
qry1.Active := true;
qry2.Active := true;
....activate all queries and table....
Result := true;
except
MessageDlg('Invalid Password or Login information,
cannot login', mtError, [mbok],0);
my_Metro_db.Connected := false;
Result := false;
end;
end;
The only things needed in your program are
login & logout which can be easily corporated in a menu
By the way this code I have from
Delphi 4 Developer's guide
Best Regards Steven van Els
SAvanEls@cq-link.sr