Subject | Re: [IBO] IB_Connection assigned |
---|---|
Author | forum@ipnetwork.eti.br |
Post date | 2003-10-13T18:54:39Z |
Citando Helen Borrie <helebor@...>:
error
Try this code example:
In DLL:
===============================
Procedure InitPlugin(ApplicationHandle:THandle); stdcall;
begin
Application.Handle:=ApplicationHandle;
DM:=TDM.Create(Application); // my data module with IB_Connection
end;
Procedure InitIBCon(IBConnectionHandle:Pointer); stdcall;
begin
//-- initiate connection
DM.IB_Connection1.dbHandleShared:=IBConnectionHandle; //!!!!
{
Warning! dbHandleShared in DLL := dbHandle from host Application
}
//---------- etc....-------------------------------
end;
In your main project (host application):
======================================
type
TInitPlugin=procedure (AppHandle:THandle); stdcall;
TInitIBConnection=procedure (IBConHandle:pointer); stdcall;
var FPluginHandle:THandle; // loaded DLL handle
FInitPlugin=TInitPlugin;
FInitIBConnection=TInitIBConnection;
Procedure LoadPlugin;
begin
FPluginHandle:=LoadLibrary('MYDLLNAME.DLL'); // DLL loading
if FPluginHandle<>0 then
begin
@FInitPlugin:=GetProcAddress(FPluginHandle,'InitPlugin');
if (@FInitPlugin<>nil) then
try
FInitPlugin(Application.Handle);
except on E:Exception do FInitiated:=False;
end;
@FInitIBConnection:=GetProcAddress(FPluginHandle,'InitIBCon');
if (@FInitIBConnection<>nil) then
try
{
put dbHandle from my DBAcs (datamodule) MainDB (IB_Connection)
to IB_Connection in already loaded DLL
}
if Assigned(DBAcs) and (DBAcs.MainDB.Connected) then
FInitIBConnection(DbAcs.MainDB.dbHandle); {- !!! -}
except on E:Exception do
begin {none} end;
end; // try
end; // if PluginHandle<>0
//........... etc ...............
end;
>I am using the example below, so that executing the program it returns the
>
>
>
> At 05:01 AM 13/10/2003 +0000, you wrote:
>
> >Hi,
>
> >I am having problems in opening a connection of the IB_Connection, am trying
>
> >to pass the connection between exe and the DLL, so that it receives the
>
> >following error
>
> >Statement must have an IB_Connection assigned
>
>
>
> Well, it's true. :-)
>
>
>
> Tell us exactly what you are doing.
>
>
>
> Helen
>
error
Try this code example:
In DLL:
===============================
Procedure InitPlugin(ApplicationHandle:THandle); stdcall;
begin
Application.Handle:=ApplicationHandle;
DM:=TDM.Create(Application); // my data module with IB_Connection
end;
Procedure InitIBCon(IBConnectionHandle:Pointer); stdcall;
begin
//-- initiate connection
DM.IB_Connection1.dbHandleShared:=IBConnectionHandle; //!!!!
{
Warning! dbHandleShared in DLL := dbHandle from host Application
}
//---------- etc....-------------------------------
end;
In your main project (host application):
======================================
type
TInitPlugin=procedure (AppHandle:THandle); stdcall;
TInitIBConnection=procedure (IBConHandle:pointer); stdcall;
var FPluginHandle:THandle; // loaded DLL handle
FInitPlugin=TInitPlugin;
FInitIBConnection=TInitIBConnection;
Procedure LoadPlugin;
begin
FPluginHandle:=LoadLibrary('MYDLLNAME.DLL'); // DLL loading
if FPluginHandle<>0 then
begin
@FInitPlugin:=GetProcAddress(FPluginHandle,'InitPlugin');
if (@FInitPlugin<>nil) then
try
FInitPlugin(Application.Handle);
except on E:Exception do FInitiated:=False;
end;
@FInitIBConnection:=GetProcAddress(FPluginHandle,'InitIBCon');
if (@FInitIBConnection<>nil) then
try
{
put dbHandle from my DBAcs (datamodule) MainDB (IB_Connection)
to IB_Connection in already loaded DLL
}
if Assigned(DBAcs) and (DBAcs.MainDB.Connected) then
FInitIBConnection(DbAcs.MainDB.dbHandle); {- !!! -}
except on E:Exception do
begin {none} end;
end; // try
end; // if PluginHandle<>0
//........... etc ...............
end;