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

Example

The following example sets the Connect properties and tests the connection before running the Report:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Connect.ServerName := 'WBSQLServer'; Crpe1.Connect.UserID := 'Elmer Fudd'; Crpe1.Connect.Password := 'Wabbit'; Crpe1.Connect.DatabaseName := 'Company1'; if Crpe1.Connect.Test then

Crpe1.Execute else

ShowMessage('Error Connecting');

Connect Methods

Connect Clear method

Declaration

procedure Clear;

Description

This method can be used to set the Connect properties to their default values:

ServerName

:= '';

UserID

:= '';

Password

:= '';

DatabaseName

:= '';

Propagate

:= True;

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.

Example

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

Crpe1.Connect.Clear;

This code clears the Connect properties for the second Subreport:Crpe1.Subreports[2]; Crpe1.Connect.Clear;

VCL Reference

252

Connect CopyFrom method

Declaration

function CopyFrom(Source: TCrpeConnect): boolean;

Description

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

var

tempConnect : TCrpeConnect; begin

tempConnect := TCrpeConnect.Create; tempConnect.CopyFrom(Crpe1.Connect);

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

end;

Connect Create method

Declaration

constructor Create;

Description

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

Connect Retrieve method

Declaration

function Retrieve: boolean;

VCL Reference

253

Description

The Retrieve method obtains the Connect information from the Report. The Connect information is obtained from the first table in the Report that has LogOn information (i.e. the first SQL table located). Returns True if the call was successful in obtaining Connect information.

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

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'; {Retrieve Subreports} Crpe1.Subreports.Retrieve;

{Loop through Reports and Retrieve}

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

Crpe1.Subreports[cnt];

Crpe1.Connect.Retrieve; end;

{Set Crpe component back to main Report} Crpe1.Subreports[0];

end;

Connect Send method

Declaration

function Send: boolean;

Description

The Send method sends the Connect 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.

VCL Reference

254

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 Connect settings are sent from the Crystal component to the Crystal Reports Print Engine DLL. This is normally handled automatically in the Execute method:

Crpe1.Connect.Send;

Connect Test method

Declaration

function Test: boolean;

Description

The Test method can be used to try out a connection after the Connect properties have been filled.

Example

The Test method is used in the example below to check the Connect information before running a Report:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.Connect.Retrieve; Crpe1.Connect.Password := 'Agent86'; if Crpe1.Connect.Test then

Crpe1.Execute else

ShowMessage('Error Connecting');

Export Properties

Export AppName property

Declaration

property AppName: TCrExportAppName;

Type

TCrExportAppName = string;

VCL Reference

255

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