Having multiple instances of same DataModule, prints data from DM1 in the report of DM2
I have a DataModule for a CRUD of orders and items. This DM is used for the form (VCL) and for print some reports. The TfrxDataSet componentes are in this DM.
When I have the order's form openned showing data from Order 1 and create other instance of same DM do print a report for Order 2, the report show data of Order 1.
Before printing, I'm setting:
Report.EngineOptions.UseGlobalDataSetList := False;
Report.EnabledDataSets.Clear
Report.EnabledDataSets.Add(...datasets from the instance of DM created to print ...)
In the FR3 (XML), there is <item DataSet="dtmNotaVenda.fdsNotaVenda" DataSetName="fdsNotaVenda"/>, where "dtmNotaVenda" is the global var to the DM instance used at Order's form.
Comments
Demo attached.
Demo with report template.
I found a solution, moving the TfrxDBDataSet to the same form/DM of TfrxReport, so at the FR3 (xml), it will be local, without the sufix "DataModule4." Off course, I will have to manually update the report template to point to local frxDBDataSet. Then, I set the frxDBDataSet.DataSet before printing the report, using the dataset from each DataModule.
See the demo.