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

IsStrEmpty method

Declaration

function IsStrEmpty(const sValue: string): boolean;

Description

IsStrEmpty is used internally in the Crystal component but has been exposed for general purpose use. It takes a string numeric value and returns a Boolean of either True (the string is empty) or False (the string is not empty). The function will ignore leading or trailing spaces.

str1 := ' ';

if Crpe1.IsStrEmpty(str1) then ShowMessage('str1 is empty!');

{str1 will be considered empty because spaces are ignored}

LogOnPrivateInfo method

Declaration

function LogOnPrivateInfo(DllName: string; PrivateInfo: pointer): boolean;

Description

LogOnPrivateInfo can be used to "piggyback" the Crystal Reports database connection on your application's existing connection to a Server. If you are already logged on, this function lowers the number of connections established by a workstation, thus reducing application time and network traffic. It also prevents a Crystal Reports Log Off call from disconnecting an application's existing connection to the Server. Note that this call only works with ODBC connections.

Parameter

Description

 

 

 

 

DllName

Currently, this can only be 'PDSODBC.DLL'. Even though 32bit Crystal actually uses the

 

P2SODBC.DLL, we use PDSODBC.DLL to refer to either, in this call.

PrivateInfo

In the application, a connection to the server has to have been established and this in

 

turn generates a Handle to a Database Connection (HDBC). This parameter specifies the

 

application's handle to the connection. This makes Seagate Crystal Reports aware of the

 

existing connection so it can use it instead of establishing a new one. Since the report

 

with which this function works are based on ODBC, this parameter is actually an ODBC

 

HDBC.

 

 

The LogOnPrivateInfo call returns True if the call is successful; False if the call fails.

NOTE: At the time of this writing, the return value is always True. This is not a fault of the Crystal component, but rather the Print Engine. It will hopefully be fixed in a future release of the Print Engine DLL.

VCL Reference

148

Remarks

This function can only be used with database connections established by ODBC or Q+E Library 2.0. Any other database connections can not be accessed by this function.

If the application uses the Q+E Library to connect, get the ODBC HDBC by using the following function calls:

qeConnect

Opens a connection to the server.

 

 

qeGetODBCHdbc

Returns the ODBC hdbc.

 

 

See the Intersolv DataDirect Developer's Toolkit for more information.

If the application uses ODBC to connect, get the ODBC HDBC by using the following function calls:

SQLAllocEnv

Initializes the ODBC call level interface and allocates memory for an

 

environment handle.

 

 

SQLAllocConnect

Returns an ODBC HDBC.

 

 

See the ODBC SDK documentation for more information.

Example

The following code samples show how to prompt for an ODBC datasource, connect to it, and then piggyback the Report on that connection. Note that the database connection used in the Report must be based off the same datasource as the LogOnPrivateInfo call is connecting to:

uses

ODBC32;

implementation

{$R *.DFM} var

henv : Pointer; hdbc : Pointer; hstmt : Pointer;

procedure TForm1.Connect; var

ConIn, ConOut : MyUChar; LenIn, LenOut : smallint; RetCode : smallint; TotOut : Pointer;

x, I : integer; Flag : BOOL; TempStr : string;

Temp, Temp2 : PChar; begin

Flag:= False;

LenIn := 256;

LenOut := 256; henv := nil; hdbc := nil; hstmt := nil;

VCL Reference

149

RetCode := SQLAllocEnv(henv); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLAllocEnv Failed');

RetCode := SQLAllocConnect(henv, hdbc); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLAllocConnect Failed');

FillChar(ConIn, 256, ' ');

RetCode := SQLDriverConnect(hdbc, Form1.Handle, ConIn,

LenIn, ConOut, LenOut,

TotOut, SQL_DRIVER_PROMPT);

if ((Retcode <> SQL_SUCCESS) and (Retcode <> SQL_SUCCESS_WITH_INFO)) then begin

ShowMessage('SQLDriverConnect Failed'); Flag := True

end else begin

ShowMessage('SQLDriverConnect Successful'); EdtConnection.Text := StrPas(ConOut);

if RetCode = SQL_SUCCESS_WITH_INFO then end;

RetCode := SQLAllocStmt(hdbc, hstmt); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLAllocStmt Failed');

end;

procedure TForm1.Disconnect; var

RetCode : ShortInt; begin

Crpe1.CloseJob;

RetCode := SQLFreeStmt(hstmt, SQL_CLOSE); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLFreeStmt Failed');

RetCode := SQLDisconnect(hdbc); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLDisconnect Failed');

RetCode := SQLFreeConnect(hdbc); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLFreeConnect Failed');

VCL Reference

150

RetCode := SQLFreeEnv(henv); if Retcode <> SQL_SUCCESS then

ShowMessage('SQLFreeEnv Failed');

end;

procedure TForm1.RunReport; begin

Crpe1.ReportName := 'MyReport.rpt'; Crpe1.Output := toWindow; Crpe1.OpenJob;

if not Crpe1.LogOnServerPrivateInfo('PDSODBC.DLL', hdbc) then begin

ShowMessage('LogOnServerPrivateInfo Failed'); Exit;

end; Crpe1.Execute;

end;

OpenEngine method

Declaration

procedure OpenEngine;

Description

OpenEngine forces the Crystal Reports Print Engine DLL to be loaded into memory and opened for use. It is called automatically within the Crystal component but may be called in code if desired.

Example

The following example uses the OpenEngine method to load the CRPE32.DLL (this is not normally necessary):

Crpe1.OpenEngine;

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

Crpe1.Output := toPrinter;

Crpe1.Execute;

OpenJob method

Declaration

function OpenJob: boolean;

VCL Reference

151

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