DLL encapsulation of MDI child form in Delphi

Source: Internet
Author: User

One question the day before yesterday: when the main form is fsmdiform, the form that calls DLL cannot be embedded in the main form. So I found related information on the Internet and found the answer: DLL encapsulation subform.

After understanding, you can use the same method to call another DLL form in the DLL subform. If you need to return parameters, you can obtain them through the function.
Example:
Add a DLL application and create a new form in the project. Now this DLL is the DLL with the form.
In DLLCode:
Library project2;

{Important Note about dll Memory Management: sharemem must be
First unit in your library's uses clause and your project's (select
Project-View Source) uses clause if your DLL exports any procedures or
Functions that pass strings as parameters or function results. This
Applies to all strings passed to and from your DLL -- even those that
Are nested in records and classes. sharemem is the interface unit
The borlndmm. dll Shared Memory Manager, which must be deployed along
With your DLL. To avoid using borlndmm. dll, pass string Information
Using pchar or parameter string parameters .}

Uses
Sysutils,
Classes,
Forms,
Windows,
Messages,
Unit1 in 'unit1. pa' {form1 };

{$ R *. Res}
VaR
Dllapp: tapplication;

Function showform (VAR app: tapplication; parentform: tform): Boolean; export; stdcall;
Begin
{Obtain the application of the call form. The obvious function is to integrate your form into the call form.Program. It can also perform many operations}
Application: = app; // convert the DLL application into an app
Form1: = tform1.create (parentform); // create a subform that exists and is released along with parentform.
Form1.formstyle: = fsmdichild; // sets the form mode.
Form1.show;
End;

{Rewrite the DLL entry function; otherwise, an error occurs in the program}
Procedure dllunloadproc (reason: integer); register;
Begin
{When the DLL is canceled, the dll_process_detach message is sent, and the DLL application is returned as itself}
If reason = dll_process_detach then application: = dllapp;
End;

Exports
Showform;

Begin
{Pre-store the DLL application at the DLL entry}
Dllapp: = application;
{Dllproc: DLL entry function pointer. Delphi is defined as dllproc: tdllproc ;}
{Point to the function we have defined here}
Dllproc: = @ dllunloadproc;
End.

You only need one tbutton to call the main program unit.
Unit unitmain;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, comctrls, menus, toolwin, rzpanel, cxcontrols, cxcontainer,
Cxtreeview, dxnavbar, dxdockpanel, dxdockcontrol, extctrls, rzsplit;

Type
Tform1 = Class (tform)
MM1: tmainmenu;
N1: tmenuitem;
Pnl1: tpanel;
Fsmdichild1: tmenuitem;
Dll1: tmenuitem;
Procedure dll1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Function showform (VAR app: tapplication; parentform: tform): Boolean; stdcall; External 'project2. dll '; // For simplicity, use the static call Method

Implementation

{$ R *. DFM}

Procedure tform1.dll1click (Sender: tobject );
Begin
Showform (application, self); // call the DLL function to call up the form. Input the Application Object of the current main program and the form1 itself
End;

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.