cannot assign a tfont to a tfont
来源:互联网 发布:歌帝梵巧克力 知乎 编辑:程序博客网 时间:2024/05/17 10:57
只需要将 ParentFont置为False
http://blog.163.com/xd8171@126/blog/static/62081043200910179332166/
http://hi.baidu.com/jangill/item/4daeb8f1b5c68517ce9f325c
http://hi.baidu.com/jangill/item/53b6d8b896049ea4eaba935a
以TImage为例,运用程序要调用Dll中创建的Timage控件,将图片显示到外部DC,如果将TImage 赋值,通常会出现 “cannot assign a tfont to a tfont”的错误,因为dll不支持TFont的直接赋值。 这样的话,我们只需要将 控件的 ParentFont 属性设为 False 就可以。
不过由于TImage的ParentFont(派生于TControl)没有public 或 published,所以对TImage稍微做点工作。
type
TMyImage = class(TImage)
private
protected
public
published
property ParentFont;
end;
在Dll创建的TImage用 TMyImage类 代替,只需要将 ParentFont置为False,在接口函数中传入运用程序
Form窗口的Self(TWinControl)值作为 MyImage.Parent 。
procedure InitImage(AParent: TWinControl);
var
oSelImg: TMyImage;
begin
oSelImg:=TMyImage.Create(nil);
oSelImg.AutoSize:=true;
oSelImg.Picture.LoadFromFile('d:\11.bmp');
oSelImg.ParentFont:= False;
oSelImg.Parent:= AParent;
oSelImg.Show;
end;
不过,这样的参数传递自然比不上直接传DC的Handle方便,我们需要在DLL中做一下改动来实现。
var
ControlAtom: TAtom;
ControlAtomString: string;
RM_GetObjectInstance: DWORD;// registered window message
procedure _InitControls;
begin
ControlAtomString:= Format('ControlOfs%.8X%.8X', [GetModuleHandle(nil), GetCurrentThreadID]);
ControlAtom:= GlobalAddAtom(PChar(ControlAtomString));
RM_GetObjectInstance:= RegisterWindowMessage(PChar(ControlAtomString));
end;
function _FindControl(Handle:HWnd):TWinControl;
var
OwningProcess: DWORD;
begin
Result:= nil;
if (Handle<>0) and
(GetWindowThreadProcessID(Handle,OwningProcess)<>0) and
(OwningProcess=GetCurrentProcessId)then
begin
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
Result:= Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result:= Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
end;
end;
procedure InitImage(AParent: HWND);
var
oSelImg: TMyImage;
begin
oSelImg:=TMyImage.Create(nil);
oSelImg.AutoSize:=true;
oSelImg.Picture.LoadFromFile('d:\11.bmp');
oSelImg.ParentFont:= False;
oSelImg.Parent:= _FindControl(AParent);
- 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 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 device to node
- TFont里的字体大小
- TFont 类的常用属性:
- 主程序调用DLL窗体cannot assign a class to a class问题的彻底解决方案
- OPCAutomation_TLB.pas(1240): Cannot assign to a read-only property 问题解决
- cannot assign to 'self' outside of a method in the init family
- Cannot assign to 'self' outside of a method in the init family
- 关于error:Cannot assign to 'self' outside of a method in the init family
- Hitech 公司完全免费的学习版 PICC-Lite 编译器套件
- 视图 v$sql,v$sqlarea,$sqltext,v$sqltext_with_newlines 的差异
- Maven实战(三)Eclipse构建Maven项目
- 消息称Surface手机仅为微软B计划 未必真上市
- 许一力:另类经济学视角下的食品安全问题
- cannot assign a tfont to a tfont
- DoG 、Laplacian、图像金字塔详解
- poj2352 Star
- unity3d中使用贝塞尔曲线
- hive 学习笔记(三)-----优化策略,函数定义,web接口
- PIC 单片机 中的堆栈是硬件实现的,其深度已随芯片而固定,无法实现需要大量堆栈操作的递归算法
- SQLite的使用完成增删改查等
- 能用到辅助驾驶系统的三个代码:特征点匹配,线段、消失点检测
- C# 局域网聊天 发送信息