Here is the simplified code.
Main window:
unit Main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Windows, mysql51conn, sqldb, db, dbf, FileUtil, dbdateedit,
rxdbgrid, RxSortSqlDB, RxSortZeos, ZDataset, ZConnection, Forms, Controls,
Graphics, Dialogs, StdCtrls, ExtCtrls, ComCtrls, DBGrids, ExtDlgs, Calendar,
EditBtn, Grids, Buttons, Menus,
dynlibs;
type
TfrmMain = class(TForm)
btnFJournal: TButton;
ZConnection1: TZConnection;
procedure btnFJournalClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
const
{$IFDEF windows}
libraryName = 'fjournal.dll';
{$ENDIF}
{$IFDEF unix}
libraryName = 'fjournal.so';
{$ENDIF}
var
frmMain: TfrmMain;
aUserName, aUserPass, aAlias: string;
implementation
uses
FizEdit, Login, gettext, translations, rxFileUtils;
{$R *.lfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
if not Log_in(ZConnection1, aUserName, aUserPass, aAlias, '') then Application.Terminate;
end;
procedure OpenFJournal;
type
TOpenFJournal = procedure(db: Pointer; aHandle: HWND);
var
lib: TLibHandle;
func: TOpenFJournal;
begin
lib := LoadLibrary(libraryName);
try
Pointer(func) := GetProcedureAddress(lib, 'OpenFJournal');
if Assigned(func) then begin
frmMain.Enabled := False;
try
func(@frmMain.ZConnection1, frmMain.Handle);
finally
frmMain.Enabled := True;
end;
end;
finally
FreeLibrary(lib);
end;
end;
procedure TfrmMain.btnFJournalClick(Sender: TObject);
begin
OpenFJournal;
end;
end.
First form:
unit fJournalGrid;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Controls, Windows, Forms, db, FileUtil, StdCtrls, ExtCtrls,
Dialogs, Graphics,
rxdbgrid, RxSortZeos, curredit, ZComponent, ZConnection, ZDataset,
Menus, EditBtn;
type
TfrmJournalGrid = class(TForm)
ZConnection: TZConnection;
ZQuery: TZQuery;
Datasource: TDatasource;
DBGrid: TRxDBGrid;
PopupMenu1: TPopupMenu;
popEdit: TMenuItem;
procedure FormShow(Sender: TObject);
procedure popEditClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
frmJournalGrid: TfrmJournalGrid;
procedure OpenFJournal(db: Pointer; aHandle: HWND);
implementation
uses
FizEdit;
{$R *.lfm}
procedure OpenFJournal(db: Pointer; aHandle: HWND);
var
pDB:^TZConnection;
begin
pDB := db;
frmJournalGrid := TfrmJournalGrid.Create(Application);
with frmJournalGrid do
try
ZQuery.Connection := pDB^;
ZQuery.Open;
ShowModal;
finally
Release;
end;
end;
procedure TfrmJournalGrid.popEditClick(Sender: TObject);
begin
FizEdit.OpenFizEdit(Datasource.DataSet.FieldByName('id').AsInteger);
end;
end.
Second form:
unit FizEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sqldb, db, dbf, FileUtil, dbdateedit, rxdbcomb, rxdbgrid,
rxlookup, ZDataset, ZSqlUpdate, ZConnection, Forms,
Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, DbCtrls, DBGrids, Buttons,
Menus;
type
TfrmFizEdit = class(TForm)
btnOk: TButton;
btnCancel: TButton;
ZQuery1: TZQuery;
ZUpdateSQL1: TZUpdateSQL;
Datasource1: TDatasource;
Label1: TLabel;
DBEdit1: TDBEdit;
...
procedure btnOkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
frmFizEdit: TfrmFizEdit;
procedure OpenFizEdit(id: Integer);
implementation
uses
fJournalGrid, Func;
{$R *.lfm}
procedure OpenFizEdit(id: Integer);
begin
with TfrmFizEdit.Create(frmJournalGrid) do
begin
try
ZQuery1.ParamByName('id').AsInteger := id;
ZQuery1.Open;
if ShowModal = mrOK then
if ZQuery1.State in [dsEdit, dsInsert] then
ZQuery1.Post
else
ZQuery1.Cancel;
finally
Free;
end;
end;
end;
procedure TfrmFizEdit.FormCreate(Sender: TObject);
begin
ZQuery1.Connection := frmJournalGrid.ZQuery.Connection;
end;
procedure TfrmFizEdit.btnOkClick(Sender: TObject);
begin
ModalResult := mrOK;
Close;
end;
end.
See in attachment how does it look.