zoukankan      html  css  js  c++  java
  • Delphi Lookup函数-根据条件查找数据

    Delphi Lookup函数-根据条件查找数据

    TCustomClientDataSet、TCustomADODataSet 均有

    函数原型:

    function Lookup(const KeyFields: string; const KeyValues: Variant;
      const ResultFields: string): Variant;
    begin
      Result := Null;
      if LocateRecord(KeyFields, KeyValues, [], False) then
      begin
        SetTempState(dsCalcFields);
        try
          CalculateFields(TempBuffer);
          Result := FieldValues[ResultFields];
        finally
          RestoreState(dsBrowse);
        end;
      end;
    end;
    

    CalculateFields

    procedure TDataSet.CalculateFields(Buffer: PChar);
    var
      I: Integer;
    begin
      FCalcBuffer := Buffer;
      if (State <> dsInternalCalc) and (IsUniDirectional = False) then
      begin
        ClearCalcFields(CalcBuffer);
        for I := 0 to FFields.Count - 1 do
          with FFields[I] do
            if FieldKind = fkLookup then CalcLookupValue;
      end;
      DoOnCalcFields;
    end;
    

      

    使用示例:

    //单字段

    var 
      sName:Variant;
    begin
    //根据ID,返回名称
      sName:=ADOQuery1.Lookup('id','22','name');
      if VarType(sName) <> varNull then
      begin
        ShowMessage(IntToStr(sName));
      end;
    end; 

    //多字段

    var 
      sArry:Variant;
    begin
    //根据ID、名称,搜索返回 标题、日期
      sArry:=ADOQuery1.Lookup('id;name',VarArrayOf([22,'test']),'title;date');
      if VarType(v) <> varNull then
      begin
        ShowMessage(sArry[0]+inttostr(sArry[1]));
      end;
    end;
    

      

    创建时间:2021.01.29  更新时间:

    博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你所有帮助,谢谢!
  • 相关阅读:
    POJ_2387_最短路
    HDU_3172_带权并查集
    Python_多线程1(创建线程,简单线程同步)
    POJ_3013_最短路
    codeforces_725C_字符串
    python_文件io
    codeforces_731D_(前缀和)(树状数组)
    codeforces_738D
    java反射机制
    struts2入门
  • 原文地址:https://www.cnblogs.com/guorongtao/p/14343165.html
Copyright © 2011-2022 走看看