Forum > Packages and Libraries

TZConnection in DLL

(1/1)

php_Teufel:
Hi everybody,

I've got a problem that I have some time to tinker around.

I wrote a program (menu) which calls modules (DLLs) dynamicaly. For not to build a database Connection for each DLL I pass a pointer to the Connection Componente (Zeos) in the menu.

So far it works, I can open and edit database tables in the DLL's. : D

However, if I set the Connection  in the module to NIL, or close the main program, I get a SIGSEGV error. : (

Can anyone explain what I'm doing wrong, or what do I need yet?:


Here the code:
DLL:

--- Code: ---
library gem001;
 
{$mode DELPHI}{$H+}
 
uses
  Classes, Interfaces, Land, zcomponent, ZConnection, Forms;
procedure Start(db: Pointer);
var pDB:^TZConnection;
begin
  pDB:=db;
  application.CreateForm(TfrmGEM001,frmGEM001);
  frmGEM001.ZTable1.Connection:=pDB^;
  frmGEM001.ShowModal;
end;
exports
  Start;
begin
  Application.Initialize;
end.
unit Land;
 
{$mode DELPHI}{$H+}
 
interface
 
uses
  Classes, SysUtils, db, FileUtil, ZConnection, ZDataset, Forms, Controls,
  Graphics, Dialogs, DBGrids;
 
type
 
  { TfrmGEM001 }
 
  TfrmGEM001 = class(TForm)
    Datasource1: TDatasource;
    DBGrid1: TDBGrid;
    ZTable1: TZTable;
    ZTable1Bezeichnung: TStringField;
    ZTable1EU: TBooleanField;
    ZTable1Land: TStringField;
    ZTable1Vorwahl: TStringField;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
 
var
  frmGEM001: TfrmGEM001;
implementation
 
procedure TfrmGEM001.FormShow(Sender: TObject);
begin
 
  ZTable1.Active:=true;
end;
 
procedure TfrmGEM001.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  ztable1.Active:=false;
  ztable1.connection:=nil;
  closeaction:=caFree;
end;
 
 
{$R *.lfm}
 
{ TfrmGEM001 }
 
 
end.

--- End code ---
Mainprogram:

--- Code: ---unit uMenue;
 
{$mode Delphi}{$H+}
 
interface
 
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  DynLibs, ZConnection;
 
type
  ProcStart = procedure(var db: Pointer);
  { TForm1 }
 
  TForm1 = class(TForm)
    Button1: TButton;
    ZConnection1: TZConnection;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  private
    { private declarations }
  public
    { public declarations }
  end;
 
var
  Form1: TForm1;
  hnd: TLibHandle;
 
implementation
 
{$R *.lfm}
 
{ TForm1 }
 
procedure TForm1.Button1Click(Sender: TObject);
var
  proc: ProcStart;
begin
  hnd := LoadLibrary('gem001.dll');
  @proc := GetProcedureAddress(hnd, 'Start');
  proc(@ZConnection1);
end;
 
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  unloadlibrary(hnd);
  closeaction:=cafree;
end;
 
 
end.

--- End code ---
Thank you very much

Volker

marcov:
The problem is that you are using LCL in DLLs. That's not supported.

Including sharemem as first unit in both program dll might solve some corner cases (at least if you compile both dll and exe from exactly the same zeos, FPC and lazarus codebase), but not all.

For this to work somewhat decent, (without thinking about many details) we would need packages support, see http://wiki.freepascal.org/packages

Navigation

[0] Message Index

Go to full version