Well, I managed to get this working!
I added a where clause to the sqlCategories SQL statement with a parameter for the GroupID:
SELECT ID, GroupID, ShortName, FullName, IsInactive
FROM Categories
WHERE GroupID = :GroupID
ORDER BY ShortName
The "entry point" procedure (for a New Activity) is basically:
procedure TfrmEditActivity.TimerNew(piGroupID: integer);
var
iModalResult: integer;
begin
Self.Caption := 'New Activity';
sqlActivities.Append();
// Without the Close/Open the Group does not get selected
sqlCategories.Close();
sqlCategories.ParamByName('GroupID').AsInteger := piGroupID;
sqlCategories.Open();
iModalResult := Self.ShowModal();
if iModalResult = mrOK then
begin
// Save the record
sqlActivities.ApplyUpdates();
end;
end;
The key point was to Close the sqlCategories control, assign the GroupID to the Parameter and then Open the sqlCategories control (lines 9 thru 11). This caused the Group combobox to select the correct entry and the cmbCategories List to contain
only entries that belong to the specified group.
Then I had to add an OnSelect event procedure for the Group combobox:
procedure TfrmEditActivity.cmbDbGroupSelect(Sender: TObject);
var
iGID: integer;
begin
// Capture the selected GroupID
iGID := sqlCategories.FieldByName('GroupID').AsInteger;
// Without the Close/Open, the Categories List does not refresh
sqlCategories.Close();
sqlCategories.ParamByName('GroupID').AsInteger := iGID;
sqlCategories.Open();
end;
When a Group is chosen (in the combobox), I had to reload the sqlCategories control. This required me to Close it, Assign the new GroupID to the parameter and then Open it. The significant point was that I had to get the ID of the selected Group from the GroupID field of the sqlCategories control
before I closed it.