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

Example

The SectionAsCode property can be used to apply formatting to specific sections based on mathematical calculations or comparisons. The following code checks each section to see if it is a Group section greater than 1, such as GH2, GH3, etc., and if it is, the Area is suppressed:

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

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

if (Crpe1.AreaFormat[cnt].SectionAsCode mod 1000 > 0) then

Crpe1.AreaFormat[cnt].Suppress := cTrue;

end; Crpe1.Execute;

The logic behind the math expression is based on the fact that each group-area increments the Section Code number by 1 (from 0 to 24 are the possible numbers). So, since 3000 is the general Section Code start number for a Group Header, and is therefore the number to represent GroupHeader 1, 3001 represents GroupHeader 2, 3002 represents GroupHeader 3, etc. Dividing by 1000 will only give a remainder for those Groups that are greater than 1.

AreaFormat Suppress property

Declaration

property Suppress: TCrBoolean;

Type

TCrBoolean = (cFalse, cTrue, cDefault);

Description

Suppress determines if the specified Area will show or not. A suppressed section is not available for drilldown in the Preview Window (the drill-down options are specified in the WindowButtonBar object). To hide an Area so that it is still available for drill-down, use the Hide property.

VCL Reference

222

Example

The code below retrieves the AreaFormat settings from the Report, then loops through looking for the Details area, and sets the Suppress option for that area:

var

cnt: integer; begin

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

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

{Look for Details area}

if Crpe1.AreaFormat[cnt].Section = 'D' then Crpe1.AreaFormat[cnt].Suppress := cTrue; end;

Crpe1.Output := toWindow; Crpe1.Execute;

end;

AreaFormat Methods

AreaFormat Add method

Declaration

procedure Add(SectionName: TCrAreaFormatSection);

Type

TCrAreaFormatSection = string;

Description

The Add method adds an item to the AreaFormat object and sets the internal index to that item. It requires a Section name as a parameter, which should be a name corresponding to a Section in the Report. Sections are named using the Short Section Name convention used in Crystal Reports. See About Section Names, Volume 1, Chapter 7, for more information. If the Add method is used, the steps to using AreaFormat are:

1Add an item to the AreaFormat object (you must specify the Section name).

2Fill the item's properties (KeepTogether, Suppress, etc.) with values.

3When Execute is called, the properties will be sent to the Print Engine.

NOTE: It is easier to use the Retrieve method instead of Add, since it ensures that the number of items, and the Section names are correct for the current Report.

VCL Reference

223

Example

The Add method can be used to manually add an item to the AreaFormat object, instead of using Retrieve:

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

{Specify Section Name - must be same as in Report} Crpe1.AreaFormat.Add('D'); Crpe1.AreaFormat.KeepTogether := cTrue; Crpe1.Output := toWindow;

Crpe1.Execute;

AreaFormat Clear method

Declaration

procedure Clear;

Description

This method can be used to clear the internal memory of the AreaFormat object. It is called automatically if the Clear method is called for the main component, or if a new Report name is assigned to the ReportName property, but may be called in code as desired.

The Clear is only applied to the AreaFormat object of the current Report/Subreport specified in the Subreports object. Therefore, to clear all the AreaFormat of all the Subreports will require a looping procedure that goes through each Subreport and applies the Clear.

Example

This code clears the AreaFormat properties for the main Report (assuming the default state of Subreports[0]):

Crpe1.AreaFormat.Clear;

This code clears the AreaFormat properties for all the Subreports:

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

Crpe1.Subreports[cnt];

Crpe1.AreaFormat.Clear; end;

VCL Reference

224

AreaFormat CopyFrom method

Declaration

function CopyFrom(Source: TCrpeAreaFormat): boolean;

Description

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

Example

The following example copies all the AreaFormat property values to a temporary TCrpeAreaFormat object:

var

tempAreaFormat : TCrpeAreaFormat; begin

tempAreaFormat := TCrpeAreaFormat.Create; tempAreaFormat.CopyFrom(Crpe1.Version); {...later, when finished with the temp object...} tempAreaFormat.Free;

end;

AreaFormat Count method

Declaration

function Count: integer;

Description

The Count method can be used to obtain the number of items currently in the AreaFormat object. It is handy for setting up loops to make similar changes to each item.

Example

The Count method is useful for looping constructions. You would normally want to call Retrieve first:

var

cnt: integer; begin

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

for cnt := 0 to (Crpe1.AreaFormat.Count - 1) do Crpe1.AreaFormat[cnt].KeepTogether := cTrue;

end;

VCL Reference

225

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