怎样制作登录窗体

⑴让登录窗体在主窗体运行前打开,
⑵根据登录窗体返回值判断主窗体是否应该运行。
详细代码如下:

//project.dpr文件

program project;
... ...
... ...

begin
Application.Initialize;


EntryFrm:=TEntryFrm.Create(application); //登录窗口
if EntryFrm.ShowModal=mrOK then //登录窗体关闭时返回了mrOK值,说明登录成功
begin
Application.CreateForm(TMainFrm, MainFrm);
//其它auto-create forms
end;
EntryFrm.Free;
application.Terminate


Application.Title := '某某管理系统';
Application.Run;
end.





//entry.pas 登录窗体文件
var
count:short; //登录次数

{$R *.dfm}

procedure TEntryFrm.BitBtn2Click(Sender: TObject);//取消登录
begin
application.Terminate;
end;

procedure TEntryFrm.BitBtn1Click(Sender: TObject);//确定登录
begin
Inc(count);
ID:=edit1.Text; //帐号
Pas:=edit2.Text; //密码;ID,Pas是全局变量


//※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※//
IDInfo.Open;
if IDInfo.Locate('ID',ID,[]) then
begin
if StrEncry(IDInfo.FieldByName('Pas').AsString)=Pas then //密码解密,登录成功
begin
Pop:=IDInfo.fieldbyname('Pop').AsString; //取得权限
writelog(ID,'登录'); //写入日志
self.ModalResult:=mrOK; //关闭窗口并返回mrOK值
end;
end;
if count>=3 then self.ModalResult:=mrabort; //只允许登录3次
IDInfo.Close;
//※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※//


edit1.Text:='';
edit2.Text:='';
edit1.SetFocus;
end;

原文地址:https://www.cnblogs.com/hssbsw/p/3159711.html