Set DataSource at Runtime
I want to use (one TfrxReport and one TfrxDBDataset) for all my reports
1- Is this code valid?
because i get an error and it not seem to update fields names when changing dataset at runtime!!
2- How I can build a report with field names only without writing TfrxDBDataset name in memo?
1- Is this code valid?
because i get an error and it not seem to update fields names when changing dataset at runtime!!
...
  frrMain: TfrxReport;
  frdMain: TfrxDBDataset;
...
case StrToInt(rpt) of
  101 : ds := 'dsQ1;
  102 : ds := 'dsQ2';
  103 : ds := 'dsQ3';
end;
 if ds <> '' then
 begin
  frdMain.DataSource.Name := ds;
 end;
 frrMain.LoadFromFile(CurrPath + 'rpts\' + rpt + '.fr3');
 frrMain.ShowReport;
2- How I can build a report with field names only without writing TfrxDBDataset name in memo?
Comments
however one can switch the datasets connection the main trick is to also change the frxdbdatasets username.
ie rpt 1 uses frxdbdataset1 user name qry1
enabled dataset will appear as qry1
fields will appear as [qry1."fieldname"].
and will be the only dataset available to the report.
rpt uses frxdbdataset1 username qry2
enabled dataset will appear as qry2
fields will appear as [qry2."fieldname"].
and will be the only dataset available to the report.
this bit of code is probably your problem
if ds <> '' then
begin
frdMain.DataSource.Name := ds;
end;
what you are doing here is setting a dataset to the report component itself.
this would only be used when running a multi design page report.
How I can change datasource and update field list at runtime?!!
so just switch the frxdbdatasets dataset or datasource prop before loading the report.
ie
datamodule repdat contains 2 ttables 2 tdatasource 1 tfrxdbdataset
procedure TForm1.Button1Click(Sender: TObject);
begin
repdat.frxDBDataset1.DataSource := repdat.ordds; // swith ds
frxreport1.Clear;
frxreport1.LoadFromFile('orders.fr3'); //load
frxreport1.ShowReport;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
repdat.frxDBDataset1.DataSource := repdat.custds;
frxreport1.Clear;
frxreport1.LoadFromFile('Customer.fr3');
frxreport1.ShowReport;
end;
It is working now.