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

Example

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

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

Crpe1.SectionHeight.Retrieve;

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.SectionHeight.Retrieve; end;

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

end;

SectionHeight SectionType method

Declaration

function SectionType: string;

Description

The SectionType method returns the Section Code without the subsection specifier. In other words, if the Section Code for an item is GH1ac, the SectionType method would return GH; if the SectionCode is Da, the SectionType method would return D.

The primary use for this method is to apply changes to all the Sections in an area, regardless of the sub-section specifier.

Example

The following example uses the SectionType method to apply conditional formatting. In this case, we only want to change the SectionHeight for the Group Header sections, so the SectionType method can be used in an expression to apply the changes:

var

cnt: integer; begin

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

VCL Reference

594

Crpe1.SectionHeight.Retrieve;

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

{if the SectionType is Group Header, apply the change} if (Crpe1.SectionHeight[cnt].SectionType = 'GH') then

Crpe1.SectionHeight[cnt].Height := 500;

end; end;

SectionHeight Send method

Declaration

function Send: boolean;

Description

The Send method sends the SectionHeight 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 SectionHeight settings are sent from the Crystal component to the Crystal Reports Print Engine DLL. This is normally handled automatically in the Execute method:

Crpe1.SectionHeight.Send;

Selection Properties

Selection Formula property

Declaration

property Formula: TCrpeString;

Type

TCrpeString = class(TStringList)

VCL Reference

595

Description

The Formula property specifies the actual Selection Formula text. Any values in the selection formula that must be seen as strings should be put in double quotes, for example:

Crpe1.Selection.Formula.Text := '{company.STATE} = "CA"';

When the Replace property is set to False, the Selection Formula that is passed in to the Report is appended with a Boolean "AND" to any characters in the Selection Formula currently in the Report. This includes comment lines (any text on a line with two forward slashes in front of it) and existing Selection Formulas. Therefore, care must be taken to make sure the Selection Formula in the Report is valid. When in doubt, use the Retrieve method and build the whole statement in Delphi, then replace the current Selection, by setting Replace to True.

See also Using Variables with Selection Formula, Page 102.

Example

The following example retrieves the current Selection Formula from the Report and adds an OR condition:

Crpe1.ReportName := 'C:\Company.rpt'; {Retrieve the Selection} Crpe1.Selection.Retrieve;

{Add an OR condition}

Crpe1.Selection.Formula.Add(' OR {company.STATE} = "WA"'); {Replace the Selection in the Report with the new one} Crpe1.Selection.Replace := True;

{Check the Selection before running Report} if Crpe1.Selection.Check then

begin

Crpe1.Output := toWindow; Crpe1.Execute;

end;

Selection Replace property

Declaration

property Replace: boolean;

Description

The Replace property determines if the Selection Formula sent from the VCL will replace the one that is already in the Report (if there is one), or if it will be ANDed on to the end.

By default, Replace is set to True.

VCL Reference

596

For example,

¾ If there is a Selection Formula in the Report that reads:

{company.STATE} = "WA"

¾ And there is a Selection Formula in the VCL that reads:

{company.SALES} = 100000

¾ If Replace is True, the Selection Formula in the Report (when it is run) will read:

{company.SALES} = 100000

¾ If Replace is False, the Selection Formula in the Report (when it is run) will read:

{company.STATE} = "WA" AND {company.SALES} = 100000

Example

The following example retrieves the current Selection Formula from the Report and adds an OR condition. It then sends the Formula back in, replacing the one that is currently there:

Crpe1.ReportName := 'C:\Company.rpt'; {Retrieve the Selection} Crpe1.Selection.Retrieve;

{Add an OR condition}

Crpe1.Selection.Formula.Add(' OR {company.STATE} = "WA"'); {Replace the Selection in the Report with the new one} Crpe1.Selection.Replace := True;

{Check the Selection before running Report} if Crpe1.Selection.Check then

begin

Crpe1.Output := toWindow; Crpe1.Execute;

end;

Selection Methods

Selection Check method

Declaration

function Check: boolean;

Description

The Check method can be used to check the syntax of a Selection Formula before running the Report. Check returns a boolean value.

VCL Reference

597

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