In Delphi, adotable uses the locate method to quickly locate records

Source: Internet
Author: User

Locate can position the current cursor on a qualified record. The first parameter of locate is the condition field, and the second parameter is the condition.
Value. The third parameter indicates whether the search is case-sensitive and partially matched. You can set multiple conditions for locate as follows:
Table1.locate ('Company; contact; phone', vararrayof (['sight diver ', 'P', '2017-431-1000']), [lopartialkey]);

 

Another example:

VaR <br/> locatesuccess: Boolean; <br/> searchoptions: tlocateoptions; <br/> vfield: variant; <br/> begin <br/> searchoptions: = [lopartialkey]; <br/> vfield: = vararraycreate ([2222], varolestr); <br/> vfield [0]: = '123 '; <br/> vfield [1]: = 'II 222 '; <br/> locatesuccess: = table1.locate ('A _ No; a_name', vfield, searchoptions ); <br/> If locatesuccess then <br/> label1.caption: = 'found' <br/> else <br/> label1.caption: = 'not found '; <br/> end;

 

Participate in the introduction of the third parameter:

Locaseinsensitive: case insensitive

Lopartialkey: whether to use the same local search method. At this time, as long as the Search Condition string is equal to the beginning of the column content, even if the length is not equal, it can still be determined to be equal. (It is like the xbase set exact off situation)

 

It is easier to understand using the following example. Assume that Table1 is:

Cu_no Cu_name
Amkb Wang Datong
Acjc Kingsichin
Bdfd Forest fire gold

 

If the stest is 'amkb ':
Table1.locate ('cu _ no', stest, [])
==> Of course, you can find

If stest is 'ac ':
Table1.locate ('cu _ no', stest, [])
==> Not found
Table1.locate ('cu _ no', stest, [lopartialkey])
==> Find the record 'acjc kingsichin.
Because the set contains the lopartialkey project, 'ac' is the same as 'acjc'
The first two characters, even if the length of the two characters is not equal, are also found.

If stest is 'ac ':
Table1.locate ('cu _ no', stest, [lopartialkey])
==> Cannot be found. Because it is case sensitive, 'ac' starts with 'acjc ',
It cannot be regarded as qualified.
Table1.locate ('cu _ no', stest, [locaseinsensitive, lopartialkey])
==> Find the acjc kingsichin record.
At this time, it is no longer case sensitive. Close information can be found.

In short, if the third index of locate () is an empty set, it indicates that the searched data must be in the same case and length as the data, that is, the data can be searched in the same way; locaseinsensitive (Case Insensitive) is added to the element in the set as needed ). lopartialkey (local equivalent) provides an elastic approach to search for approximate data.

What if the condition is only Chinese characters? Locaseinsensitive makes no sense. Addition and addition do not affect the results. Local Search is still valid.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.