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

Description

The Add method adds an item to the Formulas object and sets the internal index to that item. It requires a Formula name as a parameter, which should be a name corresponding to a Formula in the Report. Formula Names are expressed as they are written in Crystal Reports, but without the "@" symbol that gets added when they are used within other Formulas. If the Add method is used, the steps to using Formulas are:

1Add an item to the Formulas object (you must specify the Formula name).

2Fill the Text property with a formula.

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 Formula names are correct for the current Report.

Example

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

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

{Specify Formula Name - must be same as in Report} Crpe1.Formulas.Add('Formula2'); Crpe1.Formulas.Formula.Text := '2001'; Crpe1.Output := toWindow;

Crpe1.Execute;

Formulas Check method

Declaration

function Check: boolean;

Description

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

True

:Formula is good.

False

:Formula has an error.

VCL Reference

294

Example

The following code loops through all the Formulas, checking each one:

var

cnt: integer; begin

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

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

if not Crpe1.Formulas[cnt].Check then ShowMessage('Error in Formula #' + IntToStr(cnt));

end;

end;

Formulas Clear method

Declaration

procedure Clear;

Description

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

Example

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

Crpe1.Formulas.Clear;

This code clears the Formulas properties for all the Subreports:

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

Crpe1.Subreports[cnt];

Crpe1.Formulas.Clear; end;

VCL Reference

295

Formulas CopyFrom method

Declaration

function CopyFrom(Source: TCrpeFormulas): boolean;

Description

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

var

tempFormulas : TCrpeFormulas; begin

tempFormulas := TCrpeFormulas.Create; tempFormulas.CopyFrom(Crpe1.Formulas);

{...later, when finished with the temp object...} tempFormulas.Free;

end;

Formulas Count method

Declaration

function Count: integer;

Description

The Count method can be used to obtain the number of items currently in the Formulas object. It is handy for setting up loops to make similar changes to each item.

VCL Reference

296

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.Formulas.Retrieve;

for cnt := 0 to (Crpe1.Formulas.Count - 1) do Crpe1.Formulas[cnt].Formula.Text := '2001';

end;

Formulas Create method

Declaration

constructor Create;

Description

The Create method is used internally in the Crystal component to create the Formulas object, and does not need to be called in code.

Formulas Delete method

Declaration

procedure Delete(nIndex: integer);

Description

The Delete method can be used to remove an item from the Formulas object. The "nIndex" parameter represents the number of the item in the Formulas object.

NOTE: Delete will not remove the Formula from the Report, it will just remove it from the Crystal VCL.

VCL Reference

297

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