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

SectionHeight Properties

SectionHeight Height property, Page 585

SectionHeight Item property, Page 586

SectionHeight ItemIndex property, Page 587

SectionHeight Section property, Page 587

SectionHeight SectionAsCode property, Page 589

SectionHeight Methods

SectionHeight Add method, Page 589

SectionHeight Clear method, Page 590

SectionHeight CopyFrom method, Page 591

SectionHeight Count method, Page 591

SectionHeight Create method, Page 592

SectionHeight Delete method, Page 592

SectionHeight Destroy method, Page 593

SectionHeight Retrieve method, Page 593

SectionHeight SectionType method, Page 594

SectionHeight Send method, Page 595

Selection

Declaration

property Selection: TCrpeSelectionFormula;

Type

TCrpeSelectionFormula = class(TPersistent)

Description

The Selection object deals with the Selection Formula of a Report. It's main properties and methods are:

The Formula property is used to hold the text of the Selection Formula.

The Replace property is a boolean property that specifies if the text in the Formula property will replace the Selection that is already in the Report, or whether it will be ANDed on to the end of it.

VCL Reference

100

The Retrieve method will fetch the Selection Formula that is currently in the Report, and place it in the Formula property.

The Check method can be used to determine whether the Formula syntax is correct.

Selection Example

This code sample passes a new Selection formula into the Report, replacing the one that was currently there:

Crpe1.ReportName := 'Report1.rpt'; Crpe1.Selection.Formula.Assign('{company.STATE} = "CA"');

{or Crpe1.Selection.Formula.Text := '{company.STATE} = "CA"';} Crpe1.Selection.Replace := True;

Crpe1.Execute;

Since one line in the Crystal Reports Formula Editor is limited to 255 characters, Selections built with a large number of items must be split onto more than one line. The code below handles this type of case. Items are read from a ListBox, and after every 4, a new line is added to the Selection Formula:

procedure RunReport;

var

 

cnt1,cnt2

: integer;

sTmp

: string;

begin

 

Crpe1.ReportName := 'D:\Company.rpt'; Crpe1.Selection.Formula.Clear;

{This Memo shows the syntax of the final Formula} Memo1.Clear;

cnt1 := 0; cnt2 := 0;

{If the ListBox contains items to add to the Selection} if ListBox1.Items.Count > 0 then

begin

{Store the beginning of the Selection} sTmp := '{company.CONAME} in [';

{Loop through the ListBox items} while cnt1 < ListBox1.Items.Count do begin

{Take 4 items per SelectionFormula line} while cnt2 < 4 do

begin

{If it's the last item, add a close bracket} if cnt1 = (ListBox1.Items.Count - 1) then begin

sTmp := sTmp + '"' + Listbox1.Items[cnt1] + '"]'; cnt2 := 3;

end

VCL Reference

101

{If it's not the last item, add a comma} else

sTmp := sTmp + '"' + Listbox1.Items[cnt1] + '"' + ','; {Increment the counters}

Inc(cnt2);

Inc(cnt1) end;

{Reset the item counter} cnt2 := 0;

{Add the line to the Selection} Crpe1.Selection.Formula.Add(sTmp); sTmp := '';

end; end;

{Write the Formula to a Memo so we can view it} Memo1.Lines.AddStrings(Crpe1.SelectionFormula); Crpe1.Output := toWindow;

Crpe1.Execute; end;

Using Variables with Selection Formula

Delphi variables can be used with the Selection Formula if they are declared as string or converted to string (regardless of the actual data type) before being passed to Crystal Reports. Remember also, that string values require extra quotes for Crystal Reports, as well as the usual single quotes that Delphi requires. The following examples cover some of the ways in which variables can be used:

1.Passing a String variable with extra quotes included:

var

sTmp : string begin

sTmp := '"CA"';

Crpe1.Selection.Formula[0] := '{company.STATE} = ' + sTmp;

2.Passing a String variable without extra quotes included:

var

sTmp : string; begin

sTmp := 'CA';

Crpe1.Selection.Formula[0] := '{company.STATE} = "' + sTmp + '"';

3.Passing a String variable from an Edit box without extra quotes included:

var

sTmp : string; begin

sTmp := Edit1.Text;

Crpe1.Selection.Formula[0] := '{company.STATE} = "' + sTmp + '"';

VCL Reference

102

4.Passing Integer values from Edit boxes:

var

nStart : string; nEnd : string;

begin

nStart := Edit1.Text; nEnd := Edit2.Text;

Crpe1.Selection.Formula[0] := '{company.SALES} >= ' + nStart + 'AND {company.SALES} <= ' + nEnd;

5.Passing Integer variables:

var

nSales : integer; begin

nSales := 12345;

Crpe1.Selection.Formula[0] := '{company.SALES} > ' + IntToStr(nSales);

6.Passing Date variables (Crystal Reports accepts dates only as a string data type in the Date(YYYY,MM,DD) format):

var

dStart : string; dEnd : string;

begin

dStart := '1998,01,31'; dEnd := '1998,06,30';

Crpe1.Selection.Formula[0] := '{company.STARTDATE} in Date(' + dStart + ') to Date(' + dEnd + ')';

7.Passing Date variables divided into Day, Month, Year:

var

dYear : string; dMonth : string; dDay : string;

begin

dYear := '1998'; dMonth := '06'; dDay := '31';

Crpe1.Selection.Formula[0] := '{company.STARTDATE} = Date(' + dYear + ',' + dMonth + ',' + dDay + ')';

VCL Reference

103

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