Version info: Delphi 2010, Express Quantum GridSuite 6.56
I've inherited some code where the programmer has two grids in a master/detail (Customers->Devices) relationship, and he's made this work like so:
- He links his master TCXGrid datasource property to the Customer data source, which in turn links to the Customer table.
- He links his detail TCXGrid DataSource to the Device data source, which then links to the underlying Device Table.
- To make the actual Master/Detail magic happen, he's hooked into the Customer table's AfterScroll event and sets a filter on the Device dataset based on a key in the current record of the Customer table.
The code:
procedure TdmData.tblCustomerAfterScroll(DataSet: TDataSet);
begin
if tblDevices.Active then
begin
tblDevices.filter := 'DCKEY=' +
inttostr(DataSet.FieldbyName('CKEY').AsInteger)
{+ ViewInactiveString}; //my addition
tblDevices.Filtered:=True;
end;
end;
This works. (That is to say when the user clicks on a customer the Customer grid, the Devices grid changes to display only that customer's devices.)
My task has been to add an additional (global) filter for inactive devices. So I created a checkbox on this master/detail page linking to a global settings table, linked to a field called view_inactive. I've added to the filter described in step 3.
function TdmData.ViewInactiveString: String;
begin
if not tblSettingsVIEW_INACTIVE.AsBoolean
then Result := ' AND ACTIVE <> FALSE'
else Result := '';
end;
This also works in the sense that when the user clicks on the Customer grid, the Device grid displays on that customer's devices which are not inactive. But the Device grid does not update UNTIL the user clicks on the Customer grid, and I want it to update right away.
I hooked into the checkbox OnClick to call the customer's AfterScroll method, but this doesn't update the detail grid. I notice that this seems to be because the bound view_inactive field is still returning the old state. I figure the events aren't firing in the order I expect, so I'll have to hook into the global settings table. I try using the following events:
- The settings table AfterPost
- The settings data source OnDataChange
- The settings data source OnUpdateData
- The settings data set AfterPost
In each case, whether the event is fired or not, the result is the same. The underlying view_inactive table has not yet been set. But if I click on the customer grid, it somehow is.
Where am I going wrong?