主窗口代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Unit2, DBTables, DB;
type
TForm1 = class(TForm)
dm: TTable;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
if not SysLogin(DM.tblOperator) then Application.Terminate;
end;
副窗口代码如下:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,DBtables, DB;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
Edit1: TEdit;
Table1: TTable;
procedure BitBtn1Click(Sender: TObject);
private
Count: Integer;
public
tbl: TTable;
end;
function SysLogin(tbl: TTable): Boolean;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
if tbl.FieldByName('Password').AsString <> edit1.Text then
begin
ShowMessage('密码错误!');
Inc(Count);
if Count = 3 then
begin
ShowMessage('三次密码错误!');
ModalResult := mrCancel;
end
else
ModalResult := mrNone;
end;
end;
function SysLogin(tbl: TTable): Boolean;
begin
form2 := Tform2.Create(Application);
form2.tbl := tbl;
Result := form2.ShowModal = mrOk;
form2.Free;
end;
end.