A dll issue worth consideration in Delphi

Source: Internet
Author: User


Below is my original Code :
========================================================== ========================================================== ============
DPR unit code
Program mdiform;
Uses
Forms,
Umdiform in 'umdiform. pa' {mainform },
UDM in 'udm. pa' {globaldm: tdatamodule },
Ufun in 'ufun. pa ';
{$ R *. Res}
Begin
Application. initialize;
Application. createform (tmainform, mainform );
Application. Run;
End.
========================================================== ========================================================== ====================
Main form code:
Unit umdiform;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, UDM, stdctrls;
Type

Tmainform = Class (tform)
Button1: tbutton;
Procedure button1click (Sender: tobject );
Procedure formcreate (Sender: tobject );
Private
{Private Declarations}
Public
Myhandle: hwnd;
{Public declarations}
End;
VaR
Mainform: tmainform;
Type
T_showtestmng = function (var adm: tmainform): Boolean; stdcall;
Implementation
{$ R *. DFM}
Procedure tmainform. button1click (Sender: tobject );
VaR
Lib _: thandle;
_ Showtestmng: t_showtestmng;
Begin
Lib _: = loadlibrary (pchar ('mdichild. dll '));
Try
@ _ Showtestmng: = getprocaddress (LIB _, '_ showtestmng ');
If not (@ _ showtestmng = nil) then
_ Showtestmng (mainform );
Finally
Freelibrary (LIB _);
End;
End;
Procedure tmainform. formcreate (Sender: tobject );
Begin
Myhandle: = application. Handle;
End;
End.
========================================================== ========================================================== ====================
Sub-form DLL code:
Library mdichild;
Uses
Sharemem,
Umdiform, // This unit is the parent form unit. In the top object settings, I have set to search for this unit in the path.
Forms,
Sysutils,
Classes,
Uchild in 'uchild. pa' {frmchild}; // The formstyle attribute of the frmchild child form is fsmdichild.
{$ R *. Res}
Function _ showtestmng (var adm: tmainform): Boolean; stdcall;
Begin
Result: = true;
Application. Handle: = adm. myhandle;
Application. createform (tfrmchild, frmchild );// Program This error occurs because cannot create form. No MDI forms are currently active.
Frmchild. show;
End;
Exports
_ Showtestmng;
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.