[DUG] Searching ClientDataSet using locate
Robert martin
rob at chreos.co.nz
Fri Nov 7 09:04:01 NZDT 2008
Hi
Sorry misunderstood the question. I haven't done this stuff for a long
time but found the following function that seems to do what you want...
function TCustomProcessFunctionality.GetVarArray: Variant;
//Breaks incoming values
var
TempList : TStringList;
Counter : Integer;
begin
// fSearchField is a return seperated list of values
// build it in to a string list then add each value to the
// variant array.
TempList := TStringList.Create;
try
TempList.Text := fSearchField;
Result := VarArrayCreate([0, TempList.Count - 1], varVariant);
for Counter := 0 to TempList.Count - 1 do begin
Result[Counter] := TempList[Counter];
end;
finally
TempList.Free;
end;
end;
I believe this code works.
Seems very similar to your code. are you sure that the variable you are
using are ok (i.e. should AlphaFieldsAmx be AlphaFieldsAmx - 1).
You are working on the right track.
Rob
John Bird wrote:
> 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
>
>
More information about the Delphi
mailing list