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

It also sets the following properties to default:

CanCloseEngine := True;

DiscardSavedData := False;

HasSavedData := False;

IsJobFinished := True;

Output := toWindow;

ProgressDialog := True;

ReportName := '';

SendOnExecute := True;

WindowEvents := False;

WindowState := wsNormal;

Finally, it de-allocates any memory associated with the above classes and then closes the PrintJob. There are some alternatives if the programmer does not want to clear all of these properties:

1.To clear just the Subreport structures, while leaving the main Report information intact, use Subreports.Clear.

2.To clear the Subreport and main Report structures, while leaving the Window, Printer, and Export related classes as they are, use CloseJob.

When a new Report is assigned to the ReportName property, a CloseJob call is invoked, not a Clear. Thus the Window, Printer, and Export related settings are preserved. The only time the Clear method is called internally in the component is when it is destroyed. However, if it is desired to have all the settings of the component returned to default, the Clear method can be called before setting a new ReportName.

Example

The following example loads a Report and runs it. When the Report has finished, the Crystal component is cleared to set everything back to default, and another Report is loaded:

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

while not Crpe1.PrintEnded do Application.ProcessMessages;

Crpe1.Clear;

Crpe1.ReportName := 'C:\NewReport.rpt';

Create method

Declaration

constructor Create(AOwner: TComponent); override;

Description

The Create method is called when the Crystal component is created.

If the component is attached to a Form, the Create method is called automatically when the Form is created.

If the component is being created dynamically, then the Create method must be called in code (see Example).

VCL Reference

135

Example

The following code illustrates how to create the Crystal component dynamically:

uses Ucrpe32;

procedure RunReport; var

Crpe1: TCrpe; begin

{Create the Crpe instance} Crpe1 := TCrpe.Create(Self); {Set the ReportName}

Crpe1.ReportName := 'MyReport.rpt'; {Run the Report}

Crpe1.Execute;

{Go into a loop until the window is closed} while Crpe1.ReportWindowHandle <> 0 do

Application.ProcessMessages;

{Remove the Crpe instance from memory} Crpe1.Free;

end;

CloseEngine method

Declaration

procedure CloseEngine;

Description

CloseEngine causes any open Print Job to be closed, closes the Crystal Reports Print Engine DLL, and removes it from memory. It usually happens automatically when the component is destroyed, or the Form on which the component is attached is destroyed, but can also be called in code if desired.

Example

The following example uses the CloseEngine method to unload the CRPE32.DLL after running a Report:

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

while not Crpe1.PrintEnded do Application.ProcessMessages;

if Crpe1.CanCloseEngine then Crpe1.CloseEngine;

VCL Reference

136

CloseJob method

Declaration

procedure CloseJob;

Description

CloseJob closes the currently open Report in the Print Engine, and clears any memory allocated for it in the Crystal component. This will not close a currently open Preview Window, but no further calls can be made from the component to the window. If you want to close the Window, see the CloseWindow method.

CloseJob automatically takes place when the ReportName property is assigned a different Report name, or when the Crystal component is destroyed, but can also be called in code if desired.

Example

The following example uses the CloseJob method to close the Print Job after running a Report:

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

while not Crpe1.PrintEnded do Application.ProcessMessages;

Crpe1.CloseJob;

CloseWindow method

Declaration

procedure CloseWindow;

Description

The CloseWindow method closes an open Preview Window. It does not Close the PrintJob, nor does it clear the component. If you are customizing Preview Window controls, implement this method to allow the user to close the Preview Window when finished viewing the Report.

Although it is possible to open up more than one Preview Window for the same PrintJob, the VCL can only access the last one opened, hence CloseWindow will only work on the last window opened. If you need to close more than one open Preview Window, consider storing the Window Handles to variables and using the Windows API call "CloseWindow" to close these.

VCL Reference

137

Example

The following example runs a Report to Window. When a button on the application is pressed, the Window is closed:

Crpe1.ReportName := 'MyReport.rpt';

Crpe1.Output := toWindow;

Crpe1.Execute

{When a close button is pressed do...} if Crpe1.ReportWindowHandle > 0 then

Crpe1.CloseWindow;

CopyFrom method

Declaration

function CopyFrom(Source: TCrpe): boolean;

Description

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

Example

The following example copies all the Component values to a temporary TCrpe object:

var

tempCrpe : TCrpe; begin

tempCrpe := TCrpe.Create; tempCrpe.CopyFrom(Crpe1);

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

end;

DateTimeToStr method

Declaration

function DateTimeToStr(const dtValue: TDateTime; bMSec: Boolean): string;

VCL Reference

138

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