DLL encapsulation of MDI child forms is a common software development technology, which has the following advantages:
Personnel can write a module, including (interface + logic), without interfering with each other. After the module is developedProgramUnified Call.
Program upgrade: when the program is upgraded, you can update a DLL without compiling the main EXE file. Different modules can be provided to customers based on their different needs and prices. (ALL profiteers are willing to use this trick.) I used this technology because my younger brother has never used it. I Googled it on the Internet and learned about it. I used a com-Based DLL, the following is a summary:
To encapsulate an MDI subform in a DLL, note the following:
The interface in your dll must have two parameters:
First, the Application Object of the main program;
Second, the form object of the main program; you need to rewrite the DLL entry function. If it is based on COM, note: Because COM does not have the tapplication and tform types, you need to convert it into integer during input. There are so many things to pay attention to. Let's take a look at the example below (assuming you have already created 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; create an MDI form sysint as unsigned Int
Procedure createcomtest (AForm sysuint); safecall;
Public
Constructor create (AForm sysint );
End;
This is the implementation of the createmdiform method:
Procedure tcomdlltest1.createmdiform (var aapp; AForm sysint );
VaR
APP tapplication;
AF tform;
Begin
App = Tapplication (AAPP); convert the passed application object
AF = Tform (AForm); convert the passed form object
Application = APP; pay the application of the main program to the Application Object of the COM Project
If Not getmdiform (form1) Then getmdiform is used to determine whether the form has been created
Begin
Form1 = Tform1.create (AF); Create a subform
Form1.formstyle = Fsmdichild;
Form1.show;
End;
End;
The last step is to rewrite the DLL entry function. If you do not rewrite the function, an address error will be reported when you close the main form. I have suffered this loss (my sweat ......), write in the DLL project file:
Procedure dllunloadproc (reason integer); register;
Begin
If (reason = dll_process_detach) or (reason = dll_thread_detach) Then application = dllapp;
// Dllapp is the global tapplication object defined in the DLL project file to save the Application Object
End;
Add the following to the DLL initialization position:
Dllapp = application; reserved for ication
Dllproc = @ dllunloadproc; pay the address of the rewritten entry function to dllproc.
In this way, the DLL encapsulation of the MDI sub-form is implemented. Of course, you must perform operations on the sub-form, such as database operations, and a richer interface, which will certainly encounter various problems. I will summarize it later! Pai_^