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

Example

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

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

{Specify Expression Name - must be same as in Report} Crpe1.SQL.Expressions.Add('Expression1'); Crpe1.SQL.Expressions.Expression.Text := '{fn UCASE(employee.`lastname`)}'; Crpe1.Output := toWindow;

Crpe1.Execute;

{Specify the item number} Crpe1.SQL.Expressions.Delete(0);

SQL Expressions Destroy method

Declaration

destructor Destroy;

Description

The Destroy method is used internally in the Crystal component and does not need to be called in code.

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.

SQL Expressions IndexOf method

Declaration

function IndexOf(ExpressionName: TCrExpressionName): integer;

Type

TCrExpressionName = string;

Description

The IndexOf method takes an Expression name and returns the index position of the Expression item in the current Expressions object.

VCL Reference

630

After the Retrieve method has been called, the Expressions object contains one item for each Expression in the Report. The IndexOf method can be used to determine if a given Expression Name actually exists in the Expressions object before trying to access it.

Example

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

var

nItem: integer; begin

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

{Find a specific Expression}

nItem := Crpe1.SQL.Expressions.IndexOf('Expression1'); {If it exists, change the Expression}

if nItem > -1 then Crpe1.SQL.Expressions[nItem].Expression.Text := '{fn

UCASE(employee.`lastname`)}'; Crpe1.Output := toWindow; Crpe1.Execute;

end;

SQL Expressions Retrieve method

Declaration

function Retrieve: boolean;

Description

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

NOTE: Since the Expressions object also applies to Subreports, the Retrieve method will obtain the Expressions for the Report (or Subreport) that the Subreports object index is currently pointing to. If you want to obtain the Expressions 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 Expressions information for each Subreport (see Example).

Example

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

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

Crpe1.SQL.Expressions.Retrieve;

VCL Reference

631

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.SQL.Expressions.Retrieve; end;

{Set Crpe component back to main Report}

Crpe1.Subreports[0]; end;

SQL Expressions Send method

Declaration

function Send: boolean;

Description

The Send method sends the Expressions values to the Crystal Reports Print Engine. This method is called automatically when the Execute method is called, provided that SendOnExecute is set to True.

It is strongly recommended that you leave SendOnExecute to True, and let the Crystal Reports component send the values to the Print Engine. If you set the SendOnExecute property to False, each Sub-class and each property that does not belong to a Sub-class must be manually sent before calling the Execute method. This feature is mainly provided for debugging purposes.

Example

In this example, the Expressions settings are sent from the Crystal component to the Crystal Reports Print Engine DLL. This is normally handled automatically in the Execute method:

Crpe1.SQL.Expressions.Send;

SQL Params property

Declaration

property Params: TCrpeStoredProcParams;

VCL Reference

632

Type

TCrpeStoredProcParams = class(TPersistent)

Description

NOTE: For SCR 7, Params are now handled through the ParamFields object.

The Params object is a member of the SQL object, and contains all the properties that relate to Stored Procedure Parameters.

The Name property specifies the name of the Parameter.

The Value property specifies the actual value to be passed into the Stored Procedure Parameter. To set a parameter value for the Stored Procedure to NULL, pass the string constant 'CRWNull' to the Value property.

The ParamType property is a read-only property that contains the data type of the Parameter.

The Number property, or the default array property, Item, or the ItemIndex property can be used to navigate through the various Parameters stored in the Params object.

The Retrieve method can be used to get the Params from a Report.

The Count method will indicate how many Parameters are in the Params object.

All Parameter values are stored as string values. To pass a numeric value to the Value property directly, pass the value in quotes like this: '100'. The Crystal Reports Print Engine will treat this as the value 100. To pass other types, either convert them to a string representation, or use one of the properties that can read and write to the Value property using native Delphi types:

AsInteger

AsFloat

AsBoolean

AsDate

NOTE: When passing Boolean parameters, better results will be achieved by using '1' or '0' instead of 'True' or 'False'. The AsBoolean property already does this, so it is only necessary to keep in mind if you are writing directly to the Value property.

Example

In the code following, the Stored Procedure Parameters are first retrieved, then the first and second Params are passed new values:

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

Crpe1.SQL.Params.Retrieve;

Crpe1.SQL.Params[0].Value := '100';

Crpe1.SQL.Params[1].Value := '200';

Crpe1.Execute;

VCL Reference

633

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