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

Example

The Delete method can be used to manually remove an item from the AreaFormatFormulas object:

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

{Specify Section Name - must be same as in Report} Crpe1.AreaFormatFormulas.Add('PH'); Crpe1.AreaFormatFormulas.Name := afSuppress; Crpe1.AreaFormatFormulas.Formula.Text := 'True'; Crpe1.Output := toWindow;

Crpe1.Execute;

Crpe1.AreaFormatFormulas.Delete(0);

AreaFormatFormulas Destroy method

Declaration

destructor Destroy; override;

Description

The Destroy method frees the AreaFormatFormulas object. It is used internally in the VCL component to destroy the AreaFormatFormulas object when the component is destroyed, and should not be called outside of the component.

NOTE: The TCrpe component is responsible for creating and freeing all of the sub-classes that belong to it. The only time you would want to be concerned with doing this is if you are creating a temporary object to store data from the TCrpe using the CopyFrom method that is available from the sub-class or the CopyFrom method that is available from the main TCrpe class.

AreaFormatFormulas IndexOf method

Declaration

function IndexOf(SectionName: TCrAreaFormatFormulasSection): integer;

Type

TCrAreaFormatFormulasSection = string;

Description

The IndexOf method takes a Section name and returns the index position of the Section item in the current AreaFormatFormulas object.

VCL Reference

242

After the Retrieve method has been called, the AreaFormatFormulas object contains one item for each Area in the Report. This could be illustrated like so (the Section items in your Reports may not be the same):

Section items:

RH

PH

GH1

GH2

D

GF2

GF1

PF

RF

The IndexOf method can be used to determine if a given Section Name actually exists in the AreaFormatFormulas object before trying to access it.

Example

The following code illustrates the use of the IndexOf method to locate a specific AreaFormatFormula item by it's Area name:

var

nItem: integer; begin

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.AreaFormatFormulas.Retrieve; {Find Details area}

nItem := Crpe1.AreaFormatFormulas.IndexOf('D'); {If it exists...}

if nItem > -1 then begin

with Crpe1.AreaFormatFormulas[nItem] do begin

{Suppress area if STATE is California} Name := afSuppress;

Formula.Text := '{company.STATE} = "CA"'; end;

end;

Crpe1.Output := toWindow; Crpe1.Execute;

end;

VCL Reference

243

AreaFormatFormulas IndexOfName method

Declaration

function IndexOfName(FormulaName: TCrAreaFormatFormula): integer;

Type

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

Description

The IndexOfName method takes an AreaFormatFormula name and returns the index position of the Formula item in the current Area item of the AreaFormatFormulas object. See the explanation of the Name property for more details.

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

 

 

Example

This example uses the IndexOfName method to update a ListBox of Formula Names for the Details Area:

var

nItem: integer; begin

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

{Set AreaFormatFormulas object to Details item} Crpe1.AreaFormatFormulas.Section := 'D';

VCL Reference

244

{Loop through and get formula names}

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

case Ord(Crpe1.AreaFormatFormulas.Names[cnt]) of

0:ListBox1.Items.Add('Suppress');

1:ListBox1.Items.Add('Hide');

2:ListBox1.Items.Add('NewPageBefore');

3:ListBox1.Items.Add('NewPageAfter');

4:ListBox1.Items.Add('KeepTogether');

5:ListBox1.Items.Add('ResetPageNAfter');

6:ListBox1.Items.Add('PrintAtBottomOfPage');

end;

end;

{Set Formulas Index to NewPageBefore} Crpe1.AreaFormatFormulas.Name := afNewPageBefore; {Get Index number}

nItem := Crpe1.AreaFormatFormulas.IndexOfName(afNewPageBefore); {Update ListBox with Index}

ListBox1.ItemIndex := nItem;

AreaFormatFormulas NameCount method

Declaration

function NameCount: integer;

Description

The NameCount property returns the number of Formula Names available for a specific Section. NameCount can be used with the Names property in a looping construct, to step through the Formula Name items.

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

245

Example

The NameCount method is used in the example below, to loop through the Formula items for the Page Header section, sending the Formula names to a ListBox:

var

cnt: integer; begin

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

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

case Ord(Crpe1.AreaFormatFormulas.Names[cnt]) of

0:ListBox1.Items.Add('afHide');

1:ListBox1.Items.Add('afSuppress');

2:ListBox1.Items.Add('afPrintAtBottomOfPage');

3:ListBox1.Items.Add('afNewPageBefore');

4:ListBox1.Items.Add('afNewPageAfter');

5:ListBox1.Items.Add('afResetPageNAfter');

6:ListBox1.Items.Add('afKeepTogether');

end; end;

end;

AreaFormatFormulas Retrieve method

Declaration

function Retrieve: boolean;

Description

The Retrieve method obtains the AreaFormatFormulas from the Report and stores them in the AreaFormatFormulas object. If AreaFormatFormulas information was not found, the call returns False. Be aware that calling Retrieve will first cause the AreaFormatFormulas object to be cleared, so any current information stored in it will be removed.

NOTE: Since the AreaFormatFormulas object also applies to Subreports, the Retrieve method will obtain the AreaFormatFormulas for the Report (or Subreport) that the Subreports object index is currently pointing to. If you want to obtain the AreaFormatFormulas information for the main Report and all of the Subreports, you will have to step through the Subreports object and call Retrieve for each item. The VCL will store separate AreaFormatFormulas information for each Subreport (see Example).

VCL Reference

246

Example

The following code illustrates the use of the Retrieve method for the main Report:

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

Crpe1.AreaFormatFormulas.Retrieve;

The following code illustrates the use of the Retrieve method for the main Report and any Subreports:

var

cnt: integer; begin

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

{Loop through Reports and Retrieve}

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

Crpe1.Subreports[cnt];

Crpe1.AreaFormatFormulas.Retrieve; end;

{Set Crpe component back to main Report} Crpe1.Subreports[0];

end;

AreaFormatFormulas SectionType method

Declaration

function SectionType: string;

Description

The SectionType method returns the Section Code without the subsection specifier. In other words, if the Section Code for an item is GH1, the SectionType method would return GH.

This method can be used to apply formatting to all the Groups in a Report regardless of their level number. See the Example for an illustration.

Example

The following example uses the SectionType method to apply conditional formatting. The formatting is to apply to all Group Header areas, so the SectionType method can be used in an expression to apply the changes:

var

cnt: integer; begin

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

VCL Reference

247

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