如何实现“添加用户”功能,急求代码?(50分)

  • 主题发起人 主题发起人 jixiangshilin
  • 开始时间 开始时间
J

jixiangshilin

Unregistered / Unconfirmed
GUEST, unregistred user!
本人初学delphi,想请教各位大侠如何实现“添加用户”功能?
 
能不能说具体点?要求?实现什么样的功能?
 
我用的后台是sql2000,用户表名是user-inf,该功能是在“添加用户”窗口中实现的,是将用户输入的新的用户名和密码添加到我的数据库里,当用户输入的密码和确认密码不一致时,系统能自动提示错误信息~<br>它的界面如下<br>&nbsp; 用户名 edit<br>&nbsp; 密码 &nbsp;edit<br>&nbsp; 确认密码 edit<br>&nbsp; 确定 取消<br><br>谢谢大侠的帮忙!
 
为楼主的自学能力<br>晕一个<br>哎~~~
 
if edit2.Text&lt;&gt;edit3.Text then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('两次输入的密码不一至!');<br>&nbsp; &nbsp; edit2.Clear;<br>&nbsp; &nbsp; edit3.Clear;<br>&nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; if edit2.Text='' &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;showmessage('密码不能为空!');<br><br>&nbsp; exit;<br>&nbsp; if edit1.Text='' &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;showmessage('用户名不能为空!');<br><br>&nbsp; exit;<br><br>&nbsp; end<br>&nbsp; else<br>adotable1.close;<br>adotable1.tablename:='user-inf';<br>adotable1.Open;<br>&nbsp;adotable1.Append;<br>&nbsp; &nbsp; &nbsp; adotable1.Fields[1].AsString:=edit1.text;<br>&nbsp; &nbsp; &nbsp; &nbsp;adotable1.Fields[2].AsString:=edit2.text;<br>showmessage('用户添加成功!');
 
if edit2.Text&lt;&gt;edit3.Text then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('两次输入的密码不一至!');<br>&nbsp; &nbsp; edit2.Clear;<br>&nbsp; &nbsp; edit3.Clear;<br>&nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; if edit2.Text='' &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;showmessage('密码不能为空!');<br><br>&nbsp; exit;<br>&nbsp; if edit1.Text='' &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;showmessage('用户名不能为空!');<br><br>&nbsp; exit;<br><br>&nbsp; end<br>&nbsp; else<br>adotable1.close;<br>adotable1.tablename:='user-inf';<br>adotable1.Open;<br>&nbsp;adotable1.Append;<br>&nbsp; &nbsp; &nbsp; adotable1.Fields[1].AsString:=edit1.text;<br>&nbsp; &nbsp; &nbsp; &nbsp;adotable1.Fields[2].AsString:=edit2.text;<br>&nbsp; adotable1.post;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adotable1.close;<br>showmessage('用户添加成功!');<br><br><br>不好意思,呵呵,忘记了,
 
呵呵~<br>我再调试一下~
 
调试出错,我的程序如下:<br>procedure TAddUserFrm.Button2Click(Sender: TObject);<br>begin<br>&nbsp; close;<br>end;<br><br>procedure TAddUserFrm.Button1Click(Sender: TObject);<br>begin<br>if Edit2.Text&lt;&gt;Edit3.Text then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('两次输入的密码不一至!');<br>&nbsp; &nbsp; Edit2.Clear;<br>&nbsp; &nbsp; Edit3.Clear;<br>&nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; if Edit2.Text='' &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;showmessage('密码不能为空!');<br><br>&nbsp; exit;<br>&nbsp; if Edit1.Text='' &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;showmessage('用户名不能为空!');<br><br>&nbsp; exit;<br><br>&nbsp; end<br>&nbsp; else<br>ADOTable1.close;<br>ADOTable1.tablename:='user_inf';<br>ADOTable1.Open;<br>&nbsp;ADOTable1.Append;<br>&nbsp; &nbsp; &nbsp; ADOTable1.Fields[1].AsString:=Edit1.text;<br>&nbsp; &nbsp; &nbsp; &nbsp;ADOTable1.Fields[2].AsString:=Edit2.text;<br>&nbsp; ADOTable1.post;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ADOTable1.close;<br>showmessage('用户添加成功!');<br><br>end;<br>end;<br><br>错误说明:<br>[错误] AddUser.pas(64): Undeclared identifier: 'ADOTable1'<br>[错误] AddUser.pas(65): Missing operator or semicolon<br>[错误] AddUser.pas(66): Missing operator or semicolon<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .(67)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<br>[错误] AddUser.pas(71): Missing operator or semicolon<br>[致命错误] TSGL.dpr(17): Could not compile used unit 'AddUser.pas'<br><br>朋友,针对adotable未声明,如何声明啊~
 
对了,ADOTable1我放到DataModuleADO中去了~
 
看上去是什么也不懂,连最基础的都不懂。
 
adotable1有没有连接到数据库啊?
 
已经连好了,是不是还需在adotable1前加DataModuleADO前缀啊~<br>例如DataModuleADO.ADOTable1?
 
是的,但你要在单元的USER中引用DataModuleADO
 
to白河愁<br>老兄,你很懂吗?不要在一旁说风凉话啊!行动一下~<br>&nbsp; &nbsp; &nbsp;是骡子是马,拉出来溜溜!<br>毕竟我是初学者吗?我这里多混几天,说不定还会。。。。。<br>反正分给xqzhle是定了,看人家态度~当当的!<br>&nbsp; xqzhle谢谢了!
 
太感谢了~
 
引用了,还是不行~<br>呵呵~回头见!
 
行了,谢谢
 
不客气,一起学习一起进步!
 
后退
顶部