当前位置:首页 > 代码 > 正文

delphi登陆界面代码(delphi设计登录界面)

admin 发布:2022-12-19 15:23 148


本篇文章给大家谈谈delphi登陆界面代码,以及delphi设计登录界面对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

delphi 登陆 代码

procedure TForm1.Button1Click(Sender: TObject);

begin

{

if(trim(Edit1.Text)='')and(trim(Edit2.Text)='') then

Application.Messagebox('必须输入用户名和密码','提示',64)

else if(trim(Edit1.Text)'')and(trim(Edit2.Text)='') then

Application.Messagebox('请输入密码','提示',64)

else if(trim(Edit1.Text)='')and(trim(Edit2.Text)'') then

Application.Messagebox('请输入用户名','提示',64)

else

} //这些代码不要了,太繁琐!改成下面的。

if(trim(Edit1.Text)='') or (trim(Edit2.Text)='') then

begin

Application.Messagebox('必须输入用户名和密码','提示',64);

Exit;

end

else

//你的代码太啰唆了,改成这样好些。

begin

u:=Edit1.Text;

p:=Edit2.Text;

adoquery1.Close;

{adoquery1.SQL.Clear;

adoquery1.SQL.Add('select * from user where username=:u');}

adoquery1.SQL.Text := 'select * from user where username=''' + u + ''''; { 这里要特别注意,你的错误就出在这里,你定义了参数:u却没有给参数赋值,而我直接把u代进了SQL字符串。如果你还是想使用参数的话,应该给参数赋值,就像这样:ADOQuery1.Parameters.ParamByName('u').Value := u;}

adoquery1.Open;

adoquery1.Active:=true;

if adoquery1.FieldByName('password').AsString=p then

begin

adoquery1.Close;

form2.Show;

end

else

begin

adoquery1.Close;

Application.Messagebox('请输入正确的用户名和密码','提示',64);

end;

end;

end;

用delphi编写登录代码

begin

with adoquery1 do

begin

close;

sql.Clear;

sql.Add('select * from users');

SQL.Add('where name='''+edit1.Text+''' ');

Open;

end;

if adoquery1.RecordCount=0 then

begin

application.MessageBox('帐户名不正确','提示信息',mb_ok+mb_iconinformation);

edit1.SetFocus;

exit; //用户名是否存在

end

else

begin

with adoquery2 do

begin

close;

sql.Clear;

sql.Add('select * from users where name='''+edit1.Text+''' and pass='''+edit2.Text+'''');

open; //用户名存在情况下查看密码是否正确

end;

if adoquery2.RecordCount=0 then

begin

application.MessageBox('密码不正确','提示信息',mb_ok+mb_iconinformation);

edit2.SetFocus;

exit;

end

else

begin

Edit1.Clear;

Edit2.Clear;

login.Hide;

main.ShowModal;

end;

end;

求用DELPHI 从登陆窗口到主窗口的代码。

首先要设置登录窗口先运行,然后双击登录窗口的确定按钮,编写按钮点击事件,在事件中验证密码,密码正确则显示主窗口mainform。

显示主窗口命令为mainform.show;同时关闭登录窗口formlogin.close;不明白的可以上网搜索delphi 登陆界面,或者Q我

如何用delphi做登陆界面 用户名和口令要链接到数据库的那种?

以下内容仅供参考

步骤:

1.新建一个窗体,在窗体中放置上图所示组建.

2.连接数据库.选中ADOQuery1组建,点击左侧ConnectionString属性右侧的省略号,在弹出对话框中点击Build,再在弹出框中选择Microsoft OLE DB Provider for SQL Sever,点击"下一步",在新弹出的窗口中选择"使用Windows NT 继承安全设置"(当然,如果你的SQL安装时有用户名和密码则选择下面那个),然后在服务器上数据库下拉框中选择你要连接的数据库,最后一路确定即可.其他选项暂时可不用管它.

3.写代码.双击"登陆",写如下代码

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

try

with adoquery1 do

begin

close;

sql.clear;

sql.add('select * from user_master where 用户名=:a and 密码=:b and 权限=:c');

parameters.ParamByName('a').Value:=trim(combobox1.Text);

parameters.ParamByName('b').Value:=trim(edit1.Text);

if combobox1.Text ='' then

begin

application.MessageBox('请输入用户名','提示信息',64);

combobox1.SetFocus;

exit;

end;

if edit1.Text ='' then

begin

application.MessageBox('请输入密码','提示信息',64);

edit1.SetFocus;

exit;

end;

if radiobutton1.Checked=true then

begin

Quanxian:='1';

end;

if radiobutton2.Checked=true then

begin

Quanxian:='0';

end;

parameters.ParamByName('c').Value:=trim(quanxian);

open;

end;

if adoquery1.RecordCount0 then

begin

Username:=combobox1.Text;

Password:=edit1.Text;

application.MessageBox('登陆成功','提示信息',64);

form2.show;

self.Hide;

end

else

application.MessageBox('输入的用户名或密码错误','提示信息',64);

except

application.MessageBox('登陆失败','提示信息',64);

end;

end;

4.为了让用户在第一次使用管理系统时数据库文件可自动附加到SQL服务器中,可双击窗体空白部分,加入一下代码:

procedure TForm1.FormCreate(Sender: TObject);

var

ADOCommand:TADOCommand;

s,DataPath : string;

begin

adoConnection1:=TADOConnection.Create(nil);

adoConnection1.ConnectionString:='Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=library';

adoConnection1.LoginPrompt:=false;

try

adoConnection1.Connected:=true;

except

ADOCommand:=TADOCommand.Create(nil);

ADOCommand.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False';

DataPath:=ExtractFilePath(Application.ExeName) ;

s:='EXEC sp_attach_db @dbname = N'+char(39)+'library'+char(39)+','+

'@filename1 = N'+char(39)+DataPath+'library_Data.MDF'+char(39)+

','+'@filename2 = N'+char(39)+DataPath+'library_Log.LDF'+char(39);

ADOCommand.CommandText := s;

ADOCommand.Execute();

end;

end;

Delphi登陆代码

这是我的代码,你看下:

begin

with adoquery1 do

begin

close;

sql.Clear;

sql.add('select * from login where username='''+combobox1.text+''' and password='''+edit1.Text+'''');

open;

if(recordcount=0) then begin

showmessage('用户名或密码错误,请重新输入!');

edit1.Clear;

end

else begin

showmessage('登陆成功!');

form1.Hide;

FORM2.Show;

end;

end;

end;

关于delphi登陆界面代码和delphi设计登录界面的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/10201.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载