Difference between revisions of "locate"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Translate}} Unit: FreePascal, unit '''db''' <syntaxhighlight> function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; ov...")
 
(Added example, layout, tip to use sql)
Line 1: Line 1:
 
{{Translate}}
 
{{Translate}}
  
 +
==Definition==
 
Unit: FreePascal, unit '''db'''
 
Unit: FreePascal, unit '''db'''
  
 
<syntaxhighlight>
 
<syntaxhighlight>
 
     function  Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;
 
     function  Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;
//TDBF
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Official documentation: none
 
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.
 
'''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.
  
Line 22: Line 23:
 
{{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 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.}}
  
== See also ==
+
==Example==
 +
<syntaxhighlight>
 +
// Using a TDBF dataset
 +
uses dbf, db
 +
...
 +
// Look for 'di Angelo', 'Di Angelo' etc in a field called
 +
// LASTNAME
 +
if MyDBF.Locate('LASTNAME','di Angelo',[loCaseInsensitive])then
 +
  writeln('Found record.');
 +
</syntaxhighlight>
 +
 
 +
==See also==
 
* [http://delphi.about.com/od/database/l/aa052901a.htm] Description of how to use locate with Delphi
 
* [http://delphi.about.com/od/database/l/aa052901a.htm] Description of how to use locate with Delphi
  
 
[[category:FPC]]
 
[[category:FPC]]
 
[[category:Databases]]
 
[[category:Databases]]

Revision as of 10:22, 15 December 2012

Template:Translate

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)
Light bulb  Note: Locate is only implemented in non-unidirectional datasets, i.e. you must be able to move back and forwards through the dataset.
Light bulb  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.

Example

// Using a TDBF dataset
uses dbf, db
...
// Look for 'di Angelo', 'Di Angelo' etc in a field called
// LASTNAME
if MyDBF.Locate('LASTNAME','di Angelo',[loCaseInsensitive])then
  writeln('Found record.');

See also

  • [1] Description of how to use locate with Delphi