目标:打开应用程序,弹出认证模块,如果输入错误,提示错误类型,关闭窗体;如果认证通过显示主窗体;
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls,Math;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function doLogin(value:string):Boolean;
begin
if value='123456' then //判断序列号,也可以通过数据库来认证
begin
Application.ShowMainForm:=True; // 创建主窗体
Result := True;
end else
begin
MessageDlg('错误[1005]',mtError,[mbOK],0); //提示错误信息
Result := False;
Application.ShowMainForm:=false; // 不创建主窗体
Application.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s : string;
begin
s := InputBox('登录','请输入序列号',s); //把用户输入的信息赋值给 S
doLogin(s);
end;
end.
浙公网安备 33010602011771号