Board index » delphi » Findkey in table X stops dbgrid fill in table Y

Findkey in table X stops dbgrid fill in table Y

Hello everyone,

I have a query with some calculated fields which are updated in the following
procedure (while filling a DBGrid):

procedure TForm1.PupilQryCalcFields(DataSet: TDataset);
begin
  [snip]
  PupilQryCalcField1.Value := ....

  IF SchoolTbl.FindKey([PupilQryBOBRIN.Value]) THEN
    PupilCalcField2.Value := SchoolTbl.FieldByName('...

end;

Calculations like the first one work fine, but as soon as I use a Findkey into
another table, the grid displays only one row. Tracing the code I found that
this happens immediately when/after executing the FindKey.

What is going on here ?
BTW, it's all D1, and as far as I can see there is nothing wrong with the
actual value looked up, or with the primary index.

Bye,
Jan

-----------------------------------------------------------------------
Jan Doggen                Masters Software           mass...@xs4all.nl
P.O. Box 697              2300 RA  Leiden            The Netherlands
-----------------------------------------------------------------------
** Specialists in multimedia software for education and presentation **
-----------------------------------------------------------------------
Usage of this email address for commercial purposes costs US$ 50 per
message. By using this email address you agree to this condition.
-----------------------------------------------------------------------

 

Re:Findkey in table X stops dbgrid fill in table Y


I have used similar code many times with no problem.  Is the table you
are searching one of the tables used in the query?  Is the query live?

Bill

(Sorry but TeamB cannot answer support questions received via email.)
(To send me email for any other reason remove .nospam from my address.)

Re:Findkey in table X stops dbgrid fill in table Y


In message <34e1b5d5.41941...@forums.borland.com> -
Bill_T...@compuserve.com.nospam (Bill Todd (TeamB)) writes:

Quote

>I have used similar code many times with no problem.  Is the table you
>are searching one of the tables used in the query?  Is the query live?

Hi Bill,
here's the problem in more detail. I want to show the data from PupilQry in
the readonly DBGrid PupilDGrd; I look up values from readonly Table SchoolTbl.

In the FormShow proc:

  PupilQry.Close;
  PupilQry.SQL.Clear;
  PupilQry.SQL.Add('SELECT * FROM LEERLING ORDER BY AchterNaam');
  PupilQryLeerlingID.Visible     := FALSE;
  PupilQrySoundexA.Visible       := FALSE;
  { ..snip.. }
  PupilQry.Open;

In procedure TBrowsePupilFrm.PupilQryCalcFields(DataSet: TDataset):
  { PART 1                                                                }
  { Calculated field PupilQryPostcode derived from real fields works fine }
  S := PupilQryPostcode.Value;
  IF S = '' THEN S := '         '
            ELSE S := Copy(S,1,4) + '  ' + Copy(S,5,2);
  PupilQryPoPlaats.Value := S + ' ' + PupilQryPlaats.Value;

  { PART 2                                                                }
  { Calculated field PupilQryBOSchool derived from lookup causes the problem

Quote
}

  PupilQryBOSchool.Value := PupilQryBOBRIN.Value;
  IF PupilQryBOSchool.Value <> '' THEN
    IF SchoolTbl.FindKey([PupilQryBOBRIN.Value]) THEN
      PupilQryBOSchool.Value := PupilQryBOSchool.Value + ' ' +
SchoolTbl.FieldByName('Naam').AsString;

PupilQry properties (in both cases)
- Active FALSE
- AutoCalcFields true
- RequestLive either false/true
- Updatemode UpWhereAll
- Unidirectional FALSE

Other:
- Everything is single-user
- Lookups in another table have the same result
- There are no explicit refreshes or updates called, because I assume they are
not necessary
- In the FormShow I also tried:
    try
      PupilQry.Open;
    except
      PupilQry.ExecSQL;
    end

In my original post I said only one row appeared, but that should read
'an *empty* row' - it looks like an empty set. If I comment out PART 2
the grid fills OK.

Bye,
Jan

-----------------------------------------------------------------------
Jan Doggen                Masters Software           mass...@xs4all.nl
P.O. Box 697              2300 RA  Leiden            The Netherlands
-----------------------------------------------------------------------
** Specialists in multimedia software for education and presentation **
-----------------------------------------------------------------------
Usage of this email address for commercial purposes costs US$ 50 per
message. By using this email address you agree to this condition.
-----------------------------------------------------------------------

Re:Findkey in table X stops dbgrid fill in table Y


I may be missing something but your code looks correct to me. I am not
sure why it would not work unless there is a problem with the table or
index.

Bill

(Sorry but TeamB cannot answer support questions received via email.)
(To send me email for any other reason remove .nospam from my address.)

Re:Findkey in table X stops dbgrid fill in table Y


FOUND IT!!

The Scholen lookup table wasn't open yet when the FormShow procedure executed.
Together with the de{*word*81} option 'break on exception' turned off this caused
the Scholen.Findkey to return TRUE (strange) without any warnings.

Bye,
Jan

-----------------------------------------------------------------------
Jan Doggen                Masters Software           mass...@xs4all.nl
P.O. Box 697              2300 RA  Leiden            The Netherlands
-----------------------------------------------------------------------
** Specialists in multimedia software for education and presentation **
-----------------------------------------------------------------------
Usage of this email address for commercial purposes costs US$ 50 per
message. By using this email address you agree to this condition.
-----------------------------------------------------------------------

Other Threads