Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
163
Добавлен:
11.05.2015
Размер:
4.73 Mб
Скачать

Orientation := orLandscape;

{Preserve PaperSize as set in Report} PreserveRptSettings := [prPaperSize]; {Do not show the PrintDialog on Execute} ShowDialog := False;

end; Crpe1.Execute;

Printer ShowDialog property

Declaration

property ShowDialog: Boolean;

Description

The ShowDialog property can be used to bring up the Delphi Print dialog, which allows the user to change Printer property values. This dialog box looks like this:

It is the same as calling the ShowPrintDlg method, except that whereas ShowPrintDlg causes the Print dialog box to appear as soon as it is called, ShowDialog calls the Print dialog only when the Crystal component's Execute method is called.

In practical terms, you would use ShowDialog if you always want the user to be prompted for a Printer choice before the Report runs. If you only want the Print dialog to show optionally, if a button is pressed for example, then use the ShowPrintDlg method in the button click event.

With ShowDialog set to True, the Print dialog box will appear whenever the Send method is called. The Send method is automatically called whenever the Execute method for the component is called.

VCL Reference

500

If you want the Print dialog box to appear with a specific printer selected, set the Delphi Printers.PrinterIndex to the Printer desired, and call the GetCurrent method before calling Execute. When the Print dialog box appears, it will have that Printer selected by default.

Example

The following code illustrates how to use the ShowDialog property of the Printer object:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Output := toPrinter; Crpe1.Printer.ShowDialog := True;

{When Execute is called, the Printer dialog will appear} Crpe1.Execute;

Here is the same example, but in this case, we want the Printer dialog to appear with a certain Printer preselected:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Output := toPrinter; Crpe1.Printer.ShowDialog := True;

{Set the Delphi Printers list to the 4th Printer} Printers.PrinterIndex := 3;

{When Execute is called, the Printer dialog will appear} Crpe1.Execute;

Printer Methods

Printer Clear Method

Declaration

procedure Clear;

Description

The Clear method can be used to set the Printer properties back to their default values:

Name := '';

Port := '';

Driver := '';;

Mode := 0;

PMode := nil;

Orientation := orDefault;

PreserveRptSettings := [];

It is called automatically if the Clear method is called for the main component, but may be called in code as needed.

VCL Reference

501

Example

This line of code clears the Printer properties:

Crpe1.Printer.Clear;

Printer CopyFrom Method

Declaration

function CopyFrom(Source: TCrpePrinter): boolean;

Description

The CopyFrom method copies the Printer property values from another TCrpePrinter object. It is similar to Delphi's Assign method. It is useful for transferring or temporary storage of values.

Example

The following example copies all the Printer property values to a temporary TCrpePrinter object:

var

tempPrinter : TCrpePrinter; begin

tempPrinter := TCrpePrinter.Create; tempPrinter.CopyFrom(Crpe1.Printer);

{...later, when finished with the temp object...} tempPrinter.Free;

end;

Printer Create Method

Declaration

constructor Create;

Description

The Create method is used internally in the Crystal component to create the Printer object, and does not need to be called in code.

VCL Reference

502

Printer GetCurrent Method

Declaration

function GetCurrent: boolean;

Description

The GetCurrent method obtains the current Printer information and fills the component's Printer properties (Name, Driver, Port, Mode and PMode) with values.

GetCurrent would normally be called after setting the PrinterIndex of the Delphi "Printer.Printers" array, or after displaying the PrintDialog.

Returns True if the call succeeded.

Example

The following example illustrates the use of the GetCurrent method to obtain the current Printer information after setting the Printer.Printers array:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Output := toPrinter;

{Set Printer array to 3rd Printer} Printer.PrinterIndex := 2;

{Fetch the Printer Info into the VCL} Crpe1.Printer.GetCurrent; Crpe1.Execute;

This example shows the use of the GetCurrent method after a PrintDialog is called:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Output := toPrinter;

{Show the PrintDialog}

if PrintDialog1.Execute then begin

{Fetch the Selected Printer Info into the VCL} Crpe1.Printer.GetCurrent;

Crpe1.Execute; end;

VCL Reference

503

Соседние файлы в папке crystal