delphi中一个值得大家来考虑的DLL问题
所属分类:
软件编程 / Delphi
阅读数:
79
收藏 0赞 0分享
以下是我的原代码:
==========================================================================================
DPR 单元代码
program Mdiform;
uses
Forms,
UMdiform in ´UMdiform.pas´ {Mainform},
UDM in ´UDM.pas´ {GlobalDM: TDataModule},
UFun in ´UFun.pas´;
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainform, Mainform);
Application.Run;
end.
===============================================================================================
主窗体代码:
unit UMdiform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Udm,StdCtrls;
type
TMainform = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
MyHandle:HWND;
{ Public declarations }
end;
var
Mainform: TMainform;
type
T_ShowTestMng=function (var adm:TMainform) : Boolean; StdCall;
implementation
{$R *.dfm}
procedure TMainform.Button1Click(Sender: TObject);
var
Lib_ :THandle;
_ShowTestMng :T_ShowTestMng;
begin
Lib_:=LoadLibrary(pchar(´MdiChild.dll´));
try
@_ShowTestMng:=GetProcAddress(Lib_,´_ShowTestMng´);
if not(@_ShowTestMng=nil) then
_ShowTestMng(Mainform);
finally
FreeLibrary(Lib_);
end;
end;
procedure TMainform.FormCreate(Sender: TObject);
begin
MyHandle:=Application.Handle;
end;
end.
==============================================================================================
子窗体DLL代码:
library MdiChild;
uses
ShareMem,
UMdiform, //此单元为父窗体单元,在顶目设置中我已经设置了搜索此单元在路径。
Forms,
SysUtils,
Classes,
UChild in ´UChild.pas´ {FrmChild};//FrmChild子窗体的FormStyle属性为FsMDIChild
{$R *.res}
function _ShowTestMng(var adm:TMainform) : Boolean; StdCall;
begin
result:=true;
Application.Handle:=adm.MyHandle;
Application.CreateForm(TFrmChild,FrmChild); //程序就出错在此:出错原因是:Cannot create form. No MDI Forms are currently active.
FrmChild.Show;
end;
exports
_ShowTestMng;
end.
Delphi 调用外部程序并阻塞到外部程序中
这篇文章主要介绍了Delphi 调用外部程序并阻塞到外部程序中的相关知识,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0赞 0分享
修改 Delphi 10.3.3 IDE 字体和字体大小
Delphi,是Windows平台下著名的快速应用程序开发工具(Rapid Application Development,简称RAD)。这篇文章主要介绍了修改 Delphi 10.3.3 IDE 字体和字体大小,需要的朋友可以参考下
收藏 0赞 0分享
delphi 正弦曲线图
在Delphi中没有直接正弦曲线的函数。但是在科学研究中,正弦曲线的应用是非常广泛的,本实例介绍如何绘制正弦曲线。
收藏 0赞 0分享
Delphi中判断文件是否为文本文件的函数
在用Delphi 编程处理文本文件的时候,如果要装载的文件比较大,你可能会想在文件装载过程中提供一个装载进度的提示--那么你就必需自己编写直接通过文件打开/读取函数来装载文件内容的函数。
收藏 0赞 0分享
c# 多线程编程 入门篇
多线程应该是编程工作者的基础技能, 但这个基础对我来讲的确有点难(起码昨天以前是这样).
收藏 0赞 0分享
查看更多