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

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

if Crpe1.ParamFields[cnt].ParamSource = psStoredProc then ListBox1.Items.Add(Crpe1.ParamFields[cnt].Name);

end; end;

ParamFields ParamType property

Declaration

property ParamType: TCrParameterFieldType;

Type

TCrParamFieldType = (pfNumber, pfCurrency, pfBoolean, pfDate, pfString, pfDateTime, pfTime, pfInteger, pfColor, pfChar, pfLong, pfNoValue);

Description

ParamType is a read-only property that will only have a meaningful value if the Retrieve method is used to obtain ParamFields items from the Report. It indicates what data type the Value property is expecting.

NOTE: It is not possible to change the type of a ParamField at runtime. This must be done within the Crystal Reports designer.

Example

The ParamType property can be used to check the type of Value the ParamField item expects:

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

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

case Crpe1.ParamFields[cnt].ParamType of

pfNumber

:

Crpe1.ParamFields[cnt].AsNumber

:= 1;

pfCurrency :

Crpe1.ParamFields[cnt].AsCurrency := 1.23;

pfBoolean

:

Crpe1.ParamFields[cnt].AsBoolean := True;

pfDate

:

Crpe1.ParamFields[cnt].AsDate := Now;

pfString

:

Crpe1.ParamFields[cnt].Value :=

'CA';

end; end;

Crpe1.Output := toWindow; Crpe1.Execute;

VCL Reference

459

ParamFields Prompt property

Declaration

property Prompt: string;

Description

The Prompt property specifies the prompting text, if any, that will appear on the Parameter Prompt dialog box. This will be either the prompting text assigned when the Parameter field was first inserted into the Report, or the prompting text that was set from code.

If the ShowDialog property is false, then the Prompt dialog box will not appear, so there is no need, in that case, to set the Prompt property.

Example

This example changes the Prompt property:

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

Crpe1.ParamFields.Retrieve;

Crpe1.ParamFields[0].ShowDialog := True;

Crpe1.ParamFields[0].Prompt := 'Enter the State:';

Crpe1.ParamFields[0].Value := 'CA';

Crpe1.Output := toWindow;

Crpe1.Execute;

ParamFields Ranges property

Declaration

property Ranges: TCrpeParamFieldRanges;

Type

TCrpeParamFieldRanges = class(TPersistent)Description

Only available with SCR 7 and higher. The Ranges object is an extension of ParamFields that adds range capability to the Parameter values that can be passed to a Report. Ranges are different from regular Parameters in that they have a starting and ending value, instead of just a single value.

When a Report is designed, the Parameter field can be set up as having Discrete (single) values, or having Range (start and end) values. This can be changed at runtime via the ParamField.Info.ValueType property. The ValueType of a ParamField must be vtRanges in order for the Range object properties to have an effect.

VCL Reference

460

Ranges are similar to "Current" values, in that there will be no range values in a Report unless it has been run already, or it has Saved Data. Therefore, passing values via the Ranges object is normally not done unless you want to bypass the Crystal Reports Parameter Field dialog for that particular Parameter. If the Parameter dialog is to appear, then possible choices for the start and end range values should be passed via the ParamField.DefaultValues property.

The Retrieve method will fetch the Ranges values from the Report and fill the Ranges object with corresponding items.

The Count method returns the number of Ranges items currently contained in the Ranges object.

The Number property specifies Range Number of the item that the Ranges object is currently pointing to.

The Item and ItemIndex properties can be used to navigate through the Ranges object.

The RangeStart property determines the starting value of the Range.

The RangeEnd property determines the ending value of the Range.

The RangeBounds property determines how Crystal Reports will treat the values that match the range; that is, whether the values that fall within the Range include the RangeStart and RangeEnd values, or exclude them.

The Clear method removes all items from the Ranges object.

The Add and Delete methods provide a manual alternative to Retrieve/Clear for adding and deleting items from the Ranges object.

ParamFields Ranges Example

The following example illustrates the use of the Ranges object:

Crpe1.ReportName := 'C:\Company.rpt'; {Retrieve the Parameters} Crpe1.ParamFields.Retrieve;

{ByPass the Parameter Prompt Dialog} Crpe1.ParamFields[0].ShowDialog := False; {Make sure ValueType is set to Ranges}

Crpe1.ParamFields[0].Info.ValueType := vtRanges; {Clear Ranges, just to be safe} Crpe1.ParamFields[0].Ranges.Clear;

{Add a Range} Crpe1.ParamFields[0].Ranges.Add(0);

Crpe1.ParamFields[0].Ranges[0].RangeStart := 'CA'; Crpe1.ParamFields[0].Ranges[0].RangeEnd := 'WA'; Crpe1.ParamFields[0].Ranges[0].RangeBounds := IncludeStartAndEnd; Crpe1.Output := toWindow;

Crpe1.Execute;

VCL Reference

461

ParamFields Ranges Item property

Declaration

property Item[nIndex: integer]: TCrpeParamFieldRanges;

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 Ranges object, allowing the object to be treated like an array.

Item is a default property, it does not need to be specified when using the subscript: Ranges[2] is the same as Ranges.Item[2].

Item returns a reference to itself, so the Ranges properties can be used right after the subscript: Ranges[2].RangeBounds := IncludeStartAndEnd;

Example

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

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

{Set Ranges to the 1st Range} Crpe1.ParamFields[0].Ranges.Item[0];

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

{Set Ranges to the 1st Range} Crpe1.ParamFields[0].Ranges[0];

ParamFields Ranges ItemIndex property

Declaration

property ItemIndex: integer;

Description

ItemIndex is a Run-time only property which can be used to obtain the current Ranges item number, or set the Ranges 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

462

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