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

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.

Example

The SectionAsCode property can be used to apply formula-based 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 according to a formula:

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

Crpe1.SectionFormatFormulas.Retrieve;

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

if (Crpe1.SectionFormatFormulas[cnt].SectionAsCode mod 1000 = 25) then

begin

Crpe1.SectionFormatFormulas[cnt].Name := sfBackgroundColor; Crpe1.SectionFormatFormulas[cnt].Formula.Text := '{company.STATE}

= "CA"';

end; end;

Crpe1.Output := toWindow; Crpe1.Execute;

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 formula also works for Sections that do not have Group options, such as Details (Da = 4000, Db = 4025, etc.).

SectionFormatFormulas Methods

SectionFormatFormulas Add method

Declaration

procedure Add(SectionName: TCrSectionFormatFormulasSection);

VCL Reference

574

Type

TCrSectionFormatFormulasSection = string;

Description

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

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

2Specify values for the properties (Name, Formula, etc.).

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.

SectionFormatFormulas Check method

Declaration

function Check: boolean;

Description

The Check method can be used to check the syntax of a SectionFormatFormula while running the Report. Check returns a boolean value:

Returns

TRUE if the SectionFormat Formula is good.

FALSE if the SectionFormat Formula has an error.

NOTE: At this time, the error will not be returned until the report is run. Prior to running the report, this method will return TRUE.

SectionFormatFormulas Clear method

Declaration

procedure Clear;

VCL Reference

575

Description

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

Example

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

Crpe1.SectionFormatFormulas.Clear;

This code clears the SectionFormatFormulas for all the Subreports:

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

Crpe1.Subreports[cnt];

Crpe1.SectionFormatFormulas.Clear; end;

SectionFormatFormulas CopyFrom method

Declaration

function CopyFrom(Source: TCrpeSectionFormatFormulas): boolean;

Description

The CopyFrom method copies the SectionFormatFormulas property values from another TCrpeSectionFormatFormulas 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 SectionFormatFormulas property values to a temporary TCrpeSectionFormatFormulas object:

var

tempSectionFormatFormulas : TCrpeSectionFormatFormulas ; begin

tempSectionFormatFormulas := TCrpeSectionFormatFormulas.Create; tempSectionFormatFormulas .CopyFrom(Crpe1.SectionFormatFormulas); {...later, when finished with the temp object...} tempSectionFormatFormulas .Free;

end;

VCL Reference

576

SectionFormatFormulas Count method

Declaration

function Count: integer;

Description

The Count method can be used to obtain the number of items currently in the SectionFormatFormulas 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.SectionFormatFormulas.Retrieve;

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

Crpe1.SectionFormatFormulas[cnt].Name := sfKeepTogether; Crpe1.SectionFormatFormulas[cnt].Formula.Text := 'True';

end;

Crpe1.Output := toWindow; Crpe1.Execute;

end;

SectionFormatFormulas Create method

Declaration

constructor Create;

Description

The Create constructor creates the SectionFormatFormulas object. It is used internally in the VCL component to create the SectionFormatFormulas object when the component is created, and should not be called outside of the component.

VCL Reference

577

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