Create TOC (Complete Report from Code in Delphi)

Hi,

i create the report complete from code and not using the designer. I want to have a TOC including the startpage of the report category.

How can i figure out wich page has what page number in the final pass or is there a way to get the pagenumber from the page?

I am able to get the page using FindObject but that did not help me.

Any suggestions and/or examples? This is my first project using fastreport so i am somehow new to that.

Best regards and many thanks in advance,

Andy

Comments

  • gpigpi
    edited 12:03PM
    See FRDemo "URLs, anchors" report
  • edited September 2017
    gpi wrote: »
    See FRDemo "URLs, anchors" report

    Hi,

    thanks for the quick response ... i tried that but it does not seem to work ...

    i create a coverpage, intropage, the indexpage and the datapages in that sequence

    in the memo (called datafield) of the toc i create them with the following code:
       // left space
       CurrentWidth := 25;
       // TOC Entry
       DataField := TfrxMemoView.Create(DataBand);
       DataField.CreateUniqueName;
       DataField.AllowHTMLTags := true;
       DataField.AllowExpressions := true;
       DataField.HAlign := frxClass.haLeft;
       DataField.VAlign := frxClass.vaTop;
       DataField.Font.Size := 8;
       DataField.Font.Style := DataField.Font.Style + [fsbold];
       DataField.WordWrap := false;
       DataField.WordBreak := false;
       DataField.Text := GetStringFromID(TDetailViewDataObject(TempNode.DataObject).ID,1) + '  ......................................................................................................................' +
                                                                                            '......................................................................................................................';
       DataField.SetBounds(CurrentWidth,CurrentHeight,(IndexPage.Width - IndexPage.LeftMargin - IndexPage.RightMargin - RightMarginCorrector) - 80 - CurrentWidth,20);
       DataField.Hyperlink.Kind := hkAnchor;
       DataField.Hyperlink.Value := '[<TOCANCHOR' + TDetailViewDataObject(TempNode.DataObject).ID.ToString + '>]';
       CurrentWidth := (IndexPage.Width - IndexPage.LeftMargin - IndexPage.RightMargin - RightMarginCorrector) - 80 - CurrentWidth;
       // TOC Page number
       DataField := TfrxMemoView.Create(DataBand);
       DataField.CreateUniqueName;
       DataField.AllowHTMLTags := true;
       DataField.AllowExpressions := true;
       DataField.HAlign := frxClass.haRight;
       DataField.VAlign := frxClass.vaTop;
       DataField.Font.Size := 8;
       DataField.Font.Style := DataField.Font.Style + [fsbold];
       DataField.WordWrap := false;
       DataField.WordBreak := false;
       DataField.Text := '[Engine.GetAnchorPage(<TOCANCHOR' + TDetailViewDataObject(TempNode.DataObject).ID.ToString + '>)]';
       DataField.SetBounds(CurrentWidth,CurrentHeight,(IndexPage.Width - IndexPage.LeftMargin - IndexPage.RightMargin - RightMarginCorrector) - CurrentWidth - 40,20);
       // adjust height
       CurrentHeight := CurrentHeight + 20;
    

    for each first databand of the datapages i add the following code
       // add masterdata band
       DataBand := TfrxMasterData.Create(Page);
       DataBand.CreateUniqueName;
       DataBand.DataSet := AnalysisDataModule.URLReportEmptyUserDataSet;
       DataBand.FHeader := TableHeader;
       DataBand.Stretched := true;
       DataBand.Top := TableHeader.Top + TableHeader.Height + 1;
       DataBand.Height := 230;
    
       // TOC anchor stuff
       URLReport.ScriptText.Add('procedure ' + DataBand.Name +  'OnBeforePrint(Sender: TfrxComponent);');
       URLReport.ScriptText.Add('begin');
       URLReport.ScriptText.Add(' Engine.AddAnchor(<TOCANCHOR' + TDetailViewDataObject(TempNode.DataObject).ID.ToString + '>);');
       URLReport.ScriptText.Add('end;');
    
       // Global Script Stuff
       AnchorScript.Add(DataBand.Name +  '.OnbeforePrint :=' + '''' + DataBand.Name + 'OnBeforePrint' + '''' + ';');
    

    Then i get this error message ...

  • edited 12:03PM
    Does anybody have any idea regarding this problem?
  • gpigpi
    edited 12:03PM
    Create small and simple demo project with error based on standart Delphi's components and FRDemo database and attach it here
  • edited 12:03PM
    gpi wrote: »
    Create small and simple demo project with error based on standart Delphi's components and FRDemo database and attach it here

    Here is the small demo project .... hope this helps finding the problem ....
  • gpigpi
    edited 12:03PM
    Fixed and working demo project in the attach. Use designer to check your "code based" report
  • edited 12:03PM
    gpi wrote: »
    Fixed and working demo project in the attach. Use designer to check your "code based" report

    Thanks a lot ... i will check it out and put the changes to my app >>>>>

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.