How can I create subreport by delphi code

I want to create something by code:
eg:
b := TfrBandView.Create; // create ReportData band
b.SetBounds(1, 100, 500, 60);
b.BandType := btMasterData;
b.Dataset := 'frDBDataSet1'; // band's dataset
b.Name :='MasterBand' ;
Page.Objects.Add( b );

it's successfully create a Band.
but I don't know create a subreport dynamic,

p:= TfrSubreportView.Create;
p.SetBounds(1, 120, 500, 30);
(p as TfrSubReportView).SubPage := frReport1.Pages.Count;
p.name:='subreport1';

It's some code ,but its not like in frdesinger,it's not add a new page,if I do so:
page.Objects.Add(p) proceduct a wrong result,current page was changed.

if I :frReport1.Pages.Add; the page have not any relation with subreport.

Who can tell me how to product same effect that add SubReport in FrDesigner by code (Add a SubReport ,auto add a page relat with subReport).


help me. Thank you!

Comments

  • edited 8:15PM
    Nobody can help me ?
    Not understand ?

  • gordkgordk St.Catherines On. Canada.
    edited 8:15PM
    Hi
    here is a sample of adding items
    procedure TForm1.designbtnClick(Sender: TObject);
    // declare variables of these types
    var
    v: TfrView;
    b: TfrBandView;
    sr: tfrsubreportview;
    ts : string;
    Page: TfrPage;
    begin
    frreport1.Dictionary.Clear; //clear dictionary from mem in case youve created
    // a prior report with this component.
    frReport1.Pages.Clear; // clear any pages
    frReport1.Pages.Add; // create page of default type ptreport
    Page := frReport1.Pages[0]; // point page variable to 1st page of 0 based pages array
    // create a dialog page with
    Page.PageType := ptDialog; // must be set to ptdialog
    Page.Width := 200; // set properties of the page
    Page.Height := 170;
    Page.Caption := 'Test query';

    v := TfrButtonControl.Create; // create button
    v.SetBounds(60, 100, 75, 25); // set size and location
    TfrButtonControl(v).Button.Caption := 'Test!'; // set caption
    TfrButtonControl(v).Button.ModalResult := mrOk; // must be set or nothing will happen
    Page.Objects.Add(v); // add it to the page.

    // add a bde query to the dialog page you must place an fr bde component on underlying form

    v:= frcreateobject(gtAddin, 'TfrBDEQuery'); // create the query object
    v.setbounds(40,0,20,20);
    v.prop := 'trialqry'; // set tis name
    v.prop := query1.databasename; // set its dbname to an alias or path
    v.Prop := query1.sql.text; // transfer sql from a query to the new query
    page.objects.add(v); // add it to the form

    frReport1.Pages.Add; // create second page of default type ptreport
    Page := frReport1.Pages[1];
    Page.Prop := poLandscape;
    b := TfrBandView.Create; // create MasterData band
    b.SetBounds(0, 60, 0, 20); // set it's bounds
    b.BandType := btMasterData;
    b.Name := 'MasterData1'; // set it's type
    b.Dataset := 'dialogform._trialqry'; // set band's dataset property
    Page.Objects.Add( ;) ; // add it to the page

    frReport1.Pages.Add; // add pg for subrep pages are 0 based array
    sr:= tfrsubreportview.create;
    sr.Name := 'subreport1';
    sr.SetBounds(40,61,20,15);
    sr.SubPage := 2; // integer value
    page.objects.add(sr);
    // to add objects to subreport page
    Page := frReport1.Pages[2]; // point page var to new page
    //do whatever here

    // disable table and query on form1 so they are not available in report.
    //if you want to add a particular dictionary add it here
    //frreport1.dictionary.loadfromfile('dictfilename.frd');
    //disable table and query on this form report is using a dialog form
    //frReport1.Dictionary.DisabledDatasets.Add('Table1');
    //frReport1.Dictionary.DisabledDatasets.Add('Query1');
    frreport1.FileName := 'myname';
    frreport1.designreport; // just to see it
    end;

    regards ;)
  • edited 8:15PM
    Thank you ,gordk!

    I find I make a mistake.

    My code is right too, but in program environment occur that error.

    I believe I can success. thank you again.

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.