The MDI child form that encapsulates VCL in the DLL dynamic link library in Delphi

Source: Internet
Author: User

Not much said, look at the code should understand, once I encountered problems, now let everyone share!

Here is the part of the engineering document:

Encapsulating an MDI child form in a DLL requires you to override the DLL entry function, as shown in the following code:

1var
2  DllApp: TApplication;//定义保存原DLL的TApplication对象
3  DllScr: TScreen;//定义保存原DLL的TScreen对象
4
5procedure UnProcDll(Reason: Integer); register;
6//重新定义DLL入口函数
7begin
8  if Reason = DLL_PROCESS_DETACH then
9  begin
10    Application := DllApp;
11    Screen := DllScr;
12  end;
13end;
14
15//初始化区
16begin
17  DllApp := Application;//备份原DLL的TApplication对象
18  DllScr := Screen;//备份原DLL的TScreen对象
19  DllProc := @UnProcDll;//将重写后的入口函数地址付给DLLProc
20end.

Here is the function to be exported, written in the engineering file or in the interface section of a unit:

1function ShowForm(App: TApplication; Scr: TScreen; Owner: TForm):TForm; export; stdcall;
2begin
3  //下面的这两个变量是必须的
4  Application := App;//这个就是调用的时候对Application对象重新赋值
5  Screen := Scr;//对Screen对象赋值
6  //函数自定义代码
7  if not Assigned(Form1) then
8  begin
9    //Application.CreateForm(TForm1, Form1);
10    Form1 := TForm1.Create(Owner);
11    Result := Form1;
12  end
13  else
14    Result := Form1;
15  //函数自定义代码结束
16end;

Finally, in the engineering file to export this function is OK.

1//最后导出这个函数
2exports
3   ShowForm;

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.