Home > Back-end >  How the form and the main form of DLL communicate with each other
How the form and the main form of DLL communicate with each other

Time:09-30

Situation is like that, I wrote a take the Form of Dll, the Form there are 2 buttons for the and button2, a Panel in the main Form, click on the Panel call Dll interface to display the Form of Dll to the main body of a Panel, this is relatively simple to implement, the question now is, when I click for, I want to make the maximization of the main Form of button2 is to minimize the main Form, it is mainly to make a Dll actively communicate with main Form, how to achieve this? Contact of Dll is not a lot before, so please Daniel some comment here,

CodePudding user response:

Wait for Daniel grant instruction, in this thank you

CodePudding user response:

I know: the callback function, send messages,
Can take a look at this:
http://bbs.csdn.net/topics/390795469

CodePudding user response:

Call the DLL, the main window handle to the DLL,
In the DLL when click on the button send messages to the main form,
Main form according to the maximum message,,,

CodePudding user response:

Dll form through the message to control the main form available implements, but new problems come out, I found the form of Dll is invoked after the form controls in the zha is static, for example I use XE6 wrote a Dll, the Dll inside a form, put a TFlowPanel form controls, this control automatic position control function of layout in it, but once the main form call shows that the form of Dll, TFlowPanel controls, there is no automatic layout it controls the location of the work, don't know why

CodePudding user response:

To the master form post a message can ah

CodePudding user response:

DLL form
 

The library dllform;

{Important note about DLL memory management: ShareMem must be the
The first unit in your library 's USES clause AND your project' s (select
The Project - the View Source) USES clause if your DLL exports any procedures or
Functions provides 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 to
The BORLNDMM. DLL Shared memory manager, which must be deployed along
With your DLL. To get the using BORLNDMM. DLL, pass the string information
Using PChar or ShortString parameters.}

USES the
SysUtils, Forms,
Classes,
UnitdllInterface in 'UnitdllInterface. Pas,
Unit3 in 'Unit3. Pas' {Form3};


{$R *. Res}

Procedure ShowDLLForm (Parent: THandle; AInteractionData: TInteractionData); Stdcall;
The begin
Application. Handle:=the Parent;
Form3:=TForm3. Create (Application);
Form3. InteractionData:=aInteractionData;
Form3. Show;
Form3. BringToFront;
end;
Exports
ShowDLLForm;
The begin
End.

The inside of the DLL form
 
The unit Unit3.

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, UnitdllInterface StdCtrls;

Type
TForm3=class (TForm)
Btn1: TButton;
Btn2: TButton;
Procedure btn1Click (Sender: TObject);
Procedure btn2Click (Sender: TObject);
Procedure FormCreate (Sender: TObject);
Procedure FormDestroy (Sender: TObject);
Procedure FormClose (Sender: TObject; Var Action: TCloseAction);
Private
FInteractionData: TInteractionData;
{Private declarations}
Public
The property InteractionData: TInteractionData read fInteractionData write fInteractionData;
end;

Var
Form3: TForm3;

Implementation

{$R *. DFM}

Procedure TForm3. Btn1Click (Sender: TObject);
The begin
FInteractionData. DoAddData (VarArrayOf ([' MAX ']));//e1? Present 3 ido x? 'o? ˉ
end;

Procedure TForm3. Btn2Click (Sender: TObject);
The begin
FInteractionData. DoAddData (VarArrayOf ([' MIN ']));//e1? Present 3 ido x? 'o? ˉ
end;

Procedure TForm3. FormCreate (Sender: TObject);
The begin
FInteractionData:=TInteractionData. Create;
end;

Procedure TForm3. FormDestroy (Sender: TObject);
The begin
FInteractionData. Free;

end;

Procedure TForm3. FormClose (Sender: TObject; Var Action: TCloseAction);
The begin
Action:=caFree;
end;

End.


//one of the most important interactive use
 unit UnitdllInterface; 

Interface


USES the
Classes, Menus, Variants, Graphics, Controls, Forms, Dialogs, StdCtrls;

Type

TOnAddData=https://bbs.csdn.net/topics/procedure (Sender: TObject; Value: the Variant) of the object;

TInteractionData=https://bbs.csdn.net/topics/class
Private
FOnAddData: TOnAddData;
Ftestpara: string;
Public
Procedure DoAddData (Value: the Variant);
The property OnAddData: TOnAddData read fOnAddData write fOnAddData;
The property testpara: string read ftestpara write ftestpara;
end;


Implementation

{TSetData}
Procedure TInteractionData. DoAddData (Value: the Variant);
The begin
If Assigned (fOnAddData) then fOnAddData (self, Value);
end;


End.

//the last one to call DLL main program
 
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls UnitdllInterface;

Type
TForm1=class (TForm)
Btn1: TButton;
Procedure btn1Click (Sender: TObject);
Procedure FormCreate (Sender: TObject);
Private

FInteractionData: TInteractionData;
Procedure AddData (Sender: TObject; Value: the Variant);/send/receive DLL to data
Public
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related