25 - ImprovementOn this chapter, we will add functionalities to our basic example in order to determine a maximum of case.You must add a TButton component with the property CAPTION: = ' To print ' and TPrintDialog (pallet standard of DELPHI dialogues) and to obtain thas:It is a little bit long but nothing prevent yourself to create a class inheriting from TFrReport with a Print method or easier, to create a procedure " PrintReport(letat: string) " which load the report and printing it.Add also the Printers unit to the clause USE of your card and enter the following code to onClick event of the button " To print " which I named bPrint.
TForm1.bPrintClick(Sender procedure: TObject);
VAr FromPg, ToPg, Cpy: Integer;
/ / Load the state
/ / Changing the default printer
ind: = Printer.PrinterIndex;
/ / Prépare the state, to leave if the preparation did not function
Yew Not frReport1.PrepareReport then Exit;
/ / Initialise limps it of dialogue for paramètrer the edition
with PrintDialog1 C
Options:=[poPageNums ]; / / Authorizes the selection of pages
Copies: = 1; / / Only one specimen
Collate: = True; / / sorted Copies
FromPage: = 1; / / Page of beginning
ToPage: = frReport1.EMFPages.Count; / / Last page, by defect totality
MaxPage: = frReport1.EMFPages.Count; / / a Number of maximum pages, by defect totality
yew Execute then / / Exécution of limps of dialogue
was yew Printer.PrinterIndex < > ind then / / there a change of printer?
does yew frReport1.CanRebuild then / / owe one regénérer the state?
yew frReport1.ChangePrinter(ind, Printer.PrinterIndex) then / / Change of printer
else exit; / / the change of printer badly occurred
yew PrintDialog1.PrintRange = prPageNums then / / one made a selection of pages
FromPg: = PrintDialog1.FromPage; / / first page
ToPg: = PrintDialog1.ToPage; / / last page
Cpy:=PrintDialog1.Copies; / / a Number of copies
Collap:=PrintDialog1.Collate; / / Exemplary sorted
/ / Lance the edition of the page " FromPg " with " ToPg ", " Cpy " exmplaires sorted (Collap))
frReport1.PrintPreparedReport(FromPg, ToPg, Cpy, Collap);
25.2 - Possible options:
25.21 - Options of page
You obtain these options with the editor menu : " File " then " Page options... ". You obtain this:
- For setting the paper size.
- To set edges
- For the various options
Here, you specify the number of columns as well as space between the columns.
25.22 Options on the state
With the principal menu of the editor, select " File " then " Report options" to display the following dialog box :
Here, you specify the printer which is necessary to select during the loading of the state and if the preparation is done on the two ways.
Warning : if you want to number your pages with " current Page " from "Number of total page ", you must notch the option "Two-pass report"