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

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

 

 

Lower-case letters: a, b, c, etc. are used to specify sub-sections. Numbers are used to designate different Groups: GH1, GF2, etc. See About Section Names, Volume 1, Chapter 7, for more details on the syntax.

Example

The sample code applies a change only to those Graphs which are located in Group Header 1 (GH1):

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

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

if Crpe1.GraphData[cnt].Section = 'GH1' then Crpe1.GraphData[cnt].SummarizedFieldN := 2;

end;

Crpe1.Output := toWindow; Crpe1.Execute;

GraphData 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

306

Example

The following example uses the SectionAsCode property to apply conditional changes to a Graph. In this case, there is a Graph in each of three Group Header sections (GH1a, GH2a, GH3a). Since the Section Code for GH1a is 3000, GH2a is 3001, and GH3a is 3002, it is possible to do a simple mathematical calculation on the remainder of the Section Code divided by 1000 to change the style of the Graph only if it is in GH1:

var

cnt: integer; begin

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

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

{if the remainder of the SectionCode divided by 1000 is greater than zero, then apply the change}

if (Crpe1.GraphData[cnt].SectionAsCode mod 1000 = 0) then Crpe1.GraphData[cnt].SummarizedFieldN := 1;

end; end;

GraphData SummarizedFieldN property

Declaration

property SummarizedFieldN: smallint;

Description

The SummarizedFieldN property specifies which Summary field in the report is used to set the values of the Risers in the Graph.

Summary fields are numbered in order of their creation.

Summary Field numbers start with 0.

Use -1 for default (no change).

Example

The sample code below illustrates the use of the GraphData object to change the Summary Field that the Graph is based on:

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

if Crpe1.GraphData.Count > 0 then Crpe1.GraphData[0].SummarizedFieldN := 2;

Crpe1.Output := toWindow; Crpe1.Execute;

VCL Reference

307

GraphData Methods

GraphData Add method

Declaration

procedure Add(GraphNumber: TCrGraphDataNumber);

Type

TCrGraphDataNumber = integer;

Description

The Add method adds an item to the GraphData object and sets the internal index to that item. It requires a Graph number as a parameter, which should be a number corresponding to a Graph in the Report. Graphs are numbered starting from zero, from the top of the Report down, and left to right in each Section. If the Add method is used, the steps to using GraphData are:

1Add an item to the GraphData object (you must specify the Graph number).

2Fill the item's properties (ColGroupN, RowGroupN, 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 Graph numbers are correct for the current Report.

Example

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

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

{Specify Graph Number - must be same as in Report} Crpe1.GraphData.Add(0);

{Section must also be specified when using Add} Crpe1.GraphData.Section := 'PH'; Crpe1.GraphData.SummarizedFieldN := 2; Crpe1.Output := toWindow;

Crpe1.Execute;

GraphData Clear method

Declaration

procedure Clear;

VCL Reference

308

Description

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

Example

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

Crpe1.GraphData.Clear;

This code clears the GraphData properties for all the Subreports:

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

Crpe1.Subreports[cnt];

Crpe1.GraphData.Clear; end;

GraphData CopyFrom method

Declaration

function CopyFrom(Source: TCrpeGraphData): boolean;

Description

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

var

tempGraphData : TCrpeGraphData; begin

tempGraphData := TCrpeGraphData.Create; tempGraphData.CopyFrom(Crpe1.GraphData); {...later, when finished with the temp object...} tempGraphData.Free;

end;

VCL Reference

309

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