我想只查一个字段,但发现出错,如查两个字段则没问题了,不知啥?代码如下
      arry1[0]:=trim(edit1.Text) ;
      arry1[1]:=trim(edit2.Text) ;
      arry1[2]:=trim(edit3.Text) ;
    with DataModule8.ADOTable1zhzl do
     begin
      if (length(edit1.text)<>0 )then
      begin
        if (locate('acno;name',vararrayof(arry1),[loPartialKey])) then //如将 ;name去掉查则出错
          delete
         else
          showmessage('该记录不存在');
       end
上面的如这样写则错了,错哪?  if (locate('acno',vararrayof(arry1),[loPartialKey])) then 

解决方案 »

  1.   

    if (locate('acno',vararrayof([trim(edit1.Text)]),[loPartialKey])) then 
      

  2.   

    if Locate('acno',vararrayof(arry1),[loCaseInsensitive, loPartialKey])
      

  3.   

    一个不能使用这样的Locate方法,应该使用:
    if Locate('acno', Trim(Edit1.Text), [loPartialKey]) then 
      .....
      

  4.   

    if (locate('acno',vararrayof(arry1),[loPartialKey])) then你这个当然有错, 前面 acno 是一个参数,
    而后面arry1 它是三个参数啊。楼上的几种方式都行。
      

  5.   


    procedure TfrmMain.btnLocateClick(Sender: TObject);
    var
      sFields : String;
    begin
        sFields := GetSerchFields;
        dmSearchData.sqlcdsTest.Locate(sFields, GetSearchValues,[loCaseInsensitive, loPartialKey]);
    end;function TfrmMain.GetSearchValues : Variant;
    var
      iCount : Integer;
      sCond : String;
    begin
      Result := VarArrayCreate([0, Self.clbConditions.Items.Count - 1],varVariant);
      for iCount := 0 to Self.clbConditions.Items.Count - 1 do
      begin
        sCond := Self.clbConditions.Items[iCount];
        Result[iCount] := GetSearchValue(sCond);
      end;
    end;function TfrmMain.GetSearchFields: String;
    var
      iCount : Integer;
      sCond : String;
    begin
      Result := '';
      for iCount := 0 to Self.clbConditions.Items.Count - 1 do
      begin
        sCond := Self.clbConditions.Items[iCount];
        Result := Result + GetSearchField(sCond) + ';';
      end;
      Delete(Result, Length(Result), 1);
    end;