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

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;

{Set AreaFormatFormulas to the Details area} Crpe1.AreaFormatFormulas.Section = 'D';

{Set the Details item to the Suppress formula} Crpe1.AreaFormatFormulas.Name := afSuppress; {Assigning the new formula}

Crpe1.AreaFormatFormulas[cnt].Formula.Assign('{company.STATE} = "CA"'); Crpe1.Output := toWindow;

Crpe1.Execute;

AreaFormatFormulas Item property

Declaration

property Item[nIndex: integer]: TCrpeAreaFormatFormulas

Description

The Item property is a default array property. It is read-only, and only available at runtime. It's primary use is to provide an easy way to navigate through the AreaFormatFormulas object, allowing the object to be treated like an array.

Item is a default property, so it does not need to be specified when using the subscript:

AreaFormatFormulas[2] is the same as AreaFormatFormulas.Item[2].

Item returns a reference to itself, so the AreaFormatFormulas properties can be used right after the subscript:

AreaFormatFormulas[2].Section := GH;

Example

Since Item is a default array property, the following two blocks of code do the same thing:

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

{Set AreaFormatFormulas object to the 2nd item} Crpe1.AreaFormatFormulas.Item[1];

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

{Set AreaFormatFormulas object to the 2nd item} Crpe1.AreaFormatFormulas[1];

VCL Reference

230

AreaFormatFormulas ItemIndex property

Declaration

property ItemIndex: integer;

Description

ItemIndex is a Run-time only property which can be used to obtain the current AreaFormatFormulas item number, or set the AreaFormatFormulas object to another item.

Each object in the Crystal component that can contain more than one item uses an internal Index to maintain which item it is currently looking at, similar to the ItemIndex property of a ListBox. This Index is updated whenever the Item property is used (AreaFormatFormulas[2], for example), or whenever the key property (if applicable) is assigned a new lookup value (key properties are things like Formulas.Name, or SortFields.Number which serve as look-up properties).

The easiest way to read the current Index number is to use the ItemIndex property.

Example

The following code illustrates the use of the ItemIndex property to make sure the AreaFormatFormulas object is pointing to the first AreaFormatFormulas item:

if Crpe1.AreaFormatFormulas.ItemIndex <> 0 then Crpe1.AreaFormatFormulas[0];

AreaFormatFormulas Name property

Declaration

property Name: TCrAreaFormatFormula;

Type

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

Description

The Name property specifies which formula name the AreaFormatFormulas object is currently pointing to, and which formula name the Formula property will apply to. These names correspond to the Formula buttons that appear in the SectionFormat dialog in Crystal Reports Designer.

VCL Reference

231

The Retrieve method will obtain the applicable Formula names for each Area Section in the Report.

Name acts as a look up field, so assigning a new value to the Name property will cause that Formula Name (if it exists) to be the currently active one for the AreaFormatFormulas object.

The Names available in a given Area Section are accessible via the Names array property and the NameCount method.

The IndexOfName method will return the index number of a given Formula Name and the NameIndex property will return the index value of the current Formula item. The index number represents the position of that Formula in the Names array, not the position in the AreaFormatFormulas object.

Explanation

After Retrieve has been called the AreaFormatFormulas object contains an item for each Area Section in the Report, and each of these Section items contains an item for each Formula Name available to that Area. To locate a given Formula for a given Area Section, the first step is to navigate the AreaFormatFormulas object to the Section item:

Crpe1.AreaFormatFormulas.Section := 'D'; {or}

{assuming Details is the 4th Section} Crpe1.AreaFormatFormulas[4];

And then navigate the Section to the Formula Name item:

Crpe1.AreaFormatFormulas.Name := afSuppress; {or}

Crpe1.AreaFormatFormulas.Names[0];

The arrangement of Areas and Formulas could be illustrated like this:

Section items

Names items

 

 

 

 

RH

afSuppress

 

 

 

afHide

 

 

 

afNewPageAfter

 

afKeepTogether

 

 

 

afKeepTogether

 

 

 

afResetPageNAfter

 

 

 

afPrintAtBottomOfPage

 

 

PH

afSuppress

 

afResetPageNAfter

 

 

GH1

afSuppress

 

 

 

afHide

 

 

 

afNewPageBefore

VCL Reference

232

Section items

Names items

 

 

 

 

 

afNewPageAfter

 

 

 

afKeepTogether

 

afResetPageNAfter

 

 

 

afPrintAtBottomOfPage

 

 

Limitations

Since some AreaFormat Formula options are not available for certain Sections, it is not wise to assume that each AreaFormatFormula item will have 7 Formulas associated with it. On the contrary, it could have anywhere from 2 to 7 Formulas. For the Main Report, Page Headers (PH) and Page Footers (PF) have only 2 available options. The following chart lists the Sections that have limitations, and which options can have formulas:

x = available

o = not available

Formula Names

RH

RF

PH

PF

 

 

 

 

 

afSuppress

x

x

x

x

 

 

 

 

 

afHide

x

x

o

o

 

 

 

 

 

afNewPageBefore

o

x

o

o

 

 

 

 

 

afNewPageAfter

x

o

o

o

 

 

 

 

 

afKeepTogether

x

x

o

o

 

 

 

 

 

afResetPageNAfter

x

x

x

x

 

 

 

 

 

afPrintAtBottomOfPage

x

x

o

o

 

 

 

 

 

Attempting to set formulas for Sections that do not support that formula will cause errors when the Report is run. To avoid this, the IndexOfName method can be used to determine if a given Formula Name actually exists in the particular Section.

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

VCL Reference

233

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