0

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:

  1. He links his master TCXGrid datasource property to the Customer data source, which in turn links to the Customer table.
  2. He links his detail TCXGrid DataSource to the Device data source, which then links to the underlying Device Table.
  3. 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?

user3810626
  • 6,798
  • 3
  • 14
  • 19
  • 1
    With no code and a confusing description no idea. Post the code of the AfterScroll on the customer table and how you modified it to take into consideration the new option to filter out inactive devices. Might just need to move that into it's own procedure and call it when the checkbox changes in addition from in the AfterScroll event. – Brian Aug 20 '18 at 21:02
  • I have tried to clarify and included the code. – user3810626 Aug 21 '18 at 03:53
  • Try deactivating the Filter before you call AfterScroll from your Checkbox. – FredS Aug 21 '18 at 16:56
  • Deactivating the filter had no effect, thanks. – user3810626 Aug 25 '18 at 22:04

1 Answers1

1

Looks to me like you are over complicating things. Ignore the global settings table. Put something like this in a new procedure and call it from the AfterScroll for tblCustomer, OnClick for the checkbox and when tblDevices is made active.

if tblDevices.Active then
begin
   tblDevices.filter := 'DCKEY=' + inttostr(DataSet.FieldbyName('CKEY').AsInteger);
   if not CheckboxViewInActive.checked then Devices.filter := theDevices.Filter +' AND ACTIVE <> FALSE';
   tblDevices.Filtered:=True;
end;

If you want to load/save this setting in a global settings table do it separately.

Brian
  • 6,717
  • 2
  • 23
  • 31
  • Your solution makes the data module dependent on the UI, which I would regard as a Bad Thing. This is already the case, however. Also, the form for CheckBoxViewInactive is on a form that usually doesn't exist, so I'll have to change that, too. (It's kind of what I was trying to avoid.) – user3810626 Aug 25 '18 at 22:03