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

The following code illustrates the use of the Retrieve method for the main Report and any Subreports:

var

cnt: integer; begin

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Subreports.Retrieve;

{Loop through Reports and Retrieve}

for cnt := 0 to (Crpe1.Subreports.Count - 1) do begin

Crpe1.Subreports[cnt];

Crpe1.Margins.Retrieve; end;

{Set Crpe component back to main Report} Crpe1.Subreports[0];

end;

PrintDate Send method

Declaration

function Send: boolean;

Description

The Send method sends the PrintDate values to the Crystal Reports Print Engine. This method is called automatically when the Execute method is called, provided that SendOnExecute is set to True.

It is strongly recommended that you leave SendOnExecute to True, and let the Crystal Reports component send the values to the Print Engine. If you set the SendOnExecute property to False, each Sub-class and each property that does not belong to a Sub-class must be manually sent before calling the Execute method. This feature is mainly provided for debugging purposes.

Example

In this example, the PrintDate settings are sent from the Crystal component to the Crystal Reports Print Engine DLL. This is normally handled automatically in the Execute method:

Crpe1.PrintDate.Send;

VCL Reference

487

Printer Properties

Printer Driver property

Declaration

property Driver: TCrPrinterName;

Type

TCrPrinterName = string[80];

Description

The Driver property contains the Driver name of the Printer.

Traditionally, the Crystal VCL used to require the Name, Driver, Port and Mode properties to be set before it would change the Printer for a Report. With the new Crystal component, however, this is not required. The only property that needs to be specified is the Name. The component will automatically fill in the other values (if the Printer Name is valid), when the component's Execute method is called.

If the Retrieve method is used, the Driver property will contain the Driver name for the Printer that was specified in the Report (or the default printer if the Printer specified in the Report is not valid). Alternatively, the GetCurrent method can be called right after showing Delphi's PrintDialog, and it will also fill the Printer properties with values corresponding to the selected Printer.

Example

This code uses the Printer properties to change Printers to one selected via the Print Dialog. It also makes sure that the Orientation defined in the Report is preserved.

procedure RunReport; var

lpPrinter, lpDriver, lpPort : pChar;

hMode

: THandle;

pMode

: PDevMode;

nOrientation

: integer;

begin

{Set ReportName}

Crpe1.ReportName := 'C:\Company.rpt'; {Get Printer settings from Report} Crpe1.Printer.Retrieve;

{Check the Orientation} hMode := Crpe1.Printer.Mode; pMode := GlobalLock(hMode);

VCL Reference

488

case pMode^.dmOrientation of DMORIENT_PORTRAIT : nOrientation := 0; DMORIENT_LANDSCAPE : nOrientation := 1;

end; GlobalUnlock(hMode);

{Allocate memory for Printer property variables} try

lpPrinter := StrAlloc(255); lpDriver := StrAlloc(255); lpPort := StrAlloc(255);

except

if lpPrinter <> nil then StrDispose(lpPrinter); if lpDriver <> nil then

StrDispose(lpDriver); if lpPort <> nil then

StrDispose(lpPort);

Exit; end;

{Show the PrintDialog}

if PrintDialog1.Execute then {if OK was clicked} begin

{Get Selected Printer; could also use Crpe1.SelectPrinter} Printer.GetPrinter(lpPrinter, lpDriver, lpPort, hMode); {Set PrinterName}

Crpe1.Printer.Name := StrPas(lpPrinter);

{Set PrinterDriver: Check for Null - Win95 32-bit problem} if Length(StrPas(lpDriver)) <> 0 then Crpe1.Printer.Driver := StrPas(lpDriver)

else

Crpe1.Printer.Driver := StrPas(lpPrinter); Set PrinterPort}

Crpe1.Printer.Port := StrPas(lpPort); {Set PrinterMode}

Crpe1.Printer.Mode := hMode;

{Make sure the Orientation remains as in Report} pMode := GlobalLock(hMode);

case nOrientation of

0:pMode^.dmOrientation := DMORIENT_PORTRAIT;

1:pMode^.dmOrientation := DMORIENT_LANDSCAPE;

end; GlobalUnlock(hMode);

VCL Reference

489

{Run the Report} Crpe1.Execute;

end; StrDispose(lpPort); StrDispose(lpDriver); StrDispose(lpPrinter);

end;

The above code can be greatly simplified by using some of the other Printer object methods & properties:

procedure RunReport; begin

{Set ReportName}

Crpe1.ReportName := 'C:\test.rpt'; {Preserve Orientation from Report}

Crpe1.Printer.PreserveRptSettings[prOrientation]; {Prompt for Printer at Execute} Crpe1.Printer.ShowDialog := True;

{Run the Report} Crpe1.Execute;

end;

Printer Mode property

Declaration

property Mode: integer;

Description

The Mode property specifies a handle to the DevMode structure associated with a certain Printer. This handle is normally obtained via Delphi's "Printer.GetPrinter" method. Not that it is no longer necessary to fill in a value for this property, since the Crystal component will obtain this information internally provided a valid value is specified in the Name property.

Traditionally, the Crystal VCL used to require the Name, Driver, Port and Mode properties to be set before it would change the Printer for a Report. With the new Crystal component, however, this is not required. The only property that needs to be specified is the Name. The component will automatically fill in the other values (if the Printer Name is valid), when the component's Execute method is called.

If the Retrieve method is used, the Mode property will contain the Mode value for the Printer that was specified in the Report (or the default printer if the Printer specified in the Report is not valid). Alternatively, the GetCurrent method can be called right after showing Delphi's PrintDialog, and it will also fill the Printer properties with values corresponding to the selected Printer.Methods.

VCL Reference

490

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