[DUG] Searching ClientDataSet using locate
John Bird
johnkbird at paradise.net.nz
Thu Nov 6 18:13:27 NZDT 2008
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)
More information about the Delphi
mailing list