cyberfan's blog

正其谊不谋其利,明其道不计其功

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  15 随笔 :: 489 文章 :: 44 评论 :: 0 Trackbacks
⑴让登录窗体在主窗体运行前打开,
⑵根据登录窗体返回值判断主窗体是否应该运行。
详细代码如下:

//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;
posted on 2005-08-12 15:55 cyberfan 阅读(241) 评论(0)  编辑 收藏 引用 所属分类: delphi
只有注册用户登录后才能发表评论。