Set DataSource at Runtime

khhkhh
edited 10:00PM in FastReport 4.0
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!!
...
    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

  • gordkgordk St.Catherines On. Canada.
    edited 10:00PM
    Generally while you may use 1 report component you will probbably find you use more than 1 frxdbdataset or fruserdataset. in apps.
    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.

  • khhkhh
    edited December 2006
    Currently I use one frxDBDataset with same username for all my reports. I change datasource for it at designtime and there is no problem.

    How I can change datasource and update field list at runtime?!!
  • gordkgordk St.Catherines On. Canada.
    edited 10:00PM
    assuming the report was designed and saved all the datainfo is stored in the fr3 file.

    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;
  • khhkhh
    edited 10:00PM
    Thank you.

    It is working now.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.