//Rxlib里的一个子程
function ShowDialog(FormClass: TFormClass): Boolean;
var
Dlg: TForm;
begin
Application.CreateForm(FormClass, Dlg);
try
Result := Dlg.ShowModal in [mrOk, mrYes];
finally
Dlg.Free;
end;
end;
//main form的代码
procedure TfrmMain.FormCreate(Sender: TObject);
begin
if ShowDialog(TfrmLogin)=False then Application.Terminate;
end;
//frmLogin的代码
procedure TfrmLogin.btnLoginClick(Sender: TObject);
var
Password:string;
begin
with DM.adsTeacher do
begin
if Locate('用户名',cbUsername.Text,[]) then
begin
if varIsNull(FieldByName('密码').Value) then
Password:=''
else
Password:=DM.adsTeacher.FieldByName('密码').AsString;
if editPassword.Text=Password then
begin
uGlobals.teacherID:=FieldByName('教师ID').AsInteger;
uGlobals.GradeNo :=FieldByName('年级').AsInteger;
uGLOBALS.ClassNo :=1;
ModalResult:=mrOK;
end
else
ShowMessage('密码不正确!');
end
else
Showmessage('用户名不存在!');
end;{with}
end;
frmLogin 返回一个ModalResult,如果密码正确则返回mrOK,否则mrCancel,如果为mrOK则
ShowDialog返回True,否则False,也可以在.dpr文件里,不过这样的话,frmlogin就是主
Form,退出后就会整个程序都退出
给分吧