Locate usage of Delphi TQuery

Help in the interpretation

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

KeyFields: is a string containing a semicolon-delimited list of field names on which to search.

KeyValues: IS A the Variant Array containing at The values to match in at The Key Fields.

TLocateOptions IS A the SET that OPTIONALLY specifies Additional Search Latitude the when Searching ON String Fields.

About LocateOptions
of the type
  TLocateOption = (loCaseInsensitive, loPartialKey);
  TLocateOptions = setof TLocateOption;

loCaseInsensitive Key fields and key values are matched without regard to case.// ignore case
loPartialKey Key values can include only part of the matching key field value; // only a partial match, matching scratch 
{Furthermore, if there are no string type KeyFields or LocateOptions = [], the function will ignore this}

read so many, in the end Locate what it is doing? See

Searches the dataset for a specified record and makes that record the current record.

Call Locate to search a dataset for a specific record and position the cursor on it.

Obviously Locate distinct from worrying too much, but do not equate oh. Locate mainly locate the information you want in the Open has been out of the data set.

Well, read the Help text inside the crowded E, giddy, dizzy is not because it has been bad science "in British history (English)" it? E-text how I look at all this feeling, or the Chinese Chinese character looks kindly comfortable, ^ _ ^, pull away, and get down to business, read the theoretical things, we have to practice it.

Things always easy to do from the start, the writing process is no exception. Let's look at the usage of a single column.

strCode: = 'Abc'
Tquery1.Locate ( 'code', strCode, [loCaseInsensitive])

so TQuery, will position the cursor to the code field equal Abc (abc, aBc, abC, ....) of the recording.

However, since we used to look in most cases we are to fuzzy query, so this is not the method we use, we are just a little change under Option OK.
Tquery1.Locate ( 'code', strcode, [loPartialKey])

thus found is this result code "includes" (rather than starting from scratch to match the real included) Abc (Abcddfe ..., ....)

course two can be used simultaneously



with CustTable do
  Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P', '408-431-1000']), [loPartialKey]);

  1, with ";" segmenting the plurality of field names with VarArrayOf () to pass a plurality of targeting values.
  2, and the database field must be exactly the same, even if you are accustomed to using spaces too. While making the program look with clear points, but will not do it yourself Locate Trim, so it is also the space as part of field names.
  3, since the use of targeting values Variants, I do not know the positioning of the string limited.
  4, the results of the query multiple columns, be sure to all fields and all the operators can, as long as there is a column does not comply, it will return False.
  The value is preferably not empty targeting, will traverse from start to finish, the speed of impact.

 Ok, usage of Locate's stop here, write a small example as a summary.

  LocateSuccess: Boolean;
  SearchOptions: TLocateOptions;
  SearchOptions := [loCasesensitive,loPartialKey];
  LocateSuccess := CustTable.Locate(StrField,StrLocate, SearchOptions);

Guess you like

Origin www.cnblogs.com/jijm123/p/10939579.html