Board index » delphi » TQuery Locate method - multiple fields

TQuery Locate method - multiple fields

I used the locate method a couple of times (like it) but never on more
than one field. So that's where the problem begins.
Delphi helpfile cryptically says something about passing field values in
an array to the method, but I've tried that and the method don't accept
an array as an in-parameter.
What is the correct syntax?
Someone's got the answer?

/LG

 

Re:TQuery Locate method - multiple fields


Look at the help file under TBDEDataSet.Locate.  That section has the
complete syntax as well as additional info.

Specifically, the cited syntax is:
  with CustTable do
    Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P',
'408-431-1000']), [loPartialKey]);

The key is that the field names are separated by semicolons, the field
values are passed in as a variant array.

Ron Marion
(remove NOSPAM from e-mail)

Quote
Lars G Berggren wrote:
> I used the locate method a couple of times (like it) but never on more
> than one field. So that's where the problem begins.
> Delphi helpfile cryptically says something about passing field values in
> an array to the method, but I've tried that and the method don't accept
> an array as an in-parameter.
> What is the correct syntax?
> Someone's got the answer?

> /LG

Re:TQuery Locate method - multiple fields


The second parameter must be a variant array.  Can we see the code that does
not work?

--
Bill Todd
(Sorry but TeamB cannot answer questions received via email)
(Remove nospam from my email address to contact me for any other reason)

Re:TQuery Locate method - multiple fields


Oh, thanks!
It must be a variant array NOT an array of variant (which I tried). Now
it
all works the way I want it to, but I send the (correct) code anyway if
anyone is interrested. There are some swedish names, but I hope it's
readable.
Note that it's important that there are no spaces in the KeyField set.

procedure TForm_Pose.UpDateBags(BagId: Integer; GotoPeriod: string);
var
  SearchOptions: TLocateOptions;
  SearchValues: Variant;
begin
  SearchOptions := [loCaseInsensitive];
  SearchValues := VarArrayCreate([0, 1], varVariant);
  SearchValues[0] := GotoPeriod;
  SearchValues[1] := BagId;
  with DataModule_Pose.Query_GetMainPose do begin
    Close;
    Open;
    Locate('period;myndigheter_id_grupp',
      SearchValues, SearchOptions);
  end;
end;

Bill Todd (TeamB) skrev:

Quote

> The second parameter must be a variant array.  Can we see the code that does
> not work?

> --
> Bill Todd
> (Sorry but TeamB cannot answer questions received via email)
> (Remove nospam from my email address to contact me for any other reason)

Other Threads