[DUG] Searching ClientDataSet using locate

Neven MacEwan neven at mwk.co.nz
Fri Nov 7 10:02:41 NZDT 2008


Stephen

I think you'll find the filtering is a "a brute force scan of all 
records in code" :-)

I'd like to know where the data is soming from because I always think it 
is better to
to the selection in the database rather than loading lots of records and 
doing this kind of select locally

N
> Hi John,
>
> Are you trying to locate the same string within multiple fields? If so, I
> don't think the locate will help you there.
>
> Try using the onfilterrecord event as Neven said, or a filter expression
> like this if your database allows it:
>
> .filter := 'name like ''%'+findstr+'%'' or address1 like ''%'+findstr+'%''
> or...
>
> or even do a brute force scan of all records in code.
>
>
> hth
> Steve 
>
>   
>> -----Original Message-----
>> From: John Bird [mailto:johnkbird at paradise.net.nz] 
>> Sent: Thursday, 6 November 2008 6:13 p.m.
>> To: NZ Borland Developers Group - Delphi List
>> Subject: Re: [DUG] Searching ClientDataSet using locate
>>
>> Yes that would work for searching two fields, but do I do "n" 
>> fields - ie
>> what I am trying to do is generalise and build a list of 
>> fields to search
>> for at runtime where the number of fields to search changes
>>
>> (ie all where Datatype = ftString) - I can build a string 
>> listing the wanted
>> string fields, and this goes in the first parameter ok.
>>
>> What I have not figured yet is how to build the second 
>> parameter when I am
>> searching in an arbitrary number of fields  I am using the same search
>> string  on all the fields,  (it has to be passed as a variant 
>> array with as
>> many entries as the number of fields being searched if I understand
>> correctly).
>>
>> I have tried something like
>>
>> Findstr:  String;                        //string to find in 
>> the dataset
>> AlphaFieldsList: String;           //fields list of all 
>> string fields, eg
>> 'Name;Address1;Address2;Description'
>>                                              //this is built 
>> at runtime by
>> looking at the dataset
>> vAlphaStringsList:variant;
>> AlphaFieldsAmx: iinteger;        //This is set to the number of string
>> fields found in this dataset
>>
>>                 ...
>>
>>   if AlphaFieldsamx >=0 then
>>  begin
>>    vAlphaStringsList := VarArrayCreate([0, AlphaFieldsAmx],  
>> varVariant);
>>    for i := 0 to AlphaFieldsAmx do
>>    begin
>>        cAlphaStringsList[i] := Findstr;
>>    end;
>>
>>
>>   cdsFind.locate(AlphaFieldsList, vAlphaStringsList, [loPartialKey,
>> loCaseInsensitive])
>>
>> I suspect I am doing something wrong building the variant 
>> parameter and I am
>> new to working with variants...
>>
>> But it don't seem to work.....any suggestions how to build the second
>> parameter?
>>
>> I have thought of doing the search by filtering, but some of 
>> the datasets I
>> want to search on are already filtered which makes it harder 
>> to use filters
>> for new functions..
>>
>> John
>>     
>>> .Locate('Field1;Field1', VarArrayOf([Variable1, Variable2])
>>>
>>> Works fine for me (all over the place but just with std TDataset)
>>>       
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz 
>> with Subject: unsubscribe
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com 
>> Version: 8.0.175 / Virus Database: 270.8.4/1749 - Release 
>> Date: 5/11/2008 7:17 a.m.
>>
>>
>>     
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
>
>
>   



More information about the Delphi mailing list