Delphi 7学习第六天-简单登陆界面的实现

第一次尝试一天码两篇文章,分享知识的过程是快乐的。

上午试着去做一个简单的登陆界面,基本上算完成了。

登录名和密码要与数据表中匹配,才能登陆成功。

这里采用的是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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值