主程序调用DLL窗体 cannot assign a TFont to a TFont 问题的彻底解决方案
主程序调用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^);
...
================ 欢迎一起切磋 =================
发个共享帖子 居然还要给分, 没天理啊!
相关推荐
Delphi
除了直接使用TFont组件,Delphi还提供了许多第三方库和组件,如FastCode DLL、Jedi Code Library等,这些资源进一步扩展了字体处理的功能,包括更复杂的文字排版、文字特效和本地化支持
MemProof 操作说明
例如,在调用`LoadCursor`函数时未能正确处理。4. **其他常见的内存泄露问题**:包括但不限于在使用Delphi/C++ Builder进行开发时的一些常见错误。
Delphi 13.1控件之2026浪漫萨克斯 放松的烛光晚餐.zip
;资源释放环节须调用FreeAndNil确保对象彻底销毁;多线程环境下播放操作应置于主线程或通过TThread.Synchronize安全同步。
Delphi 7 经典控件之DevExpress.Inspector.v2.01.D67.rar
组件内部无任何外部 DLL 依赖,全部代码以静态链接方式编译进目标应用程序,部署时仅需分发主程序 EXE 文件即可独立运行。
超扭滑模与快速终端滑模的永磁同步电机无感控制:理论、离散化实现与仿真研究(Simulink仿真实现)
内容概要:本文聚焦于超扭滑模控制(STSMC)与快速终端滑模控制(FTSMC)在永磁同步电机(PMSM)无位置传感器控制中的应用,系统地开展了理论分析、离散化实现与Simulink仿真实验研究。重点探讨了这两种高阶滑模控制策略在零低速工况下的控制性能,通过设计基于磁链观测器的无感估计算法,实现了对电机转子位置与速度的精确估计,有效规避了传统机械传感器带来的成本增加与可靠性下降问题。文中详尽阐述了控制算法的数学建模与推导过程,并针对数字控制系统的特点进行了严谨的离散化处理,最终在Simulink环境中搭建了完整的电机控制仿真模型,通过对比实验全面评估了不同控制策略在动态响应速度、抗外部干扰能力和稳态控制精度等方面的综合性能。; 适合人群:具备自动控制理论、电机驱动原理等专业知识,并熟悉MATLAB/Simulink仿真环境操作的电气工程、自动化等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入研究超扭滑模与快速终端滑模等高阶滑模控制理论在高性能电机驱动系统中的具体应用与实现方法;②掌握永磁同步电机在零低速段无位置传感器控制的核心算法,特别是基于磁链观测的转子状态估算技术;③学习如何将连续域的先进控制理论转化为适用于实际数字控制器的离散化算法,并完成从理论到仿真的完整闭环验证。; 阅读建议:此文理论深度与实践操作紧密结合,读者应重点关注控制算法的设计思想、离散化实现的关键步骤以及Simulink仿真模型的构建细节,建议在阅读过程中动手复现仿真模型,通过调整控制器参数来深入理解各模块的功能作用及系统整体的动静态性能表现。


