Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Using FireDacs Locate &/or Locate function



Permlink Replies: 4 - Last Post: Dec 20, 2016 9:35 AM Last Post By: Barry Wood
Barry Wood

Posts: 73
Registered: 9/3/01
Using FireDacs Locate &/or Locate function
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2016 6:17 AM
Hi,
The documentation for using the above isn't very clear to me, I was wondering if anyone can provide a few samples of how the functionality is used?

What I want to do is find the value of a specific field in a query using 4 other fields to find the record. My current code looks like this:

vR:= dm.fdqA.LocateEx( 'Year = ' + QuotedStr( cYear ) + ' AND League = ' + QuotedStr( cLeague ) + ' AND HomeClub = ' + QuotedStr( cHomeTeam ) + ' AND AwayClub = ' + QuotedStr( cAwayTeam ), 'MatchDate', []);

Were vR is a variant and the variables cYear, cLeague, cHomeTeam and cAwayTeam hold the actual values to be used to find a record and MatchDate is the field in which I want to get the value. The data is held in a MSSQL table.

I have a feeling that QuotedStr isn't used by FireDac and if that's so I'm wondering how the Locate method can use variables in it's creation?

Any help would be appreciated.
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Using FireDacs Locate &/or Locate function
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2016 6:45 AM   in response to: Barry Wood in response to: Barry Wood
Barry Wood wrote:

Hi,
The documentation for using the above isn't very clear to me, I was
wondering if anyone can provide a few samples of how the
functionality is used?

What I want to do is find the value of a specific field in a query
using 4 other fields to find the record. My current code looks like
this:

vR:= dm.fdqA.LocateEx( 'Year = ' + QuotedStr( cYear ) + ' AND League
= ' + QuotedStr( cLeague ) + ' AND HomeClub = ' + QuotedStr(
cHomeTeam ) + ' AND AwayClub = ' + QuotedStr( cAwayTeam ),
'MatchDate', []);

Were vR is a variant and the variables cYear, cLeague, cHomeTeam and
cAwayTeam hold the actual values to be used to find a record and
MatchDate is the field in which I want to get the value. The data is
held in a MSSQL table.

I have a feeling that QuotedStr isn't used by FireDac and if that's
so I'm wondering how the Locate method can use variables in it's
creation?

Any help would be appreciated.

I've never used the locateEx method only the locate, I would use the
other overload version:

  if dm.fdqA.LocateEx('Year;League;HomeClub', VarArrayOf([cYear,
cLeague, cHomeTeam]), []) then
    ShowMessage('Located!')
  else
    ShowMessage('Failed!');


Of course in this case I believe there is no difference between Locate
and LocateEx?
Barry Wood

Posts: 73
Registered: 9/3/01
Re: Using FireDacs Locate &/or Locate function
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2016 8:06 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Hi
Many thanks for replying. I've used that code and it finds the records OK. However, what I'm after is the value of another field in that record returned, namely the 'MatchDate' field. That's why I'm searching for a specific record, not to check it exists but to get the value of another field. Is that possible with the Locate?

Lajos Juhasz wrote:
Barry Wood wrote:

Hi,
The documentation for using the above isn't very clear to me, I was
wondering if anyone can provide a few samples of how the
functionality is used?

What I want to do is find the value of a specific field in a query
using 4 other fields to find the record. My current code looks like
this:

vR:= dm.fdqA.LocateEx( 'Year = ' + QuotedStr( cYear ) + ' AND League
= ' + QuotedStr( cLeague ) + ' AND HomeClub = ' + QuotedStr(
cHomeTeam ) + ' AND AwayClub = ' + QuotedStr( cAwayTeam ),
'MatchDate', []);

Were vR is a variant and the variables cYear, cLeague, cHomeTeam and
cAwayTeam hold the actual values to be used to find a record and
MatchDate is the field in which I want to get the value. The data is
held in a MSSQL table.

I have a feeling that QuotedStr isn't used by FireDac and if that's
so I'm wondering how the Locate method can use variables in it's
creation?

Any help would be appreciated.

I've never used the locateEx method only the locate, I would use the
other overload version:

  if dm.fdqA.LocateEx('Year;League;HomeClub', VarArrayOf([cYear,
cLeague, cHomeTeam]), []) then
    ShowMessage('Located!')
  else
    ShowMessage('Failed!');


Of course in this case I believe there is no difference between Locate
and LocateEx?
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Using FireDacs Locate &/or Locate function
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2016 8:20 AM   in response to: Barry Wood in response to: Barry Wood
The cursor is on the located record, so can't you just get the value asking the query result?

if qryTest.Locate('NAME','barry',[loCaseInsensitive]) then
begin
    if qryTest.FieldByName('MatchDate').AsDateTime<>myDate then
    begin
      //
    end;
end;
Barry Wood

Posts: 73
Registered: 9/3/01
Re: Using FireDacs Locate &/or Locate function
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2016 9:35 AM   in response to: Robert Triest in response to: Robert Triest
Hi Robert,

Works brilliantly, many thanks ...

Robert Triest wrote:
The cursor is on the located record, so can't you just get the value asking the query result?

if qryTest.Locate('NAME','barry',[loCaseInsensitive]) then
begin
    if qryTest.FieldByName('MatchDate').AsDateTime<>myDate then
    begin
      //
    end;
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02