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

{Check for Details area}

if Crpe1.AreaFormatFormulas[cnt].Section = 'D' then begin

{Choose the Suppress formula} Crpe1.AreaFormatFormulas[cnt].Name := afSuppress; {Clear it from any previous formula} Crpe1.AreaFormatFormulas[cnt].Formula.Clear;

{Add the new formula} Crpe1.AreaFormatFormulas[cnt].Formula.Add('{company.STATE} = "CA"'); Break;

end; end;

Crpe1.Execute;

AreaFormatFormulas NameIndex Property

Declaration

property NameIndex: integer

Description

The NameIndex property is a run-time only property which can be used to obtain the current Formula Name item number, or set the Formula Name list to another item.

Comparison of Properties for Section Items and Name Items

The AreaFormatFormulas object contains an internal Index which determines which Area item it is currently looking at. This index is changed via the Section, Item, and ItemIndex properties, and can be read via the IndexOf method.

Likewise, since each Area contains numerous Formula Name items, these are controlled via a secondary internal Index which is changed via the Name, Names, and NameIndex properties, and can be read via the IndexOfName method.

Sections

Names

 

 

 

 

Section

Name

Item

Names

 

 

ItemIndex

NameIndex

 

 

IndexOf

IndexOfName

 

 

Count

NameCount

 

 

VCL Reference

234

Example

This example checks the NameIndex of the Formula names list and sets it to the first item if it is not currently pointing to that item:

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

if Crpe1.AreaFormatFormulas[0].NameIndex <> 0 then Crpe1.AreaFormatFormulas[0].NameIndex := 0;

AreaFormatFormulas Names Property

Declaration

property Names[nIndex: integer]: TCrAreaFormatFormula

Type

TCrAreaFormatFormula = (afHide, afSuppress, afPrintAtBottomOfPage, afNewPageBefore, afNewPageAfter, afResetPageNAfter, afKeepTogether);

Description

The Names property can be used to step through the Formula Name items of an AreaFormatFormulas item by numerical subscript. It is useful in looping constructs, to gather all the Formula Names that apply to a particular Section. In this case, it should be used along with the NameCount method, to avoid a "Subscript out of bounds" error.

Comparison of Properties for Section Items and Name Items:

The AreaFormatFormulas object contains an internal Index which determines which Area item it is currently looking at. This index is changed via the Section, Item, and ItemIndex properties, and can be read via the IndexOf method.

Likewise, since each Area contains numerous Formula Name items, these are controlled via a secondary internal Index which is changed via the Name, Names, and NameIndex properties, and can be read via the IndexOfName method.

AreaFormatFormulas Section property:

Sections

Names

 

 

 

 

Section

Name

 

 

Item

Names

 

 

ItemIndex

NameIndex

IndexOf

IndexOfName

 

 

Count

NameCount

 

 

VCL Reference

235

Declaration

property Section: TCrAreaFormatFormulasSection;

Type

TCrAreaFormatFormulasSection = string;

Description

The Section property specifies the Section name that the AreaFormatFormulas object is currently pointed to. The property acts as a look-up, to point the AreaFormatFormulas object to the item with the Section specified.

If the Retrieve method is used, the Section property is automatically filled when the AreaFormatFormulas are retrieved. The IndexOf method can be used to locate an AreaFormatFormula item with a specific Section name.

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

RH - Report Header

PH - Page Header

GH - Group Header

D - Details

GF - Group Footer

PF - Page Footer

RF - Report Footer

Numbers are used to designate different Groups: GH1, GF2, etc. See About Section Names, Volume 1, Chapter 7, for more details on the syntax.

NOTE: Whereas objects such as SectionFormat and SectionFormatFormulas work on specific individual subsections, such as Details "a", Details "b", etc., AreaFormat and AreaFormatFormulas work on certain areas, for example, Details area. The options set in these objects affect all the sub-sections of that Area as a unit.

Example

This example retrieves the AreaFormatFormula information, then assigns a Suppress formula to the Details area, so that the Details area will be suppressed if the State is California:

Crpe1.ReportName := 'Company.rpt';

Crpe1.AreaFormatFormulas.Retrieve; {Loop through the Areas}

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

{Check for Details area}

if Crpe1.AreaFormatFormulas[cnt].Section = 'D' then begin

{Choose the Suppress formula} Crpe1.AreaFormatFormulas[cnt].Name := afSuppress; {Clear it from any previous formula} Crpe1.AreaFormatFormulas[cnt].Formula.Clear;

VCL Reference

236

{Add the new formula} Crpe1.AreaFormatFormulas[cnt].Formula.Add('{company.STATE} = "CA"'); Break;

end; end;

Crpe1.Execute;

AreaFormatFormulas 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 (GH1, 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 Group section greater than 1, such as GH2, GH3, etc., and if it is, the Area is suppressed conditionally:

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

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

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

Crpe1.AreaFormatFormulas[cnt].Name := afSuppress; Crpe1.AreaFormatFormulas[cnt].Formula.Text := '{company.STATE} = "CA"';

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

VCL Reference

237

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