Home > Back-end >  Delphi DLL call form after an error.
Delphi DLL call form after an error.

Time:09-19

RT on the above code,

Click ok after the form is to be able to normal after, according to dynamic tree was gone, but I the inside of the form

Dynamic tree, this place was now empty, tree refresh the function also can appear similar to figure a mistake,
DLL code
 library ProInfoDll; 

USES the
Sharemem,
Forms,
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Dialogs,
Unit1 in 'Unit1. Pas' {Form1},
Unit2 in 'Unit2. Pas' {Form2},
Unit3 in 'Unit3. Pas' {Form3},
Unit4 in 'Unit4. Pas' {Form4},
Unit5 in 'Unit5. Pas' {DataModule5: TDataModule},
Unit6 in 'Unit6. Pas' {Form6},
Unit8 in 'Unit8. Pas' {Form8},
Unit9 in 'Unit9. Pas' {Form9};

{$R *. Res}

Procedure ProvaChild (ParentApplication: TApplication; ParentForm: TForm); Export; Stdcall;
Var
Form1: TForm1;
DllProc: Pointer; {Called whenever a DLL entry point is Called}

The begin
Application:=ParentApplication;

Form1:=TForm1. Create (ParentForm);
Form1. MyParentForm:=ParentForm;
Form1. MyParentApplication:=ParentApplication;
//Windows. SetParent (Form1. Handle, ParentForm. Handle);
//Form1. FormStyle:=fsMDIChild;
Form1. Show;
end;

Procedure DLLUnloadProc (Reason: Integer); The register;
The begin
If a tiny=DLL_PROCESS_DETACH then Application:=DllApplication;
end;

Exports
ProvaChild;

The begin
DllApplication:=Application;
DLLProc:=@ DLLUnloadProc;
End.

Main form call DLL code
 procedure TForm9. ToolButton2Click (Sender: TObject); 
Var
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
The begin
Panel1. Visible:=False;
Panel2. Visible:=False;
DllHandle:=LoadLibrary (' ProInfoDll ');
ProcAddr:=GetProcAddress call (DllHandle, 'ProvaChild');
If ProcAddr & lt;> Nil then
The begin
ProvaChild:=ProcAddr;
ProvaChild (Application, Self);
end;

end;

CodePudding user response:

DLL wife form part of the code
 private 
{Private declarations}
Procedure AddClass (AId: integer; FatherNode: TTreeNode);//add the classification process
Procedure AddDataToDB (CurrNode FatherNode: TTreeNode);//add the actual data to the database
Public
{Public declarations}
MyParentForm: TForm;
MyParentApplication: TApplication;
Procedure FillTreeView (TreeView: TTreeView);



end;

Var
Form1: TForm1;
//CurrentTreeNode: TTreeNode;
//AddChildeTreeNode: TTreeNode;
//flag: Boolean;//used to identify whether you need to update data when rename tree node
DllApplication: TApplication;
Procedure TForm1. AddClass (AId: integer; FatherNode: TTreeNode);
Var
QryTmp: TADOQuery;
MyNode: TTreeNode;
Where: TLabel;
The begin
QryTmp:=TADOQuery. Create (self);
QryTmp. Connection:=ADOConnection2;
QryTmp. SQL. The Add (' select * from Type ');
QryTmp. SQL. The Add (' where ParentID='+ inttostr (AId));
QryTmp. Open;
While not QryTmp. Eof do
The begin
MyNode:=Treeview1. Items. AddChild (FatherNode, QryTmp fieldbyname (' Name '). AsString) are identical.

//create labels, caption for each branch of AutoId icon
Where:=TLabel. Create (self);
Where the Visible:=false;
Where the Caption:=QryTmp fieldbyname (' ID '.) AsString;
MyNode. Data:=where;

AddClass (QryTmp fieldbyname (' ID '.) AsInteger, myNode);//recursive call process
QryTmp. Next;
end;
QryTmp. Free;
end;

Procedure TForm1. AddDataToDB (CurrNode FatherNode: TTreeNode);
Var
Where: TLabel;
QryTmp: TADOQuery;
AId: integer;
The begin
If not assigned (FatherNode) then
AId:=0
Else if not assigned (FatherNode. Data) then
AId:=0
The else
AId:=strtoint (TLabel (FatherNode. Data). The caption);
QryTmp:=TADOQuery. Create (self);
QryTmp. Connection:=ADOConnection2;
QryTmp. SQL. The Add (' select * from Type ');
QryTmp. SQL. The Add (' where ParentID='+ inttostr (AId));
QryTmp. Open;
QryTmp. Append;
QryTmp [' ParentID '] :=AId;
QryTmp [' Name '] :=CurrNode. Text;
QryTmp. Post;

//create records currNode AutoId table is standard
Where:=TLabel. Create (self);
Where the Visible:=False;
Where the Caption:=QryTmp fieldbyname (' ID '.) AsString;
CurrNode. Data:=where;

QryTmp. Free;

end;

Procedure TForm1. FillTreeView (TreeView: TTreeView);
Procedure CreateSubTree (FNodeName: string; Node: TTreeNode=nil);
Var
MLocalName: string;
TreeNode: TTreeNode;
Ads_Tmp: TADODataSet;
The begin
ADS_Tmp:=TADODataSet. Create (Self);
ADS_Tmp. Connection:=DataModule5. ADOConnection2;
With ADS_Tmp do
Try
The Close;
CommandText:='Select * from Type Where ParentID=' + FNodeName;
The Open;
First;
While not Eof do
The begin
MLocalName:=FieldbyName (' ID '.) Asstring;
TreeNode:=TreeView. Items. AddChild (Node, FieldByName (' Name '). AsString) are identical.
CreateSubTree (mLocalName TreeNode);//the loop recursive
Next; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related