Hi,
Hopefully someone can help me: I have a
MDI Application, but the Child Forms are located in a
DLL. So when I load the
DLL, i send through the TApplication and TScreen
Handle, so that the Child form can be attached to the
MDI Application. This works just fine.
Each
DLL only has one export procedure, and thats the LoadDLLForm procedure
Delphi-Quellcode:
procedure LoadDLLForm(ATApp : TApplication; S: TScreen; var AMDITabBar : TAdvOfficeMDITabSet); export;
begin
Application := ATApp;
Screen := S;
frmChild := TfrmChild.Create(Application);
frmChild.FormStyle := fsMDIChild;
frmChild.Caption := 'Patient Data';
AMDITabBar.AddTab(frmChild);
end;
This function will call the MAIN MDICHild form, and all forms from there will be
SDI Based. So Basically, only one MDIChild form per
DLL,the rest as modal forms.
So this is what I wish to accomplish:
When the ChildForm is closed(wish is located in the
DLL), I want the
DLL to be distracted/unloaded, but I have no idea how to do this.
Here is my
MDI Application Code:
Delphi-Quellcode:
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AdvOfficeTabSet, StdCtrls;
type
TfrmMain =
class(TForm)
MDITabBar: TAdvOfficeMDITabSet;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure LoadMyLibrary(Alib :
String);
public
{ Public declarations }
end;
TLoadDLLForm =
procedure(ATApp : TApplication; S: TScreen;
var AMDITabBar : TAdvOfficeMDITabSet);
var
frmMain: TfrmMain;
LoadDLLForm : TLoadDLLForm;
implementation
uses uChild, uChildP;
{$R *.dfm}
//****************************************************************************//
procedure TfrmMain.Button1Click(Sender: TObject);
begin
LoadMyLibrary('
MyDLL.dll');
end;
//****************************************************************************//
procedure TfrmMain.LoadMyLibrary(Alib :
String);
var
Handle: THandle;
begin
Handle := LoadLibrary(PChar(Alib));
if Handle = 0
then
begin
ShowMessage('
Error loading dll "'+Alib+'
"');
end
else
begin
@LoadDLLForm := GetProcAddress(
Handle, '
LoadDLLForm');
if @LoadDLLForm <>
nil then
begin
LoadDLLForm(Application,Screen,MDITabBar);
end
else
begin
FreeLibrary(
Handle);
ShowMessage('
Could not load library');
end;
end;
end;
//****************************************************************************//
end.
DLL Code
Delphi-Quellcode:
library MyDLL;
uses
SysUtils,
Classes,
Windows,
Forms,
AdvOfficeTabSet,
uChild
in '
uChild.pas'
{frmChild};
var
PrevApplication : TApplication;
PrevScreen : TScreen;
{$R *.res}
//****************************************************************************//
procedure DLLMain(EntryCode: integer);
begin
case EntryCode
of
DLL_PROCESS_ATTACH:
begin
// Do Initialization stuff here. Called when a process loads the DLL
PrevApplication := Application;
PrevScreen := Screen;
end;
DLL_PROCESS_DETACH:
begin
// Do Finalization stuff here. Called when a process unloads the DLL
FreeLibrary (GetModuleHandle ( '
MyDLL.dll'));
Application := PrevApplication;
Screen := PrevScreen;
end;
end;
end;
//****************************************************************************//
procedure LoadDLLForm(ATApp : TApplication; S: TScreen;
var AMDITabBar : TAdvOfficeMDITabSet);
export;
begin
Application := ATApp;
Screen := S;
frmChild := TfrmChild.Create(Application);
frmChild.FormStyle := fsMDIChild;
frmChild.Caption := '
Patient Data';
AMDITabBar.AddTab(frmChild);
end;
//****************************************************************************//
exports LoadDLLForm;
begin
DLLProc := @DLLMain;
DLLMain(DLL_PROCESS_ATTACH);
end.