在Delphi中,Locate和Lookup封装了原生ADO的Find查找方法。提供以下函数形式使用

 

 1 function TCustomADODataSet.Locate(const KeyFields: string;
 2   const KeyValues: Variant; Options: TLocateOptions): Boolean;
 3 begin
 4   DoBeforeScroll;
 5   Result := LocateRecord(KeyFields, KeyValues, Options, True);
 6   if Result then
 7   begin
 8     Resync([rmExact, rmCenter]);
 9     DoAfterScroll;
10   end;
11 end;
12 
13 function TCustomADODataSet.Lookup(const KeyFields: stringconst KeyValues: Variant;
14   const ResultFields: string): Variant;
15 begin
16   Result := Null;
17   if LocateRecord(KeyFields, KeyValues, [], False) then
18   begin
19     SetTempState(dsCalcFields);
20     try
21       CalculateFields(TempBuffer);
22       Result := FieldValues[ResultFields];
23     finally
24       RestoreState(dsBrowse);
25     end;
26   end;
27 end;

使用时 loCaseInsensitive代表区分大小写,loPartialKe代表部分匹配。

当多个字段时用“;”隔开字段名,字段值是变体数组形式,可以用VarArrayof()生成。

例如:ds1.Locate('name', 'k1727', [loCaseInsensitive, loPartialKe]);

相关文章:

  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-09-09
  • 2021-12-05
猜你喜欢
  • 2021-04-10
  • 2021-07-17
  • 2022-01-07
  • 2021-09-01
  • 2022-01-10
  • 2022-01-07
  • 2021-12-18
相关资源
相似解决方案