locate

locate

Contents [hide]
1 Definition
2 Description
3 Examples
4 See also

The article from http://wiki.freepascal.org/locate


Definition

Unit: FreePascal, unit db

function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;

Official documentation: none


Description

locate looks for a record in the dataset where the specified search values for the specified fields match. If found, the function returns true and the cursor position/current record moves to that record.
KeyFields can be a single field name or a semicolon-separated list of fields.
KeyValue can be a variant or a variant array and the number of items must match the number of fields specified in KeyFields.

Search options can be

  • loCaseInsensitive: ignore upper case/lower case differences when searching
  • loPartialKey: match partial finds (instead of the complete key). Note: this only works for string-type fields, not for number/date/currency etc fields where this option is ignored.

Note: Locate is only implemented in non-unidirectional datasets, i.e. you must be able to move back and forwards through the dataset.

Note: Locate and lookup act at low level inside a dataset to search for records. Often it is more efficient to filter/limit what gets into the dataset in the first place, e.g. using SQL WHERE clauses.


Examples

Using a TDBF dataset and looking for ‘di Angelo’, ‘Di Angelo’ etc in a field called LASTNAME:

uses dbf, db
...
if MyDBF.Locate('LASTNAME','di Angelo',[loCaseInsensitive])then
  writeln('Found record.');

Using multiple fields to find a record.
Note: you have to add Variants to the uses clause.

uses Variants;
..
procedure LocateMyRecord;
var
  aCityID, aCountryID: integer;
begin
  if Locate('city_id;country_id', VarArrayOf([aCityID, aCountryID]), []) then
  begin
    DoSomething;
  end;
end;

See also

[1] Description of how to use locate with Delphi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值