function TfrmMain.CheckQuanXian(const xPhone:String; const xBillNO:String ):Boolean;      //检查用户是否有权限审批此笔单据
var
  sSQL:string;
  var yUserID:String; var yShenpYJ:String; var yPhone:String;
begin 
  result:= true;
  sSQL:= 'select userid,[审批单号],[用户名],[短信开启],[审批意见],[审批意见nm],[审批状态] from v_shenp where [审批单号]='''+xBillNO+'''';
  with frmDM.qryDSelect do
  begin 
    Close; 
    SQL.Clear;
    SQL.Append(sSQL);
      Open;
      if RecordCount > 0 then
          begin
              //yUserID    := FieldByName('userid').AsString;  //用户ID
              //yShenpYJ    := FieldByName('[审批意见nm]').AsString;  //审批意见nm
              if FieldByName('审批意见nm').IsNull then
                 yUserID    := FieldByName('userid').AsString;
                 sSQL:= 'select id,用户名,短信开启,成功回复,转发权,SMSID,同意结果,手机号码  from t_userlogin where id='''+yUserID+'''';              else
                 yUserID    := FieldByName('userid').AsString;  //用户ID
                 yShenpYJ    := FieldByName('审批意见nm').AsString;  //审批意见nm
                 sSQL:= 'select 用户名,手机号码 from t_userlogin where id=(select 通知领导 from canshu where id ='''+yShenpYJ+''')'              with frmDM.qryDSelect do
              begin
                Close;
                SQL.Clear;
                SQL.Append(sSQL);
                  Open;
                   yPhone    := FieldByName('手机号码').AsString;
              end;
          end
      else
          SendResultSms(xPhone,'无相应的审批信息+++!');
  end;
end;上面的这段语句,编译的时侯报了很多错,求高手帮忙查一下错误如何修改,另外
条件判断的这段
             if FieldByName('审批意见nm').IsNull then
                 yUserID    := FieldByName('userid').AsString;
                 sSQL:= 'select id,用户名,短信开启,成功回复,转发权,SMSID,同意结果,手机号码  from t_userlogin where id='''+yUserID+'''';              else
                 yUserID    := FieldByName('userid').AsString;  //用户ID
                 yShenpYJ    := FieldByName('审批意见nm').AsString;  //审批意见nm
                 sSQL:= 'select 用户名,手机号码 from t_userlogin where id=(select 通知领导 from canshu where id ='''+yShenpYJ+''')'              with frmDM.qryDSelect do
              begin
                Close;
                SQL.Clear;
                SQL.Append(sSQL);
                  Open;
                   yPhone    := FieldByName('手机号码').AsString;
              end;
这样写是否正确?

解决方案 »

  1.   

    首先指出你的 if then 后跟多条语句,怎么也不加begin end呀,这肯定会出错
      

  2.   

    这里加上begin和end
    if FieldByName('审批意见nm').IsNull then
    begin 
      ...
    end 
    else
    begin
      ...
    end;你两次OPEN frmDM.qryDSelect  你第一次的结果还要不要啊? 
      

  3.   

    通常这样可以使用procedure TForm1.Button1Click(Sender: TObject);
    var
      name:string;
    begin
      with Adoquery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Text:='select * from table where 1=1';
        Open;
        while not eof do  // 这里保证不检索空结果
        begin
          name:=FieldByName('name').AsString;
          Next;
        end;
      end;
    end;
      

  4.   


    function TfrmMain.CheckQuanXian(xPhone,xBillNO:String ):Boolean;      //检查用户是否有权限审批此笔单据
    var
      sSQL:string;
      yUserID:String;
      yShenpYJ:String;
      yPhone:String;
    begin
      result:= true;
      sSQL:= 'select userid,[审批单号],[用户名],[短信开启],[审批意见],[审批意见nm],[审批状态] from v_shenp where [审批单号]='''+xBillNO+'''';
      with frmDM.qryDSelect do
      begin
        Close;
        SQL.Clear;
        SQL.Add(sSQL);
        Open;
        if RecordCount > 0 then
        begin
          //yUserID    := FieldByName('userid').AsString;  //用户ID
          //yShenpYJ    := FieldByName('[审批意见nm]').AsString;  //审批意见nm
          if FieldByName('审批意见nm').IsNull then
          begin
             yUserID    := FieldByName('userid').AsString;
             sSQL:= 'select id,用户名,短信开启,成功回复,转发权,SMSID,同意结果,手机号码  from t_userlogin where id='''+yUserID+'''';
          end
          else
          begin
             yUserID    := FieldByName('userid').AsString;  //用户ID
             yShenpYJ    := FieldByName('审批意见nm').AsString;  //审批意见nm
             sSQL:= 'select 用户名,手机号码 from t_userlogin where id=(select 通知领导 from canshu where id ='''+yShenpYJ+''')'
          end;
          with frmDM.qryDSelect do
          begin
            Close;
            SQL.Clear;
            SQL.add(sSQL);
            Open;
            yPhone    := FieldByName('手机号码').AsString;
          end;
        end
        else
        begin
           result:=False;
           SendResultSms(xPhone,'无相应的审批信息+++!');
        end;
      end;
    end;
      

  5.   

    给你整理一下function TfrmMain.CheckQuanXian(const xPhone:String; const xBillNO:String ):Boolean;      //检查用户是否有权限审批此笔单据
    var
      sSQL:string;
      var yUserID:String; var yShenpYJ:String; var yPhone:String;
    begin
      result:= true;
      sSQL:= 'select userid,[审批单号],[用户名],[短信开启],[审批意见],[审批意见nm],[审批状态] from v_shenp where [审批单号]='''+xBillNO+'''';
      with frmDM.qryDSelect do
      begin
        Close; 
        SQL.Clear;
        SQL.Append(sSQL);
          Open;
          if RecordCount > 0 then
          begin
              //yUserID    := FieldByName('userid').AsString;  //用户ID
              //yShenpYJ    := FieldByName('[审批意见nm]').AsString;  //审批意见nm
              if FieldByName('审批意见nm').IsNull then
              begin
                 yUserID    := FieldByName('userid').AsString;
                 sSQL:= 'select id,用户名,短信开启,成功回复,转发权,SMSID,同意结果,手机号码  from t_userlogin where id='''+yUserID+'''';
              end
              else
              begin
                 yUserID    := FieldByName('userid').AsString;  //用户ID
                 yShenpYJ    := FieldByName('审批意见nm').AsString;  //审批意见nm
                 sSQL:= 'select 用户名,手机号码 from t_userlogin where id=(select 通知领导 from canshu where id ='''+yShenpYJ+''')'
              end;
              Close;
              SQL.Clear;
              SQL.Append(sSQL);
              Open;
              yPhone    := FieldByName('手机号码').AsString;
          end
          else
              SendResultSms(xPhone,'无相应的审批信息+++!');
      end;
    end;
      

  6.   

    错误原因可能就是因为你少了begin end~~
    用上面整理的试一下了~~