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

LogOnInfo Destroy method, Page 410

LogOnInfo PromptForLogOn property, Page 410

LogOnInfo Retrieve method, Page 411

LogOnInfo Send method, Page 412

LogOnInfo Test method, Page 413

LogOnServer

Declaration

property LogOnServer: TCrpeLogOnServer;

Type

TCrpeLogOnServer = class(TPersistent)

Description

The LogOnServer object is a run-time only object that contains properties that allow for Logging onto a Server. The difference between this object and the Connect and LogOnInfo objects is that the latter work on a table by table basis, setting the LogOn information for each table in a Report, whereas LogOnServer just opens a connection to a SQL Server and if the Report has that Server specified in it, it will use the connection.

The advantage to LogOnServer is that it is simple, and only needs to be opened once for any Reports (and Subreports) that use that particular Server, whereas the Connect and LogOnInfo properties need to be specified on a report by report basis. The disadvantage is that it will not change the Server name that is specified in a Report, therefore it is not possible to use LogOnServer if the Server name is going to be different than when the Report was created.

The LogOn parameters for LogOnServer are similar to the other two objects:

ServerName

UserID

Password

DatabaseName

DLLName

DLLName specifies the name of the Seagate Crystal Reports DLL for the server or password-protected nonSQL table you want to log on to, for example, 'PDSODBC.DLL'. DLL names have the following naming convention: PDS*.DLL for SQL/ODBC databases.

The Retrieve method will create an item in the LogOnServer object for each unique ServerName it finds in the Report (including any Subreports), and fill all the properties of each item except for Password.

The LogOn and LogOff methods create and terminate the actual connection.

VCL Reference

54

The Number property stores the connection number created by a successful LogOn.

The IndexOf method can be used to locate a specific LogOnServer item by it's connection Number.

NOTE: LogOff will not normally be successful unless the Report that uses the connection is first closed, by either changing the ReportName, or using the component's CloseJob method.

LogOnServer 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 := 'PDSORA7.DLL'; {Crystal's Native Oracle Driver} ServerName := 'oracleserver';

UserID := 'SCOTT'; Password := 'tiger';

DatabaseName := ''; {Not usually req'd for Oracle} if LogOn then

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

ShowMessage('Error Logging on to Server');

end;

This example shows how to create a LogOnServer item by retrieving the LogOn information from the Report. This should only be done if the ServerName that the Report was created with is going to remain the same, since LogOnServer cannot be used to change ServerName:

Crpe1.LogOnServer.Retrieve; {Retrieve LogOnServer info from Report} if Crpe1.LogOnServer.Count > 0 then

begin

Crpe1.LogOnServer[1]; Crpe1.LogOnServer.Password := 'tiger'; if not Crpe1.LogOnServer.LogOn then

ShowMessage('Error Logging on to Server');

end;

This example shows how to log off a Server that has been Logged On using the LogOnServer property. First the PrintJob must be closed, or the LogOff will fail. Then the LogOnServer object must be set to the item that was used to LogOn (the IndexOf method can be used to search LogOnServer for a particular LogOn ID).

Finally an attempt is made to LogOff:

Crpe1.CloseJob;

Crpe1.LogOnServer[0];

if Crpe1.LogOnServer.LogOff then ShowMessage('LogOff Server successful')

else

ShowMessage('LogOff Server failed');

VCL Reference

55

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