I had this code from an August 15, 1999 posting and have not tested it nor
verified accuracy. May it will help with your problem.
"Just assign the handle to the database component"
Here is the part of the calling unit.
unit Calling_Unit;
interface
var MainDatabase: TDatabase;
implemention
uses Other_units, BDE; {you need BDE for type definition of HDBIDB}
function DLL_funtion(const hnd: HDBIDB): boolean; external 'YOURDLL.DLL';
procedure Calling_Proc;
var res: boolean;
begin
res := DLL_funtion(MainDatabase.Handle); {MainDatabase must be
connected}
end;
Note: you can put the declaration of DLL_funtion in the interface part too,
then you have to include BDE in the uses clause of the interface
Here is the DLL
project file:
library YOURDLL
uses
SysUtils,
Classes,
DLLMain in 'DLLMain.pas',
exports
DLL_function index 1;
begin
end.
Unit file:
unit DLLMain;
interface
uses Other_Units,BDE;
var DLLDatabase: TDatabase;
function DLL_funtion(const hnd: HDBIDB):boolean;
implementation
function DLL_funtion(const hnd: HDBIDB): boolean;
begin
DLLDataModule.DLLDatabase.Handle := hnd;
{Now DLLDatabase uses the same connection as MainDatabase}
end;
end.
----- original message ------
Quote:> Hello,
> I want to use the same database connection in a DLL
> like in the main application.
> I tried to use a procedure with a TDatabase parameter
> in the DLL, but I didn't manage to connect queries
> with this TDatabase parameter.
> Can anyone help
> Thank you
> Bernhard