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

If you would like the Prompt dialog box to contain different Server information than what is stored in the Report, follow these steps:

1Retrieve LogOnInfo from the Report.

2Set PromptForLogOn to False.

3Modify the LogOnInfo property values to the desired settings.

4Call LogOnInfo.Send to send these parameters into the Report.

5Repeat steps 1 to 4 for any Subreports.

6Set PromptForLogOn to True.

7Call Crpe1.Execute.

NOTE: If you wish to modify this dialog, the Form information is stored in URLOGON.DFM. The URLOGON.PAS file is in the Source\Dialogs directory, although if changes are made to the URLOGON.PAS, they must be copied into the appropriate section of the UCDIALOG.PAS file in order to be compiled into the VCL.

Example

The following example shows how to use the PromptForLogOn property:

Crpe1.ReportName := 'C:\Company.rpt'; Crpe1.ConnectMethod := useLogOnInfo; Crpe1.LogOnInfo.PromptForLogOn := True; Crpe1.Output := toWindow;

{LogOn Prompt Dialog appears after Execute} Crpe1.Execute;

LogOnInfo Retrieve method

Declaration

function Retrieve: boolean;

Description

The Retrieve method obtains the LogOnInfo information from the Report. Retrieve will create one LogOnInfo item for each SQL table it finds in the Report. If LogOn information was not found, the call returns False. Be aware that calling Retrieve will first cause the LogOnInfo object to be cleared, so any current information stored in it will be removed.

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

VCL Reference

411

Example

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

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

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

{Loop through Reports and Retrieve}

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

Crpe1.Subreports[cnt];

Crpe1.LogOnInfo.Retrieve; end;

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

end;

LogOnInfo Send method

Declaration

function Send: boolean;

Description

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

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

Crpe1.LogOnInfo.Send;

VCL Reference

412

LogOnInfo Test method

Declaration

function Test: boolean;

Description

The Test method provides a way to test the connection before running the Report. With LogOnInfo, this can be done on a table by table basis, since the Test can be applied to each item. Returns True if the connection was successful, False if it was not.

Example

This example illustrates the use of the Test method:

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

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

Crpe1.LogOnInfo[cnt].UserID := 'Maxwell Smart'; Crpe1.LogOnInfo[cnt].Password := 'Agent86';

if Crpe1.LogOnInfo.Test then

ShowMessage('LogOn information is good: Table #' + IntToStr(Crpe1.LogOnInfo[cnt].Table))

else

ShowMessage('LogOn information is not good: Table #' + IntToStr(Crpe1.LogOnInfo[cnt].Table));

end;

LogOnServer Properties

LogOnServer DatabaseName property

Declaration

property DatabaseName: string;

Description

This property contains the name of the Database being connected to. Most SQL Servers require this parameter (Oracle is usually an exception to the rule).

VCL Reference

413

Example

This example shows how to create a LogOnServer item manually, and fill the properties with values. Finally, the LogOn method is called:

with Crpe1.LogOnServer do

 

begin

 

Add;

{Create a LogOnServer item}

DLLName := 'PDSSQL.DLL'; {Crystal's Native MS SQL Server Driver} ServerName := 'enterprise';

UserID := 'Kirk'; Password := 'captain'; DatabaseName := 'pubs'; if LogOn then

ShowMessage('The LogOn ID is: ' + IntToStr(Number)) else

ShowMessage('Error Logging on to Server');

end;

LogOnServer DLLName property

Declaration

property DLLName: string;

Description

The DLLName property refers to the name of the Crystal database DLL used to make the LogOn connection. This must be the same as the one defined in the Report. If ODBC drivers are being used to make the connection, the DLL Name is:

'PDSODBC.DLL'

If Crystal's native SQL drivers are being used to make the connection, the DLL naming convention is:

'PDS*.DLL' {PDSORA7.DLL for Oracle, PDSSQL.DLL for MS SQL Server, PDSSYB10.DLL for Sybase System 10/11, etc.}

Notice that the 16-bit naming convention can be used even for 32-bit drivers. The 32-bit names can also be used (P2SODBC.DLL, etc.) if desired.

NOTE: To determine the driver that the Report was designed with, load the Report into Crystal Reports, go to the Database menu in Crystal Reports 6.0 (or File | Report Options in Crystal Reports 5.0) and selecting the "Convert Database Driver" option. The driver name is listed after the word "From:" in the dialog.

VCL Reference

414

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