我想做一个修改口令的窗口,但是程序有很多问题,小弟惭愧哦,请各位大虾帮忙!
下面是程序还有错误,请问怎么改???
unit xiugaikouling;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DB, ADODB, DBTables;type
  TF_xiugaikouling = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Query1: TQuery;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  F_xiugaikouling: TF_xiugaikouling;implementation{$R *.dfm}procedure TF_xiugaikouling.BitBtn1Click(Sender: TObject);//取消按钮
begin
  close;
end;procedure TF_xiugaikouling.BitBtn2Click(Sender: TObject); //确定按钮
begin
  if ((edit1.Text='')     //如果没有输入用户名
  or (edit3.Text<>edit4.Text)) then  //或两次输入的口令不一致
    begin
      showmessage('请输入用户名!');  //提示请输入用户名
      edit1.setfocus;
      end
      else if edit3.text<>edit4.text then
      showmessage('新口令确认不一致!');
      edit1.setfocus;
    end;
      end
      else
      begin
      Query1.close;
      Query1.sql.clear;
      Query1.sql.add('select rybh,mm from [user]');
      Query1.sql.add('rybh='+''''+trim(edit1.Text)+'''');
      Query1.sql.add('and mm='+''''+trim(edit2.text)+'''');
      Query1.open;
      if ((Query1.recordcount<>1) or                 //如果用户名
       (edit2.text<>Query1.fieldvalues['mm'])) then  //或密码不对
       begin
        showmessage('口令不对,请检查!');
        edit1.setfocus;
       end
       else
       begin
         Query1.edit;
         Query1.fieldvalues['mm']:=edit3.text;
         Query1.post;
            showmessage('更改口令成功');
         Query1.close;
         close;
       end;
      end;
  end;end;end.
[Error] xiugaikouling.pas(55): '.' expected but 'ELSE' found
[Error] xiugaikouling.pas(56): Identifier redeclared: 'Finalization'
[Error] xiugaikouling.pas(57): Undeclared identifier: 'Query1'
[Error] xiugaikouling.pas(57): '(' expected but ';' found
[Error] xiugaikouling.pas(58): Missing operator or semicolon
[Error] xiugaikouling.pas(59): Missing operator or semicolon
[Error] xiugaikouling.pas(60): Missing operator or semicolon
[Error] xiugaikouling.pas(60): Undeclared identifier: 'edit1'
[Error] xiugaikouling.pas(60): Incompatible types
[Warning] xiugaikouling.pas(63): Text after final 'END.' - ignored by compiler
[Fatal Error] Project1.dpr(75): Could not compile used unit 'xiugaikouling.pas'

解决方案 »

  1.   

    建议你写代码时,一定注意代码结构。
    begin
    end应同时输入后,再移到中间插入相关代码。首先,你先从代码本身检查,代码的关系没有理顺。
      

  2.   

    先注意你代码的书写格式,这样便于大家帮你检查,也有利于自己查错。
    建议你如果要使用begin 和 end 时。写完一个begin 马上在后面写一个end。然后再在中间插入你要写的代码。看你的程序错误都是比较简单的,自己慢慢调试跟踪,应该很快会通过。
      

  3.   

    你的代码很乱,Query1是一个查询控件,是只读的,不能修改里面的数据。要是修改数据必须和UpdateSQL联用。你先把这个问题解决一下吧。我把代码调整了一下:procedure TF_xiugaikouling.BitBtn2Click(Sender: TObject); //确定按钮
    begin
      if ((edit1.Text='') or (edit3.Text<>edit4.Text)) then begin //或两次输入的口令不一致
          showmessage('请输入用户名!');  //提示请输入用户名
          edit1.setfocus;
      end else if (edit3.text<>edit4.text) then begin
          showmessage('新口令确认不一致!');
          edit1.setfocus;
      end else begin
          Query1.close;
          Query1.sql.clear;
          Query1.sql.add('select rybh,mm from [user]');
          Query1.sql.add('rybh='+''''+trim(edit1.Text)+'''');
          Query1.sql.add('and mm='+''''+trim(edit2.text)+'''');
          Query1.open;      if ((Query1.recordcount<>1) or (edit2.text<>Query1.fieldvalues['mm'])) then begin //或不对
              showmessage('口令不对,请检查!');
              edit1.setfocus;
          end else begin
             Query1.edit;
             Query1.fieldvalues['mm']:=edit3.text;
             Query1.post;         Query1.close;         showmessage('更改口令成功');         close;
           end;
       end;
    end;end;
      

  4.   

    呵呵,你的 意思是不是修改用户口令!~~~uses db;
     With  Data_m.Table1  do
                 begin
                          try
                                    active :=true;
                                    a_flag :=Locate ('pass_name;pass_wd',VarArrayof([Edit4.Text,Edit5.Text ]),[loCaseInsensitive]);
                                    if  (a_flag =false )
                                    then begin
                                                 key_values :=Lookup('pass_name',Edit4.Text ,'pass_wd');
                                                 if  (key_values <>Edit5.Text )
                                                 then begin
                                                            showmessage('用户名存在,但是您输入的密码错误');
                                                            exit;
                                                      end;
                                                 showmessage('用户名不存在,您可以注册该用户');
                                                 Edit4.Text :='';
                                                 Edit5.Text :='';
                                                 Edit6.Text :='';
                                                 Edit7.Text :='';
                                                 exit;
                                         end
                                    else begin
                                                 try
                                                          Edit;
                                                          FieldByname('pass_wd').AsString :=Edit6.Text ;
                                                          Post;
                                                          Refresh;
                                                          showmessage('修改密码成功');
                                                          Edit4.Text :='';
                                                          Edit5.Text :='';
                                                          Edit6.Text :='';
                                                          Edit7.Text :='';
                                                 except
                                                         showmessage('error,&_&');
                                                 end;
                                         end;
                          finally
                                     close;
                          end;
                 end;
    end;思路:首先使用locate 方法来判断 用户名是否存在,
         然后使用lookup 方法判断输入的旧密码是否正确,
    之后才进行修改!~~~
      

  5.   

    给你一个现成的
    自己消化吧
    unit Unit_changepwd;interfaceuses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
      Buttons,dialogs, ExtCtrls, fcLabel, DB, ADODB, fcStatusBar, fcButton,
      fcImgBtn, fcShapeBtn, RzButton, RzLabel, Mask, RzEdit;type
      Tform_changepwd = class(TForm)
        Bevel1: TBevel;
        ADOQuery_login: TADOQuery;
        fcStatusBar1: TfcStatusBar;
        fcLabel4: TfcLabel;
        fcshapebtn1: TRzBitBtn;
        RzBitBtn1: TRzBitBtn;
        edit_username: TRzEdit;
        edit_password: TRzEdit;
        LabeledEdit1: TRzEdit;
        LabeledEdit2: TRzEdit;
        RzLabel1: TRzLabel;
        RzLabel2: TRzLabel;
        RzLabel3: TRzLabel;
        RzLabel4: TRzLabel;
        procedure ttyClick(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure RzBitBtn1Click(Sender: TObject);
        procedure fcshapebtn1Click(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      form_changepwd: Tform_changepwd;implementationuses Unit_main, Unit_global;{$R *.dfm}procedure Tform_changepwd.ttyClick(Sender: TObject);
    var
      sShowStr: string;
    begin
      if edit_username.Text='' then
      begin
        edit_username.SetFocus ;
        exit;
      end;
      if edit_password.Text='' then
      begin
        edit_password.SetFocus ;
        exit;
      end;
      with ADOQuery_login  do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from tc_user where user_name='+ '''' +edit_username.Text +'''') ;
        Open;
        First;
      end;  if(adoquery_login.Recordset.RecordCount=0) then
      begin
     //   Case Unit_Global.Language_id of
     //   0:
          sShowStr := '用户名不存在!';
    //    1:
    //      sShowStr := 'UserName does not Exist';
    //    else
    //    end;
        showmessage(sShowStr);
        edit_username.SetFocus ;
        edit_username.SelectAll ;
        exit;
      end
      else
      begin
       if (edit_password.Text=adoquery_login.FieldByName('password').AsString) then
       begin
          adoquery_login.Edit;
          adoquery_login.FieldByName('password').AsString:=labelededit1.Text ;
          adoquery_login.UpdateRecord;//      Case Unit_Global.Language_id of
    //      0:
            sShowStr := '密码已经更改';
    //      1:
    //        sShowStr := 'Password has changed';
    //      else
    //      end;
          showmessage(sShowStr);
          close;
       end
       else
       begin
    //      Case Unit_Global.Language_id of
    //      0:
            sShowStr := '密码不正确!';
    //      1:
    //        sShowStr := 'Password is not correct';
    //      else
    //      end;
          showmessage(sShowStr);
          edit_username.SetFocus ;
          edit_username.SelectAll ;
          exit;
       end;  end;end;procedure Tform_changepwd.FormClose(Sender: TObject;
      var Action: TCloseAction);
      var
      aaa:tform_changepwd;
    begin
    aaa:=form_changepwd;
    form_changepwd:=nil;
    aaa.Release ;end;procedure Tform_changepwd.RzBitBtn1Click(Sender: TObject);
    begin
    close;
    end;procedure Tform_changepwd.fcshapebtn1Click(Sender: TObject);begin
      if edit_username.Text='' then
      begin
        edit_username.SetFocus ;
        exit;
      end;  if (labelededit1.Text<>labelededit2.Text) then
      begin
    //        case unit_global.language_id of
    //        0: //中文
    //        begin
               application.MessageBox('你输入的密码不匹配,请在两个文本框内输入新密码!','错误',mb_ok+mb_iconerror);
    //        end;
    //        else
               messagedlg('Password does not match, please input correct password.',mterror ,[mbok],0);
    //        end;
        labelededit1.Clear ;
        labelededit2.Clear ;
        edit_password.Clear ;
        edit_password.SetFocus ;
        exit;
      end;
      with ADOQuery_login  do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from tc_user where user_name='+ '''' +edit_username.Text +'''') ;
        Open;
        First;
      end;  if(adoquery_login.Recordset.RecordCount=0) then
      begin
    //        case unit_global.language_id of
    //        0: //中文
    //        begin
               application.MessageBox('用户名不存在!','错误',mb_ok+mb_iconerror);
    //        end;
    //        else
    //           messagedlg('UserName does not Exist!',mterror ,[mbok],0);
    //        end;
        edit_username.SetFocus ;
        edit_username.SelectAll ;
        exit;
      end
      else
      begin
       if (edit_password.Text=adoquery_login.FieldByName('password').AsString) then
       begin
          adoquery_login.Edit;
          adoquery_login.FieldByName('password').AsString:=labelededit1.Text ;
          adoquery_login.post ;
    //        case unit_global.language_id of
    //        0: //中文
    //        begin
               application.MessageBox('密码已经更改!','提示',mb_ok+mb_iconinformation);
    //        end;
    //        else
    //           messagedlg('Password has changed!',mtinformation ,[mbok],0);
    //        end;
          close;
       end
       else
       begin
    //        case unit_global.language_id of
    //        0: //中文
    //        begin
               application.MessageBox('密码不正确!','错误',mb_ok+mb_iconerror);
    //        end;
    //        else
               messagedlg('Password is not correct!',mterror ,[mbok],0);
    //        end;
         labelededit1.Clear ;
         labelededit2.Clear ;
         edit_password.Clear ;
         edit_password.SetFocus ;
         exit;
       end;
      end;
    end;procedure Tform_changepwd.FormShow(Sender: TObject);
    begin
    end;end.
      

  6.   

    else if edit3.text<>edit4.text then
          showmessage('新口令确认不一致!');
          edit1.setfocus;
        end;少一个begin吧?哎呀,后面太多了,我也不想改了,自己多看看帮助和pascle的语法吧!
      

  7.   

    说实话 真的好乱  程序是一行行执行的 所以注意结构很重要 
    QUERY一般情况下返回的数据集都是只读的 只是改密码的话 用TABLE不好吗 或者换ADO吧:)
      

  8.   

    procedure TF_xiugaikouling.BitBtn2Click(Sender: TObject); //确定按钮
    begin
      if ((edit1.Text='')     //如果没有输入用户名
      or (edit3.Text<>edit4.Text)) then  //或两次输入的口令不一致
      begin
          showmessage('请输入用户名!');  //提示请输入用户名
          edit1.setfocus;
          exit;
      end
      else 
      if edit3.text<>edit4.text then
          showmessage('新口令确认不一致!');
          edit1.setfocus;
          exit;
      end;
      Query1.close;
      Query1.sql.clear;
      Query1.sql.add('select rybh,mm from [user]');
      Query1.sql.add('rybh='+''''+trim(edit1.Text)+'''');
      Query1.sql.add('and mm='+''''+trim(edit2.text)+'''');
      Query1.open;
      if ((Query1.recordcount<>1) or                 //如果用户名
           (edit2.text<>Query1.fieldvalues['mm'])) then  //或密码不对
      begin
            showmessage('口令不对,请检查!');
            edit1.setfocus;
      end
      else
      begin
             Query1.edit;
             Query1.fieldvalues['mm']:=edit3.text;
             Query1.post;
                showmessage('更改口令成功');
             Query1.close;
             close;
      end;
    end;
    你将上面的代替你的程序试试吧.;)
      

  9.   

    Query可以写操作啊,只要将RequestLive改成True行了