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

Description

The OnExecuteEnd event takes place within the Execute method, after the Crystal component values have been sent to the Crystal Reports Print Engine, and after the Report has been run.

See Execute method, Page 142, for a fuller explanation of the order of events.

Example

The following example runs a Report to Window. When the Execute method has finished running the Report, a message is shown:

procedure TForm1.RunReport; begin

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

end;

procedure TForm1.Crpe1OnExecuteEnd(Sender: TObject); begin

ShowMessage('Report was run successfully'); end;

OnFieldMapping event

Declaration

property OnFieldMapping : TCrpeFieldMappingEvent;

Type

TCrpeFieldMappingEvent = procedure(var ReportFields: TList; var DatabaseFields: TList; var Cancel: Boolean) of object;

TCrFieldValueType = (fvUnknown, fvInt8s, fvInt8u, fvInt16s, fvInt16u, fvInt32s, fvInt32u, fvNumber, fvCurrency, fvBoolean, fvDate, fvTime, fvString, fvTransientMemo, fvPersistentMemo, fvBlob, fvDateTime, fvBitmap, fvIcon, fvPicture, fvOle, fvGraph);

TCrFieldMappingInfo = class(TPersistent) public

property TableName : string property FieldName : string

property FieldType : TCrFieldValueType property MapTo : integer

end;

VCL Reference

170

Description

The OnFieldMapping event can be used at runtime to handle remapping of Database Fields whose names have changed since the Report was designed. This event will only be invoked if the FieldMapping property is set to fmEvent, and the VerifyDatabase method has been called. This event passes two TList objects as parameters, and a boolean Cancel parameter.

The two TList objects contain TCrFieldMappingInfo classes, one item in the ReportFields list for each database field used in the Report, and one item in each DatabaseFields list for each database field in the physical table(s). The MapTo property of the TCrFieldMappingInfo class is used to set which ReportField goes with which DatabaseField. Any unmapped ReportFields and DatabaseFields have a MapTo value of -1.

See the Example for more details.

NOTE: The Cancel parameter is not working properly at this time. This is not a problem with the VCL but rather the CRPE32.DLL.

Example

The following example shows how to read the Report and Database fields passed in the OnFieldMapping event. The Table and Field name are attached to the String part of a TStringList, and the Object part of the TStringList contains a pointer to the original TCrFieldMappingInfo class. This kind of handling makes it easy to pass the Table.FieldName strings into a ListBox or ComboBox, if you plan to make your own Mapping Dialog (See the Sample App included with the VCL for a working demonstration of this).

procedure TForm.Crpe1OnFieldMapping(var ReportFields, DatabaseFields: TList; var Cancel: Boolean);

var

 

RptFields

: TCrFieldMappingInfo;

DBFields

: TCrFieldMappingInfo;

slRptFields

: TStringList;

slDBFields

: TStringList;

cnt

: integer;

begin

 

slRptFields := TStringList.Create; slDBFields := TStringList.Create; {Get unmapped ReportFields}

for cnt := 0 to ReportFields.Count - 1 do begin

RptFields := TCrFieldMappingInfo(ReportFields[cnt]); if RptFields.MapTo = -1 then

begin

slRptFields.Add(RptFields.TableName + '.' + RptFields.FieldName); slRptFields.Objects[slRptFields.Count - 1] := ReportFields[cnt];

end; end;

{Get unmapped DatabaseFields}

for cnt := 0 to DatabaseFields.Count - 1 do

VCL Reference

171

begin

DBFields := TCrFieldMappingInfo(DatabaseFields[cnt]); if DBFields.MapTo = -1 then

begin

slDBFields.Add(DBFields.TableName + '.' + DBFields.FieldName); slDBFields.Objects[slDBFields.Count - 1] := DatabaseFields1[cnt]; DBFields.MapTo := cnt;

end; end;

{When you want to map a ReportField to a DatabaseField, you can simply cast the StringList Object back into the TCrFieldMappingInfo variable, and then set the MapTo property}

RptFields := TCrFieldMappingInfo(slRptFields.Objects[x]); DBFields := TCrFieldMappingInfo(slDBFields.Objects[y]); {Set the MapTo number to the Database field item number} RptFields.MapTo := DBFields.MapTo;

{Remember to free the StringLists when done} slRptFields.Free;

slDBFields.Free; end;

OnGetVersion event

Declaration

property OnGetVersion : TCrpeVersionEvent;

Type

TCrpeVersionEvent = procedure(Sender: TObject; var Major, Minor : integer) of object;

Description

The OnGetVersion event allows the developer to over-ride the VCL's built-in version check of the CRPE32.DLL. The VCL does a File Version check on CRPE32.DLL and will not run with anything less than 5.x.x.108 or higher. Normally, over-riding this safety feature would not be a wise thing to do, but we have come across a few variant versions of CRPE32 that have odd version numbers, so this event can be used to handle such circumstances.

The two important parameters are the Major and Minor integers. Major refers to the first number sequence in the File Version, such as 5, 6, or 7. Minor refers to the last number sequence, such as 108, 135, 151, etc. These can be set as desired, and the VCL will then assume that it is dealing with that particular version of CRPE32.DLL.

NOTE: Be careful about setting the Major version too high. If the VCL does not find certain procedures in CRPE32.DLL that it expects to find in a particular version, errors will result.

VCL Reference

172

Example

The following example shows how to over-ride the VCL's version check on CRPE32.DLL using the OnGetVersion event:

procedure TForm.Crpe1OnGetVersion(Sender: TObject; var Major, Minor : integer);

begin

Major := 5; Minor := 108;

end;

OnJobOpened event

Declaration

property OnJobOpened: TCrpeJobNumEvent;

Type

TCrpeJobNumEvent = procedure(Sender: TObject; const JobNum: Word) of object;

Description

The OnJobOpened event occurs when the PrintJob for a Report is opened. The PrintJob is opened when a Report is loaded into the Crystal Reports Print Engine (CRPE32.DLL). This does not occur initially when the ReportName property is set, but happens when any call is made that requires the Report to be loaded into the Print Engine. An example of this type of call would be any of the Retrieve methods, such as Subreports.Retrieve, ParamFields.Retrieve, etc. It is at this point that the JobNumber property will have a meaningful value. Note that it is possible to force the PrintJob open by using the OpenJob method.

The event passes the JobNum variable, which is the internal Job Number that the CRPE assigns to the Job, and which is used as an identifier for all the internal calls made to the CRPE concerning this particular Job. The Job Number is also available via the component's JobNumber property, but in case the component is being created dynamically within a procedure and may not be visible outside of it, the Job Number is passed in the event. The JobNum variable can be used to make direct Print Engine DLL calls, such as are used internally in the component, although care must be taken not to modify the PrintJob properties in such a way that the component may not be aware of the changes.

VCL Reference

173

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