Aha. I thought I was creating fields using the FieldDefs but apparently not the same thing. So I've gotten rid of the design-time aspects and used this instead:
var
// other stuff as before
dtMenu: TXDataWebDataSet;
dtMenu_GRP: TStringField;
dtMenu_NAM: TStringField;
dtMenu_REF: TIntegerField;
dtMenu_ICO: TIntegerField;
dtMenu_SRT: TIntegerField;
dtMenu_DSC: TStringField;
begin
// other stuff as before up to dtMenu.Connection which is now replaced with
dtMenu := TXDataWebDataset.Create(nil);
dtMenu_GRP := TStringField.Create(dtMenu);
dtMenu_GRP.FieldName := 'Original.GRP';
dtMenu_GRP.Size := 30;
dtMenu_GRP.Dataset := dtMenu;
dtMenu_NAM := TStringField.Create(dtMenu);
dtMenu_NAM.FieldName := 'Original.NAM';
dtMenu_NAM.Size := 30;
dtMenu_NAM.Dataset := dtMenu;
dtMenu_REF := TIntegerField.Create(dtMenu);
dtMenu_REF.FieldName := 'Original.REF';
dtMenu_REF.Dataset := dtMenu;
dtMenu_ICO := TIntegerField.Create(dtMenu);
dtMenu_ICO.FieldName := 'Original.ICO';
dtMenu_ICO.Dataset := dtMenu;
dtMenu_SRT := TIntegerField.Create(dtMenu);
dtMenu_SRT.FieldName := 'Original.SRT';
dtMenu_SRT.Dataset := dtMenu;
dtMenu_DSC := TStringField.Create(dtMenu);
dtMenu_DSC.FieldName := 'Original.DSC';
dtMenu_DSC.Size := 250;
dtMenu_DSC.Dataset := dtMenu;
dtMenu.SetJSONData(JRowList);
dtMenu.Open;
LogThis(' -- Building Main Menu');
dtMenu.First;
// other stuff as before, with this added at the end
dtMenu.Close;
dtMenu_GRP.Free;
dtMenu_NAM.Free;
dtMenu_REF.Free;
dtMenu_SRT.Free;
dtMenu_ICO.Free;
dtMenu_DSC.Free;
dtMenu.Free;
end;
So this works pretty well! No more trouble with the connection aspects of XDataWebDataset, and I get my runtime-only instantiation without another design-time element hanging around unnecessarily.
Any suggestions on how to have the fields created using the contents of the JSON to pick out the names and datatypes/sizes? And I don't know how you'd declare the fields ahead of time (var) if you don't know what they are? Maybe Just an array of the different types and then assign them based on what you find in the JSON?
I did look at the thread suggested by Igor but didn't make the connection as far as how it could help here. I think the JSON coming from FireDAC has all the information I need so it is sitting there. I guess it is just a matter of unpacking it and iterating through the values to get what I need. Seems it would be something that lots of people have already done?
Reason for wanting this is so that the same block of code can be used more generically for many queries that might be retrieved. Once the data is there it can be passed over to whatever is using the data and can be more specific about fields, but up until that point, keeping things as generic as possible field-wise I think would work best.