主程序调用DLL窗体 cannot assign a TFont to a TFont 问题的彻底解决方案

jason_28693 2009-12-16 02:42:51
经验共享:
主程序调用DLL窗体 cannot assign a TFont to a TFont 问题的彻底解决方案

在网上搜索N久,总结并实战出来的经验和大家分享
1、中国的网站链接大多建议的方案是 project->options选项的packages标签页面勾选 'Buidl with runtime packages'
我个人在D7中测试确实能够解决问题。但是程序发布的时候需要带很多bpl包。
2、在国外网站搜索到另一种解决方案,就是通过修改系统的controls.pas和graphics.pas两个文件来彻底解决上述问题。
具体链接地址为:http://tengco.spaces.live.com/Blog/cns!689EE398F7BFBE58!150.entry
http://www.delphi3000.com/articles/article_4957.asp?SK=

下面是我的程序做法:
首先、把系统的controls.pas和graphics.pas拷贝到自己的工程目录,并做如下修改
第一步、在controls.pas 的声明部分加入
function GetControlAtom : pointer;
第二步、在controls.pas 的实现部分加入
function GetControlAtom : pointer;
begin
result := @ControlAtom;
end;
第三步、修改graphics.pas的TCanvas.SetFont函数
procedure TCanvas.SetFont(Value: TFont);
begin
FFont.Assign(Value);
end;

给上面的代码加上 try..except保护,编程如下:

procedure TCanvas.SetFont(Value: TFont);
begin
try
FFont.Assign(Value);
except
on Exception do;
end;
end;

第四步、在DLL工程中引入我们修改好的两个文件;
第五步、DLL工程的初始化
procedure myDllProc(dWseason: DWORD);
var
p:^word;
begin
case dWseason of
DLL_PROCESS_ATTACH: begin
oldApp := Application; //保存DLL的Application
oldScr := Screen; //保存DLL的Screen
p := Controls.GetControlAtom;
OldControlAtom := p^;
CoInitialize(nil); //使用了ADO控件所以需要调用此方法
end;
DLL_PROCESS_DETACH: begin
p := Controls.GetControlAtom;
p^ := OldControlAtom;
application := oldApp; //恢复Dll的Application
Screen := oldScr; //恢复Dll的Screen
CoUninitialize(); //使用了ADO控件所以需要调用此方法
end;
end;
end;

procedure InitDll(var app:tapplication; var scr:Tscreen; RealControlAtom:integer);
var
p:^word;
begin
p := controls.GetControlAtom;
if scr <> nil then screen := scr;
application := app;
p^ := RealControlAtom;
end;


library testdll;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions 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 avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
ShareMem,
SysUtils,
Classes,
windows,
Controls in 'Controls.pas',
Graphics in 'Graphics.pas';

exports
InitDll;

begin
DllProc := @myDllProc;
myDllProc(DLL_PROCESS_ATTACH); //DLL入口初始化
end.

主程序调用示例:
...
p := controls.GetControlAtom;
InitDll(application,screen,p^);
...


================ 欢迎一起切磋 =================
发个共享帖子 居然还要给分, 没天理啊!


...全文
757 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yxixhdfqwe 2010-05-06
  • 打赏
  • 举报
回复
正好遇到这个问题了...太感谢了
wxsan 2009-12-16
  • 打赏
  • 举报
回复
支持楼主!
zjh333 2009-12-16
  • 打赏
  • 举报
回复
支持!!!!!!!!!!!
金卯刀 2009-12-16
  • 打赏
  • 举报
回复
好...
跨進程訪問delphi控件,也是用此法。。。。。
FOREST169 2009-12-16
  • 打赏
  • 举报
回复
顶一下
hjkto 2009-12-16
  • 打赏
  • 举报
回复
学习一下
jason_28693 2009-12-16
  • 打赏
  • 举报
回复
自己顶一下 哈哈
bdmh 2009-12-16
  • 打赏
  • 举报
回复
支持一下
内容概要:本文系统研究了移相控制全桥LLC谐振变换器的工作特性,深入分析其在不同工况下的运行机理与性能表现,并基于Simulink平台构建了完整的仿真模型进行验证。文章详细阐述了LLC谐振变换器的电路拓扑结构、工作原理、关键参数设计方法以及移相控制策略的实现机制,重点对电压增益特性、转换效率、软开关实现条件等核心性能指标进行了仿真分析,全面评估了系统在宽输入电压范围内的稳定性、动态响应能力及高效运行区间。; 适合人群:适用于电力电子、电气工程及其自动化等相关专业的高校研究生、科研机构研究人员以及从事高频开关电源、DC-DC变换器设计的工程技术人员;要求读者具备扎实的电路理论基础和一定的Simulink仿真应用经验。; 使用场景及目标:①深入掌握LLC谐振变换器的基本原理与数学建模方法;②理解并应用移相控制策略以提升高效率DC-DC变换器的性能;③通过仿真实践优化谐振腔参数(如谐振电感、励磁电感、谐振电容)与开关频率配置,提高电源系统的整体能效、功率密度和可靠性,服务于实际工程中的电源产品开发与性能验证。; 阅读建议:建议读者结合提供的Simulink仿真模型同步操作,重点探究谐振元件参数变化对系统增益曲线和ZVS软开关实现条件的影响,尝试调节移相角与开关频率以观察动态响应过程,从而深化对LLC变换器高频软开关特性和控制策略的理解。

5,943

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧