DLL中报'Cannot assign a TFont to a TFont'的问题
来源:互联网 发布:java单例设计模式 编辑:程序博客网 时间:2024/05/17 17:59
写了一个DLL,在DLL中创建了一个窗口,并使用的ADO控件操作数据库。宿主程序初始化DLL和显示DLL窗口都没有问题,但是在执行DLL窗口中数据库操作时就会报'Cannot assign a TFont to a TFont'这样一个错误。网上搜索了一下,找到了一个解决方法,如下:
主要是由于在创建Dll的Form时,将外部调用程序的Application、Screen和MainForm都传给了Dll并且将Dll中的这几个对象都替换掉了的缘故,解决的办法是只需将外部调用程序的Application.Handle及MainForm传给Dll并替换掉Dll中的这两项值就可以了。如:
var
p: PLongInt;
{DllApp: TApplication Dll中的Application
OutApp: TApplication 外部调用程序的Application
}
p:=@(DllApp.MainForm);
DllApp.Handle := OutApp.Handle;
p^:=LongInt(OutApp.MainForm);
这样处理一下就能解决这个问题,但究竟是什么原因呢?
按照上面的方法修改了代码,编译运行,进行数据库操作时,弹出ADOConnection登录验证输入用户名和密码的小窗口,输入完成后,数据库操作正常了。突然想到是不是因为弹出验证小窗口的原因?于是,将ADOConnection的LoginPrompt属性置为False,去掉上边的代码,编译运行,数据库操作也正常了。果然如此!
可是为什么按照下面的写法不可以,而按照上面的写法就可以呢?
开始是这样的代码:
DllApplication := Application; //先将Dll的Application存到一个变量中
Application := ParentApplication; //将宿主的Application赋值给Dll的Application,这样使Dll加入到宿主的消息循环中去
按照这个写法在弹出数据库验证小窗口时就会报错,而按照网上的那段代码就不会报错。
- DLL中报'Cannot assign a TFont to a TFont'的问题
- 关于Dll中“cannot assign a tfont to a tfont ”问题
- 主程序调用DLL窗体 cannot assign a TFont to a TFont 问题的彻底解决方案
- 主程序调用DLL窗体 cannot assign a TFont to a TFont 问题的彻底解决方案
- DLL:cannot assign a tfont to a tfont
- Cannot assign a TFont to a TFont
- Cannot assign a TFont to a TFont!!
- cannot assign a tfont to a tfont
- delphi7 Cannot assign a TFont to a TFont问题
- 调用DLL窗体 cannot assign a TFont to a TFont 问题
- 主程序调用DLL窗体cannot assign a class to a class问题的彻底解决方案
- TFont里的字体大小
- TFont 类的常用属性:
- Cannot assign a device to node
- Delphi 的绘图功能[10] - TFONT 类
- iOS 初始化报错 cannot assign to self outside of a method in the init
- 报错cannot assign to 'self' outside of a method in the init family
- 子类中初始化错误Cannot assign to ’self’ outside of a method in the init family
- 轻松玩转CreateRemoteThread
- VC中Tab control控件之应用
- CxImage读取与创建多页TIFF文件
- C#四种排序算法
- 关于ie6下iframe的高度bug
- DLL中报'Cannot assign a TFont to a TFont'的问题
- 函数返回表
- tomcat之server.xml列表
- POJ_3100
- iphone模型数据 实例
- 我的blog中文章版权申明
- Ibatis 的 Example 类的使用
- 著名网站系统架构设计
- 关于Mysql分页的两种方法