您的位置:首页 > 编程语言 > Delphi

delphi随机输入验证码

2009-12-26 17:47 633 查看
输入验证码 一个文本框 24字母随机出4个字母 然后用户

输入所随机出的字母 输入正确 进入界面。。错误又随机下。。。
*/
unit Unit1;

interface

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

type
TForm1 = class(TForm)
lbl1: TLabel;
Edit1: TEdit;
btn1: TButton;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
function ShowRandom:string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
i,j:Integer;
c:Char;
begin
lbl1.Caption:=''; //这个是标签
for j:=0 to 3 do //随机生成4个a到z的字符串
begin
i:=Random(24);
c:=chr(ord('a') + i);
lbl1.Caption:=lbl1.Caption + c;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
if edit1.Text=lbl1.Caption then //成功
ShowMessage('0k')
else
ShowMessage('error');
end;

function ShowRandom:string;
var
i,j:Integer;
c:Char;
begin
Result:='';
for j:=0 to 3 do //随机生成4个a到z的字符串
begin
Randomize;
i:=Random(24);
c:=chr(ord('a') + i);
Result:=Result + c;
end;
end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐