第一次尝试一天码两篇文章,分享知识的过程是快乐的。
上午试着去做一个简单的登陆界面,基本上算完成了。
登录名和密码要与数据表中匹配,才能登陆成功。
这里采用的是Delphi的ADO连接SQL server数据库,具体连接过程,可参照我前两天的博客,这里不再赘述。
现在将设计的过程分享下。
1、设计的界面及运行的结果
运行的时候要保证ADOtable1的active的属性为true.
同时保证SQL服务已经开启。我的需要手动开启。
登陆成功后进入的界面:
2、附上源码:
unit Welcome;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
//uses master;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
Edit2: TEdit;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses master; //引用加在实现部分。
{$R *.dfm}
var
time:Integer=0;
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
results:variant; //16字节可变类型
begin
ADOTable1.Active:=true;
{
if (edit2.Text='admin') and (edit1.Text='123456') then
showmessage('登陆成功!')
}
str:=Edit2.Text;
results:=ADOTable1.Lookup('LoadName',edit2.Text,'LoadPassword');
//showmessage(BoolToStr(results=edit1.Text,true));
if edit2.Text='' then
begin
Application.MessageBox('用户名不能为空!','提示',mb_ok);
edit2.SetFocus;
end
else
if not ADOTable1.Locate('LoadName',str,[loCaseInsensitive]) then
begin
Application.MessageBox('用户名不存在!','提示',mb_ok);
edit2.Text:='';
edit1.Text:='';
edit2.SetFocus;
end
else
if edit1.Text='' then
Application.MessageBox('密码不能为空!','提示',mb_ok)
else
if (results=edit1.Text) then //重建数据表才验证成功
begin
//showmessage('登陆成功!')
masterform.show;
end
else
begin
time:=time+1;
if time<5 then
begin
showmessage('密码错误,请重新输入!');
edit1.Text:='';
//edit2.Text:='';
edit1.SetFocus; //焦点重新回到edit2
end
else
begin
messageDlg('对不起,密码输入错误达到5次!请退出。',mtInformation,[mbok],0);
application.Terminate;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close; //关闭登陆窗口
end;
end.
-----------------------------------------------------------------------
今天解决了两个问题,完成了目标。Tomorrow,Go on!
------------For my love.
————————————————
版权声明:本文为CSDN博主「Deen12520」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/dingding_12345/article/details/47133121