Subject | Re: [IBO] IB_Connection assigned |
---|---|
Author | Dmitry Beloshistov |
Post date | 2003-10-14T06:58:31Z |
Hello!
This fully work sample source code (DLL + Host application).
Only recompile it ;) On Form1 in host application - one TButton and one TIB_Connection component.
1) DRP
program TestPlugs;
uses
Forms,
HostApp in 'HostApp.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
2) Host application:
unit HostApp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IB_Components, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
IB_Connection1: TIB_Connection;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TInitPlugin=procedure (AppHandle:THandle); stdcall;
TInitIBCon=procedure (IBHandle:pointer); stdcall;
TExecPlugin=procedure; stdcall;
TDonePlugin=procedure; stdcall;
procedure TForm1.FormShow(Sender: TObject);
begin
IB_Connection1.LoginPrompt:=True;
IB_Connection1.Connect;
end;
procedure TForm1.Button1Click(Sender: TObject);
var DllHandle:THandle;
InitPlugin:TInitPlugin;
InitIBCon:TInitIBCon;
ExecPlugin:TExecPlugin;
DonePlugin:TDonePlugin;
begin
DllHandle:=LoadLibrary('TESTDLL.DLL');
if DllHandle<>0 then
begin
@InitPlugin:=GetProcAddress(DllHandle,'InitPlugin');
if (@InitPlugin<>nil) then InitPlugin(Application.Handle);
@InitIBCon:=GetProcAddress(DllHandle,'InitIBCon');
if (@InitIBCon<>nil) then InitIBCon(IB_Connection1.dbHandle);
@ExecPlugin:=GetProcAddress(DllHandle,'ExecPlugin');
if (@ExecPlugin<>nil) then ExecPlugin;
@DonePlugin:=GetProcAddress(DllHandle,'DonePlugin');
if (@DonePlugin<>nil) then DonePlugin;
end;
FreeLibrary(DllHandle);
end;
end.
3) DLL
library TestDLL;
uses SysUtils,Classes,Forms,IB_Components;
{$R *.res}
var IB_Connection1:TIB_Connection;
Procedure InitPlugin(AppHandle:cardinal); stdcall;
begin
Application.Handle:=AppHandle;
end;
Procedure DonePlugin; stdcall;
begin
IB_Connection1.Free;
end;
Procedure InitIBCon(IBHandle:pointer); stdcall;
begin
IB_Connection1:=TIB_Connection.Create(nil);
IB_Connection1.dbHandleShared:=IBHandle;
end;
procedure ExecPlugin; stdcall;
var Q:TIB_Query;
T:TIB_Transaction;
begin
T:=TIB_Transaction.Create(nil);
try
Q:=TIB_Query.Create(nil);
try
Q.IB_Transaction:=T;
T.IB_Connection:=IB_Connection1;
Q.IB_Connection:=T.IB_Connection;
T.StartTransaction;
with Q do
begin
close; sql.clear;
sql.Text:='SELECT COUNT(ID) FROM JUR_CLIENTS_REF';
Open;
Application.MessageBox(PChar(Fields[0].AsString),'Result from DLL!',0);
Close;
end;
T.Commit;
T.Close;
finally
Q.Free;
end;
finally
T.Free;
end;
end;
exports
InitPlugin,
DonePlugin,
InitIBCon,
ExecPlugin;
end.
WBR, Dmitry Beloshistov AKA [-=BDS=-]
[Non-text portions of this message have been removed]
This fully work sample source code (DLL + Host application).
Only recompile it ;) On Form1 in host application - one TButton and one TIB_Connection component.
1) DRP
program TestPlugs;
uses
Forms,
HostApp in 'HostApp.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
2) Host application:
unit HostApp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IB_Components, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
IB_Connection1: TIB_Connection;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TInitPlugin=procedure (AppHandle:THandle); stdcall;
TInitIBCon=procedure (IBHandle:pointer); stdcall;
TExecPlugin=procedure; stdcall;
TDonePlugin=procedure; stdcall;
procedure TForm1.FormShow(Sender: TObject);
begin
IB_Connection1.LoginPrompt:=True;
IB_Connection1.Connect;
end;
procedure TForm1.Button1Click(Sender: TObject);
var DllHandle:THandle;
InitPlugin:TInitPlugin;
InitIBCon:TInitIBCon;
ExecPlugin:TExecPlugin;
DonePlugin:TDonePlugin;
begin
DllHandle:=LoadLibrary('TESTDLL.DLL');
if DllHandle<>0 then
begin
@InitPlugin:=GetProcAddress(DllHandle,'InitPlugin');
if (@InitPlugin<>nil) then InitPlugin(Application.Handle);
@InitIBCon:=GetProcAddress(DllHandle,'InitIBCon');
if (@InitIBCon<>nil) then InitIBCon(IB_Connection1.dbHandle);
@ExecPlugin:=GetProcAddress(DllHandle,'ExecPlugin');
if (@ExecPlugin<>nil) then ExecPlugin;
@DonePlugin:=GetProcAddress(DllHandle,'DonePlugin');
if (@DonePlugin<>nil) then DonePlugin;
end;
FreeLibrary(DllHandle);
end;
end.
3) DLL
library TestDLL;
uses SysUtils,Classes,Forms,IB_Components;
{$R *.res}
var IB_Connection1:TIB_Connection;
Procedure InitPlugin(AppHandle:cardinal); stdcall;
begin
Application.Handle:=AppHandle;
end;
Procedure DonePlugin; stdcall;
begin
IB_Connection1.Free;
end;
Procedure InitIBCon(IBHandle:pointer); stdcall;
begin
IB_Connection1:=TIB_Connection.Create(nil);
IB_Connection1.dbHandleShared:=IBHandle;
end;
procedure ExecPlugin; stdcall;
var Q:TIB_Query;
T:TIB_Transaction;
begin
T:=TIB_Transaction.Create(nil);
try
Q:=TIB_Query.Create(nil);
try
Q.IB_Transaction:=T;
T.IB_Connection:=IB_Connection1;
Q.IB_Connection:=T.IB_Connection;
T.StartTransaction;
with Q do
begin
close; sql.clear;
sql.Text:='SELECT COUNT(ID) FROM JUR_CLIENTS_REF';
Open;
Application.MessageBox(PChar(Fields[0].AsString),'Result from DLL!',0);
Close;
end;
T.Commit;
T.Close;
finally
Q.Free;
end;
finally
T.Free;
end;
end;
exports
InitPlugin,
DonePlugin,
InitIBCon,
ExecPlugin;
end.
WBR, Dmitry Beloshistov AKA [-=BDS=-]
[Non-text portions of this message have been removed]