Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scan within a scan. Help from code guru needed please.

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA
Can someone please tell me why I don't get to "Point A" below?

with qryFileOne do
begin
qryFileOneDisablecontrols;
qryFileOne.First; // Go to the first record
while not qryFileOne.Eof do
begin
with qryFileTwodo
begin
Active := True;
qryFile Two.Disablecontrols;
qryFileTwo.First;
while not qryFileTwo.Eof do
begin

Point A
I don't get here to do other stuff because this
routine ignores the "Eof" above, even though
there ARE records, and leaps directly to point "B"
below.


qryFileTwo.next;
end;
end;
if qryFileTwo.UpdatesPending then // Point B
qryFileTwo.ApplyUpdates;
qryFileTwo.enablecontrols;
qryFileOne.next;
end;
qryFileOne.GotoBookmark(GLBookMark);
qryFileOne.FreeBookMark(GLBookMark);
qryFileOne.enablecontrols;
if qryFileOne.UpdatesPending then
qryFileOne.ApplyUpdates;
end;
 
Is there a master / detail relationship between FileOne and FileTwo ?

If for example there were no records in FileTwo relating to the current record in FileOne then the EOF property of FileTwo would be set to true which would cause the program to behave as you indicate.

Andrew
 
I don't know if you copied that directly out of the unit, but the proper syntax is below. I added a ShowMessage (make sure Dialogs is in the USES clauses and change 'SomeQRY1Field' to some field that is actually in query1 and the same for QRY2) so you can see where it is in each query. You have to be careful using nested with statements (especially in this instance when you are using two queries!):

Code:
with qryFileOne do
begin
  Disablecontrols;
  First; // Go to the first record
  while not Eof do
  begin
    ShowMessage(FieldByName('SomeQRY1Field').AsString);
    with qryFileTwo do
    begin
      Active := True;
      Disablecontrols;
      First;
      while not Eof do
      begin
        ShowMessage(FieldByName('SomeQRY2Field').AsString);
        Next;
      end;
      if UpdatesPending then
        ApplyUpdates;
      enablecontrols;
    end;
    next;
  end;
  GotoBookmark(GLBookMark);
  FreeBookMark(GLBookMark);
  enablecontrols;
  if UpdatesPending then
    ApplyUpdates;
end;

Leslie
 
Hi towerbase
Nope!

Andrew I have deliberately steered clear of a TTable (with Master/Detail) relationship as it is too limiting.

Im using TQuery and have a singlerecord in another
File which is used for reference only.
Thanks for the input anyway! :)

Hi lespaul
Leslie ... I've been been there ... done that.
That's how I know that I am not getting to Point A.
But I'll carefully check you code against mine.
 
What are the SQL statements in both TQuerys ?

Have you tried testing out the SQL statement of qryFileTwo in DBExplorer (or something similar) ?

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top