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

SQL Properties

SQL Expressions property

Declaration

property Expressions : TCrpeSQLExpressions;

Type

TCrpeSQLExpressions = class(TPersistent)

Description

Only available with SCR 7 and higher. The Expressions object contains all the properties that apply to SQL Expressions in a Report.

The Name property specifies the Name of the Expression.

The Expression property holds the Expression text.

The default array property Item, and the ItemIndex property, can be used to navigate through the various Expressions that may be stored in the Expressions object.

Expressions may be retrieved from the Report via the Retrieve method.

The Add / Delete methods can be used instead of Retrieve/Clear to manually add and remove items in the Expressions object.

The Check method provides an easy way of checking the syntax of the Expression text before running the Report.

SQL Expressions are similar to Crystal Reports Formulas, except that they use SQL syntax, and are processed on the Server (whenever possible).

Example

The following code retrieves the Expressions from a Report, and sets the first one:

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

{Assign a new expression to the Expression property} Crpe1.SQL.Expressions[0].Expression.Text := '{fn RTRIM(company.`name`)}'; Crpe1.Output := toWindow;

Crpe1.Execute;

VCL Reference

622

SQL Expressions Expression property

Declaration

property Expression: TCrpeString;

Type

TCrpeString = class(TStringList)

Description

The Expression property contains the actual text of the Expression. To assign a new value to the Expression property, any of the following methods can be used (or any other method that is valid for a StringList):

1.Crpe1.SQL.Expressions.Expression.Assign('{fn UCASE(table.`lastname`)}');

2.Crpe1.SQL.Expressions.Expression.Text := '{fn UCASE(table.`lastname`)}';

3.Crpe1.SQL.Expressions.Expression.Clear; Crpe1.SQL.Expressions.Expression[0] := '{fn UCASE(table.`lastname`)}';

4.Crpe1.SQL.Expressions.Expression.SetText(PChar('{fn UCASE(table.`lastname`)}'));

The new Expression string must conform to SQL syntax requirements.

Example

The following code shows how the Expression property is used to store a new expression:

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

Crpe1.SQL.Expressions.Retrieve;

Crpe1.SQL.Expressions[0].Expression.Assign('{fn

UCASE(employee.`lastname`)}');

Crpe1.Output := toWindow;

Crpe1.Execute;

SQL Expressions Item property

Declaration

property Item[const nIndex: integer]: TCrpeSQLExpressions;

VCL Reference

623

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 various items stored in the Expressions 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: Expressions[2] is the same as Expressions.Item[2].

Item returns a reference to itself, so the Expressions properties can be used right after the subscript: Expressions[2].Name := 'Expression1';

Example

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

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

{Set Expressions to the 3rd Expression} Crpe1.SQL.Expressions.Item[2];

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

{Set Expressions to the 3rd Expression} Crpe1.SQL.Expressions[2];

SQL Expressions ItemIndex property

Declaration

property ItemIndex: integer;

Description

ItemIndex is a Run-time only property which can be used to obtain the current Expressions item number, or set the Expressions 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 (Expressions[2], for example), or whenever the key property (if applicable) is assigned a new lookup value (key properties are things like Expressions.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.

VCL Reference

624

Example

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

if Crpe1.SQL.Expressions.ItemIndex <> 0 then Crpe1.SQL.Expressions[0];

SQL Expressions Name property

Declaration

property Name: TCrExpressionName;

Type

TCrExpressionName = string;

Description

The Name property specifies the Name of the Expression. It is a key property, and therefore serves as a lookup; that is, assigning it a value will cause the Expressions object to point to the item that has a Expression Name with the same value. Before using the Name property to navigate through the Expressions, the Retrieve method should be called, or the manual Add method.

The % sign is not used when designating an Expression name in this property.

This property cannot be used to create new Expressions. Only Expressions that already exist in the Report can be specified.

Example

The following code uses the Expression Name property to point the Expressions object to the specified expression. It then assigns a new expression text to the Expression property:

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

{Set the Expressions object to the "Expression One" item} Crpe1.SQL.Expressions.Name := 'Expression One';

{Assign a new expression to the Expression property} Crpe1.SQL.Expressions.Expression.Text := '{fn RTRIM(company.`name`)}'; Crpe1.Output := toWindow;

Crpe1.Execute;

VCL Reference

625

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