1
How to do a survey with Locate
with two or more fields simultaneously?
- What are the drawbacks of doing this?
1
How to do a survey with Locate
with two or more fields simultaneously?
3
The Locate
what I’m used to doing is in this format:
DataSetX.Locate('CODIGO;DATAVENCTO;COD_PRODUTO',VarArrayOf([QOperacoesCODIGO.AsInteger
,QOperacoesDATAVENCIMENTO.AsDateTime
,QOperacoesPRODUTO.AsInteger]), [])
The disadvantage of Locate
exists only when you own a DataSet
that was not loaded with FetchAll
, because, when running it it may be necessary that the Dataset recharges all data from the Table, increasing memory consumption.
A good alternative would be to use a ClientDataSet
that has data compression property, that way you would load this client with the data of the dataset and destroy it, leaving only the client with the data ready for search.
In a Client would use the FindKey
operation is the same, but much faster.
ClientDataSetX.FindKey([QOperacoesCODIGO.AsInteger
,QOperacoesDATAVENCIMENTO.AsDateTime
,QOperacoesPRODUTO.AsInteger])
Remember that for this you need to set an Index for the Client to work correctly, in the case of the example cited the Index would be by the fields CODE, DATE AND PRODUCT.
2
LOCATE - Declaration:
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; virtual;
This method allows the exact search of a record, for fields that are not part of the current index of the table represented by the component, and receives as parameters:
LoPartialKey
- indicates that the search will be approximated.This is an example of how to make the method Locate
with two fields I found in docwiki.embarcadero.com/Using_locate.
CustTable.IndexFieldNames := 'ID';
if CustTable.Locate('ID1';'ID1', VarArrayOf([´String1´,´String2´]), [])then
ShowMessage ('O cliente com ID = String1 e ID = String2 encontrado')
else
ShowMessage ('O cliente não encontrado') ;
In the docwiki.embarcadero.com has all description of the method and also found another method that searches with the fields that is the Extended Locating take a look at the method LocateEx
accepts field values or expressions.
Field Value:
if not CustTable.LocateEx('COMPANY', 'AMCO', [lxoCaseInsensitive]) then
ShowMessage('The customer from AMCO company is not found')
else
ShowMessage('Order is not found');
Expression:
if FDQuery1.LocateEx('Price >= 1000 and Price <= 2000', []) then
ShowMessage('Order is found')
else
ShowMessage('Order is not found');
Browser other questions tagged delphi delphi-7 delphi-10
You are not signed in. Login or sign up in order to post.
Note that in Locate you should not separate the String fields by ','. The constant
KeyFields
is just a string.– Junior Moreira
Okay. Well done @Junior Moreira.
– Edu Mendonça