插件设计2

  上次说到使用插件来实现应用程序功能的扩充。但是后来实现的时候发现一个问题。就是在DLL中的窗体实现加载的时候,居然会报告一个错误:

   Can't   Assign A TFont To A TFont,经过多方的查找,找到如下资料:

21. Can I pass objects to a DLL? (Also: Why does it say 'Cannot assign a TFont to a TFont'?)

Yes, you can, but there's a catch. The DLL will not use the same classes as the main program even when compiled from the same source. Objects will look the same, but their classes will not compare equal. That's why assigning a TFont value from the DLL to a TFont property in the main program (or the other way around) doesn't work: the Assign procedure is looking for the main program's TFont class, and never recognises the DLL's TFont object.

Using packages instead of normal DLLs solves this problem. Packages use the main program's classes. This is the preferred solution.

 

意思是说在DLL中的类和其宿主程序中的类是不同的,哪怕他们的编译代码相同,他们也是不同的类型,说最好的解决方案是使用 Delphi的包。

另一个方法是:

In this you have to edit graphics.pas found in /source/vcl.

First find the code below

procedure TCanvas.SetFont(Value: TFont);
begin
  FFont.Assign(Value);
end;

and add a try..except statement like so

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

then recompile.

修改Delphi的Graphics的TCanvas的SetFont过程,在那添加一个异常处理。这样则可跳过处理,但是似乎不是什么好的解决方案。

  无奈之下,只好采用Delphi的包来实现插件。但是采用包的同时,我却发现一个问题,在反复的

LoadPackage和UnLoadPackage的时候,程序则会出现错误!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值