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

Subreports Section property

Declaration

property Section: string;

Description

The Section property contains the Section name that the current Subreport is located in. For the main Report, this property will be a blank string. It's primary use is to help locate Subreports in a Report, since there is no easy way in the Crystal Reports designer to determine where all the Subreports are located.

If the Retrieve method is used, the Section property is automatically filled when the Subreports are retrieved. The Section property is not used in the internal processing of the VCL so assigning it an new value will not affect the execution of the Report (i.e., it is not possible to move a Subreport to a different section by assigning a new value to the Section property).

The Section name syntax is the same as the Short Section Names used in the Crystal Reports Designer. See

About Section Names, Volume 1, Chapter 7, for more details on the syntax.

Example

The following code fills a list box with all the Subreport Section codes:

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

for cnt := 1 to (Crpe1.Subreports.Count - 1) do ListBox1.Items.Add(Crpe1.Subreports[cnt].Section);

Subreports SubExecute property

Declaration

property SubExecute: boolean;

Description

The SubExecute property determines whether Subreports can be run as individual reports or not. By default this property is set to False.

If the SubExecute property is set to True, then when Crpe1.Execute is called, the current Report will be run. The current Report is the Report that the Subreports object is currently pointing to (whatever was last specified via the Item, ItemIndex, or Name properties). If this happens to be a Subreport, then the Subreport will run as if it were a stand-alone Report.

If the SubExecute property is set to False, then when Crpe1.Execute is called, the main Report will always be run (along with any associated Subreports), regardless of which Report the Subreports object is currently pointing to.

VCL Reference

654

Remarks

Bear in mind that if you set this property to True, and you want to run the main Report, you will need to make sure that the Subreports object is pointing to the main Report before calling Crpe1.Execute, that is:

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

Crpe1.Subreports.Retrieve;

Crpe1.SubReports[1];

{pointing

to Subreport

1}

Crpe1.SubExecute := True;

 

 

 

Crpe1.SubReports[0];

{point to Main Report

before Executing}

Crpe1.Execute;

{Run the

Main Report}

 

Example

The following example will run the first Subreport as a separate Report:

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

Crpe1.Subreports.Retrieve;

Crpe1.Subreports[1];

Crpe1.Subreports.SubExecute := True;

Crpe1.Output := toWindow;

Crpe1.Execute;

The following example will run the main Report in spite of the fact that the Crystal Reports Component is currently pointing to a Subreport:

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

Crpe1.Subreports.Retrieve;

Crpe1.Subreports[1];

Crpe1.Subreports.SubExecute := False;

Crpe1.Execute;

Subreports Methods

Subreports Add method

Declaration

procedure Add(SubName: TCrSubreportName);

Type

TCrSubreportName = string;

VCL Reference

655

Description

The Add and Delete methods provide a manual method of maintaining the Subreport items in the Subreports object. We recommend that you use the Retrieve method instead as it is much easier and less error-prone. The Add method adds an item to the Subreports object and sets the Subreports object index to that item. It requires a valid Subreport name as a parameter.

NOTE: This method will not add a Subreport to a Report; it only works on the VCL's internal data arrays.

Example

This example adds a new Subreport called MySubName to the Subreports object, and then runs the Subreport:

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

{Specify Subreport Name - must be same as in Report} Crpe1.Subreports.Add('SubRpt1'); Crpe1.Subreports.SubExecute := True;

Crpe1.Output := toWindow; Crpe1.Execute;

Subreports Clear method

Declaration

procedure Clear;

Description

The Clear procedure removes any current Subreport information from the VCL. It does not clear the main Report information. To Clear the main Report as well, use the CloseJob method of the TCrpe object:

Crpe1.CloseJob;

or change the ReportName property to a different value (which causes CloseJob to be called):

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

To Clear the main Report and Subreport information, and all of the Window/Printer/Export properties as well, use the Clear method of the TCrpe component:

Crpe1.Clear;

NOTE: It is not normally necessary to call the Subreports Clear method, since this will be called automatically when the ReportName is changed.

VCL Reference

656

Example

This code sets the Subreport Selection Formula, runs the main Report, and then clears all the Subreport information stored in the VCL component:

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

Crpe1.Selection.Formula.Text := '{company.STATE} = "CA"'; Crpe1.Subreports[0];

Crpe1.Output := toWindow; Crpe1.Execute;

{Clear the Subreport information from the VCL} Crpe1.Subreports.Clear;

To clear properties for a specific Subreport only, use the Clear methods for those particular properties. This example clears the Tables object for the second Subreport:

Crpe1.Subreports[2];

Crpe1.Tables.Clear;

Subreports CopyFrom method

Declaration

function CopyFrom(Source: TCrpeSubreports): boolean;

Description

The CopyFrom method copies the Subreports sub-class property values to another TCrpeSubreports object. It is similar to Delphi's Assign method. It is useful for temporary storage of values.

NOTE: This method will not copy all of the other sub-classes of information relating to a particular Subreport, such as Selection, Tables, SortFields, etc. These must be done separately, or via the CopyFrom method for the base TCrpe class.

Example

The following example copies all the Subreports property values to a temporary TCrpeSubreports object:

var

tempSubreports : TCrpeSubreports; begin

tempSubreports := TCrpeSubreports.Create; tempSubreports.CopyFrom(Crpe1.Subreports); {...later, when finished with the temp object...} tempSubreports.Free;

end;

VCL Reference

657

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