MDI child package with DLL embodiment

MDI child package with DLL embodiment is a common software development technique, his strengths:

R & D staff to be responsible for the preparation of a module include (+ interface logic), it can interfere with each other, after the completion of the module R & D, the main program unified call. 
Easy-to-upgrade program, when the program upgrade, do not compile the main exe file, update a DLL will be able to upgrade. 
According to different customer needs, giving them the price of different modules. (Profiteers are willing Yongzhe Zhao)
recently used this technique has not been used because younger brother, online google a bit, got to know him, I use the COM-based DLL, summarized below as follows:

Want in the DLL package MDI child form, we should note the following:

Interface DLL you have two parameters: first, the main program of the Application object; the second, the main program window objects; 
you want to override DLL entry function 
if it is based on COM, note: since no COM TApplication and TForm type, when you need to pass strong into Integer.
Need so much attention, the following is an example to see (assuming you have established a project):

  TComDllTest1 = class(TAutoObject, IComDllTest1)
  Private
    FMsgStr: WideString;
    function GetMDIForm(AForm: TForm): boolean;
  protected
    { Protected declarations }
    function Get_MsgStr: WideString; safecall;
    procedure Set_MsgStr(const Value: WideString); safecall;
    procedure ShowMsgStr; safecall;
    procedure CreateForm(AHandle: SYSUINT); safecall;
    procedure CreateMdiForm(var AApp; AForm: SYSINT); safecall;    //创建MDI窗体 SYSINT为unsigned int
    procedure CreateComTest(AForm: SYSUINT); safecall;
  public
    constructor Create(AForm: SYSINT);
  end;

This is achieved CreateMdiForm method:

TComDllTest1.CreateMdiForm Procedure (var AAPP; the aForm: SYSINT);
var
  App: TApplication;
  AF: a TForm;
the begin
  App: = TApplication (AAPP); // The Application object passed in turn strongly
  af: = TForm (AForm); / / the Form object passed in turn strongly

  Application: = app; // main program will be paid to the application of engineering application COM objects

  if not GetMDIForm (Form1) then // GetMDIForm is to determine whether the form has been created
  the begin
    Form1: = TForm1.Create (af); // Create a child form
  Form1.FormStyle: = fsMDIChild;
  Form1.Show;
  End;
End;

The last step is the most crucial is to rewrite the DLL entry function, an error will be reported if the address is not rewritten, close the main window, I'll eat this loss (I Khan ......), the DLL project document write:

DLLUnloadProc Procedure (Reason: Integer); the Register;
the begin
 IF (Reason = DLL_PROCESS_DETACH) or (Reason = DLL_THREAD_DETACH) the then Application: = DLLApp; // global TApplication objects DLLApp is defined in the DLL project document
                                          // used to save the Application object
end;

DLL initialization added to the position of:

   DLLApp: = Application; // Reserved the Application
   DLLProc: = @DLLUnloadProc; // the address of the rewritten entry function paid DLLProc

This realization of the DLL package MDI child form, of course, you want to be in the child form such as: database operations, but also a richer interface, will certainly run into various problems. After the summary to say it! ^ _ ^

Guess you like

Origin www.cnblogs.com/bdqczhl/p/10937169.html