AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

MDI Child form in DLL

Ein Thema von FaNIX · begonnen am 12. Mär 2008
Antwort Antwort
FaNIX

Registriert seit: 8. Okt 2007
36 Beiträge
 
#1

MDI Child form in DLL

  Alt 12. Mär 2008, 08:10
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.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz