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

SectionFormat SuppressBlankSection property

Declaration

property SuppressBlankSection: TCrBoolean;

Type

TCrBoolean = (cFalse, cTrue, cDefault);

Description

SuppressBlankSection determines whether the specified Section will be suppressed if it is blank. A Section must be completely empty before it will be suppressed. Fields that have empty strings or nulls will be counted as empty, but if they have even so little as a space for a value, they will not be counted as empty.

Example

The code below retrieves the SectionFormat settings from the Report, then loops through looking for the Details "a" section, and sets the SuppressBlankSection option for that section:

var

cnt: integer; begin

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

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

{Look for Details "a" section}

if Crpe1.SectionFormat[cnt].Section = 'Da' then Crpe1.SectionFormat[cnt].SuppressBlankSection := cTrue;

end;

Crpe1.Output := toWindow; Crpe1.Execute;

end;

SectionFormat UnderlaySection property

Declaration

property UnderlaySection: TCrBoolean;

Type

TCrBoolean = (cFalse, cTrue, cDefault);

VCL Reference

556

Description

UnderlaySection determines if the specified Section will print underneath the following Section, like a transparency.

Example

The code below retrieves the SectionFormat settings from the Report, then loops through looking for the Details "a" section, and sets the UnderlaySection option for that section:

var

cnt: integer; begin

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

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

{Look for Details "a" section}

if Crpe1.SectionFormat[cnt].Section = 'Da' then Crpe1.SectionFormat[cnt].UnderlaySection := cTrue;

end;

Crpe1.Output := toWindow; Crpe1.Execute;

end;

SectionFormat SectionAsCode property

Declaration

property SectionAsCode: smallint

Description

The SectionAsCode property can be used to read and write the Section property via Print Engine Section Code numbers. Since the Print Engine Section Codes are numeric, it is easier to apply conditional formatting to certain sections (in a "For loop", for example) based on mathematical calculations on the Section Code number than it is by parsing out the regular Section Code string (GH1b, etc.).

See also: About Section Names, Volume 1, Chapter 7.

VCL Reference

557

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 "b" section, such as RHb, PHb, Db, etc., and if it is, the background color is changed to red:

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

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

if (Crpe1.SectionFormat[cnt].SectionAsCode mod 1000 = 25) then Crpe1.SectionFormat[cnt].BackgroundColor := clRed;

end; Crpe1.Execute;0

The logic behind the math expression is based on the fact that each sub-section increments the Section Code number by 25 (from 0 to 975 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 1a, 3025 represents GroupHeader 1b, 3050 represents GroupHeader 1c, etc. Therefore, in order to find the "b" sections we must divide by 1000, and if the remainder is 25, it is a "b" section. This also works for all the other sections that do not have Group options, such as Details, ReportHeader, etc. since dividing by 25 will also return no remainder if the Section Code number is evenly divisible by 1000.

SectionFormat Methods

SectionFormat Add method

Declaration

procedure Add(SectionName: TCrSectionFormatSection);

Type

TCrSectionFormatSection = string;

Description

The Add method adds an item to the SectionFormat 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 SectionFormat are:

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

VCL Reference

558

2Fill the item's properties (NewPageAfter, SuppressBlankSection, 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.

Example

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

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

{Specify Section Name - must be same as in Report} Crpe1.SectionFormat.Add('Da'); Crpe1.SectionFormat.BackgroundColor := clRed; Crpe1.Output := toWindow;

Crpe1.Execute;

SectionFormat Clear method

Declaration

procedure Clear;

Description

This method can be used to clear the internal memory of the SectionFormat 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 method is only applied to the SectionFormat object of the current Report/Subreport specified in the Subreports object. Therefore, to clear all the SectionFormat of all the Subreports will require a looping procedure that goes through each Subreport and applies the Clear method.

Example

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

Crpe1.SectionFormat.Clear;

This code clears the SectionFormat properties for all the Subreports:

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

Crpe1.Subreports[cnt];

Crpe1.SectionFormat.Clear; end;

VCL Reference

559

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