⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 本光盘是《Delphi 7应用教程》一书的配套光盘
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if ord(key)=13 then //如果是回车键
      if  edit1.text<>'123456'  then//如果账号不正确
          begin
             ShowMessage('账号有错误,请重新输入');//显示提示信息
             edit1.text:='';
             edit1.setFocus;
          end
      else
         Edit2.SetFocus //把焦点移至Edit2,以便输入密码
  else
    if (key<'0') or (key>'9') then//如果输入的不是数字
       begin
            Showmessage('账号必须为数字'); //显示提示信息
            key:=#0; //清除输入的字符
       end;
 end;

procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
  if ord(key)=13 then  //如果是回车键
    if edit2.text='Pass'  then //如果密码正确
       begin
          ShowMessage('欢迎你使用本系统!');//进入系统提示
          Form1.Close ; //关闭窗体
       end
    else  //密码输入不正确
       begin
          ShowMessage('密码错误,请重新输入!'); //提示密码错
          Edit2.text:='';
          edit2.SetFocus ;
       end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -