Page 1 of 1

Is there a quick way to refreshed cached Lookup Value?

Posted: Fri 09 Dec 2011 05:04
by Justmade
There are some query that is structure in this way
Q1 is Master Table which Lookup a fields from Q2
Q2 query is depends on one field of Q1 so has to open after Q1

As I used CacheCalcFields in Q1 (needed for performance issue for other features), it lookup Q2 and cached null for its lookup field (as Q2 is not opened yet).

If I refresh Q1, it can lookup correctly from Q2.

However, a refresh (or refreshquick) need another not necessary access to the server, which can be costly for remote issue.

Is there a direct way to refresh the Cached lookup / calculated fields?

Thanks in advance for your kind help.

Posted: Mon 12 Dec 2011 14:52
by AndreyZ
Hello,

The point is that lookup field requires lookup dataset to be opened before opening a dataset containing this lookup field. And master/detail relationship requires the master table to be opened before opening the detail dataset. To solve the problem in this case, you should use master/detail relationship that is based on SQL statements and parameters. Here is an example:

Code: Select all

procedure TMainForm.BitBtnClick(Sender: TObject);
begin
  MyDetailQuery.SQL.Text := 'select * from detail where id=:id or :id is null';
  MyDetailQuery.Open;
  MyMasterQuery.SQL.Text := 'select * from master';
  MyMasterQuery.Open;
end;

procedure TMainForm.MyMasterQueryAfterScroll(DataSet: TDataSet);
begin
  MyDetailQuery.Close;
  MyDetailQuery.ParamByName('id').AsInteger := MyMasterQuery.FieldByName('id').AsInteger;
  MyDetailQuery.Open;
end;
Using this code you will have master/detail relationship and filled lookup field in the master table.