Static/dynamic Call DLL encapsulation form (Modal/non-modal)

Source: Internet
Author: User

I wrote an example that some netizens needed.

Please follow the instructions below if there is something wrong or unreasonable.

Delph Xe passed the test.

DLL project file

Library project10; uses sysutils, classes, forms, unit14 in 'unit14. PAS '{form1}; {$ R *. res} function edebtmoney (H: thandle): integer; begin application. handle: = H; with tform1.create (Application) Do try showmodal; Result: = 0; finally free; {destroy window when call ends} end; function getform (H: thandle): thandle; begin application. handle: = H; with tform1.create (Application) Do try show; Result: = handle; handle T on E: exception do raise E. create (E. message); end; exports edebtmoney, getform; beginend.

Form close event in DLL

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin  Action := caFree;end;

Call Unit

Unit unit13; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform13 = Class (tform) btn1: tbutton; btn2: tbutton; procedure btn1click (Sender: tobject); Procedure btn2click (Sender: tobject); Private {private Declarations} public {public declarations} end; var form13: tform13; function myform (H: thandle): thandle; stdcall; implementationfunction myform; External 'project10. DLL 'name' getform '; {$ R *. DFM} // call the modal window procedure tform13.btn1click (Sender: tobject); Type tgetform = function (H: thandle): integer; cdecl; var dllform: tgetform; dllhandle: thandle; NN: integer; begin dllhandle: = loadlibrary (pchar ('project10. dll '); try if dllhandle <> 0 then begin dllform: = getprocaddress (dllhandle, 'edebtmoney'); NN: = dllform (application. handle); self. caption: = inttostr (NN); end; finally freelibrary (dllhandle); end; // static call non-modal window procedure tform13.btn2click (Sender: tobject); var dllhandle: thandle; begin dllhandle: = myform (application. handle); 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.