Delphi TOC
Hi,
I have looked at the Demos for building a Table Of Contents (TOC). What I am trying to do is build a TOC for my report which is mainly constructed from within Delphi rather than the designer's pascal script, as my data is not stored in a database. In fact the whole report is built in Delphi code with only static stuff on the actual report designs.
I am using the reports 'OnManualBuild' event handler to build my report by adding master bands in Delphi code. How do I build a TOC with page numbers for each master band added ? There' doesnt seem to be access to "Engine.AddAnchor(xyz)" or a "Report.Engine.AddAnchor(xyz)" when in Delphi code.
What I have tried is calling "Engine.AddAnchor(<TOC_Entry>);" from within OBP event handler of the master data band on my main report page. The master data bands are printed, but no TOC entry is printed. The report is Double Pass. In the designer, I have TOC page with text labels within a masterdata band. In the second main data page I have another master data band that lists the main report data.
All my values come from report variables so I use the report's OnGetValue event handler for all data in the report.
Any help on how to create a TOC page in Delphi would be much appreciated,
Thanks
Bill.
I have looked at the Demos for building a Table Of Contents (TOC). What I am trying to do is build a TOC for my report which is mainly constructed from within Delphi rather than the designer's pascal script, as my data is not stored in a database. In fact the whole report is built in Delphi code with only static stuff on the actual report designs.
I am using the reports 'OnManualBuild' event handler to build my report by adding master bands in Delphi code. How do I build a TOC with page numbers for each master band added ? There' doesnt seem to be access to "Engine.AddAnchor(xyz)" or a "Report.Engine.AddAnchor(xyz)" when in Delphi code.
What I have tried is calling "Engine.AddAnchor(<TOC_Entry>);" from within OBP event handler of the master data band on my main report page. The master data bands are printed, but no TOC entry is printed. The report is Double Pass. In the designer, I have TOC page with text labels within a masterdata band. In the second main data page I have another master data band that lists the main report data.
All my values come from report variables so I use the report's OnGetValue event handler for all data in the report.
Any help on how to create a TOC page in Delphi would be much appreciated,
Thanks
Bill.
Comments
ie
frxreport1.Clear;
// working with a basic starting script
frxreport1.LoadFromFile('testscriptvars2.fr3');
// initially the code page contains only
{begin
end.}
frxreport1.ScriptText.Clear; // clear existing script text
//create code page variables to be used in report internal events
frxreport1.ScriptText.Add('var'); //add to top of page
// used a loop but you wlll probably want to use individual
// enties to make names more meaningfull
for i := 1 to 3 do
begin
// use ScriptText.add('')method to add the varname and type declartion
frxreport1.ScriptText.Add('myvar'+inttostr(i)+': string;');
end;
// add a procedure to to script
frxreport1.ScriptText.Add('procedure MasterData1OnBeforePrint(Sender: TfrxComponent);');
frxreport1.ScriptText.Add('Begin');
frxreport1.ScriptText.Add('if <Line#> = 2 then memo2.text := '+''''+''+''''+';');
frxreport1.ScriptText.Add('end;');
// cleanup end of script and initialize vars
// this block of code is processed when report starts.
frxreport1.ScriptText.Add('Begin');
// initialize variable values here
frxreport1.ScriptText.Add('myvar1:='+''''+'Hello world'+''''+';');
// connect masterdata1 obp event to procedure
frxreport1.ScriptText.Add('masterData1.OnbeforePrint :='+''''+'MasterData1OnBeforePrint'+''''+';');
frxreport1.ScriptText.Add('end.');
// alternate way to connect procedure
{bnd:= frxreport1.FindObject('MasterData1');
tfrxMasterdata(bnd).OnBeforePrint := 'MasterData1OnBeforePrint';}
// i use the line below so i can check what i have added
if cb1.Checked then frxreport1.DesignReport else frxreport1.ShowReport;
end;
Although I learnt something new today from your reply about FR, I eventually managed to do what I wanted to do using just the script below.
For anyone whos interested, in Delphi I then just had to write the OnGetValue (to populate the variable 'TOC_Caption') and the OnManualBuild event handler to build the main report and TOC pages as needed.
Thanks
Bill.
procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
begin
Engine.AddAnchor(<TOC_Caption>);
end;
procedure mmoTOCPageNoOnBeforePrint(Sender: TfrxComponent);
begin
mmoTOCPageNo.Memo.Text:=IntToStr(Engine.GetAnchorPage(<TOC_Caption>));
end;