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.
Is there a quick way to refreshed cached Lookup Value?
-
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:Using this code you will have master/detail relationship and filled lookup field in the master table.
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;