使用BPL加载Delphi对象运行时 [英] Loading a Delphi Object Run Time using BPL

查看:314
本文介绍了使用BPL加载Delphi对象运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个班级在一个单位。通常,当我改变其方法的算法时,我必须重新编译并提供整个补丁。
我认为使用DLL创建类的实例。在delphi.about.com中搜索后,我发现不用使用DLL,我可以使用BPL。它是Delphi的一个DLL。问题是几乎所有的例子,我发现只是告诉如何导出一个功能。
我想动态加载BPL,每当我更换BPL,我可以得到类的最新算法,不仅仅是我导出的函数。



文章我已阅读:

- http:// delphi.about.com/od/objectpascalide/a/bpl_vs_dll.htm

- 用于Delphi应用程序的插件系统 - bpl vs dll?

- http://delphi.about.com/library/weekly/aa012301a.htm



任何URL或SAMPLE如何从头创建BPL以封装组件或类非常感谢。






亲爱的大师,



假设我有这样的代码:

  unit unitA; 

接口

类型
B =类(TObject)
public
procedure HelloB;
结束

A = class(TObject)
public
函数GetB:B;
函数HelloA:String;
程序帮助;
结束

实现

使用
对话框;

{B}

程序B.HelloB;
begin
ShowMessage('B');
结束

{A}

函数A.GetB:B;
begin
结果:= B.创建;
结束

函数A.HelloA:String;
begin
结果:='你好,这是A';
结束

程序A.帮助;
begin
//做某事
end;

结束。

我想导出所有的公共方法A.如何使它成为一个DLL?
如何从另一个单位使用它进行导入?
让我们说:

  var a:A; 

a:= A.创建;
a.GetB;
showMessage(a.HelloA);

A没有在单元中声明(它在DLL中)。
请指教。






Hurray。我昨晚得到了所有我要做的是使对象实现一个在调用单元中使用的接口来捕获由DLL返回的对象的实例。



谢谢大家。 / p>

解决方案

将类放在外部文件中的问题是,您的主要应用程序需要知道某种方式来引用它。它将不得不从一个基类下降,它将所有需要的方法作为虚拟方法公开,或者实现一个包含所需的所有功能的接口。



如果您已经知道对象的界面应该是什么样子,并且您正在改变的所有内容都是实现细节,例如内部算法,可能最简单的方法是让您的类实现一个界面并将其放在导出一个函数返回此接口的实例。这样你就不用担心将你的应用程序分解成包,这可能是一个真正的麻烦。


I have a class in a unit. Usually, when I changed the algorithm of its methods, I have to recompile it and deliver the patch as a whole. I think to create the instance of the class using DLL. After searching in delphi.about.com, I found that instead of using DLL, I can use BPL. It is a DLL for Delphi. The problem is almost all examples I found is only telling how to export a function. I want to dynamically load the BPL, and whenever I replace the BPL, I can get the latest algorithm of the class, not only the functions I export.

Article I have read:
- http://delphi.about.com/od/objectpascalide/a/bpl_vs_dll.htm
- Plugins system for Delphi application - bpl vs dll?
- http://delphi.about.com/library/weekly/aa012301a.htm

Any URL or SAMPLE how to create a BPL from scratch to encapsulate a component or a class is greatly appreciated.


Dear Guru,

Suppose I have code like this:

unit unitA;

interface

type
  B = class(TObject)
  public
    procedure HelloB;
  end;

  A = class(TObject)
  public
    function GetB: B;
    function HelloA: String;
    procedure Help;
  end;

  implementation

  uses
      Dialogs;

  { B }

   procedure B.HelloB;
   begin
     ShowMessage('B');
   end;

  { A }

  function A.GetB: B;
  begin
    Result := B.Create;
  end;

  function A.HelloA: String;
  begin
    Result := 'Hello, this is A';
  end;

  procedure A.Help;
  begin
    //do something
  end;

  end.

I want to export all public methods of A. How to make it a DLL? How to use it from another unit where to import it? let's say:

 var a: A;

 a := A.Create;
 a.GetB;
 showMessage(a.HelloA);

A is not declared in the unit (it is in the DLL). Please advise.


Hurray. I got it last night. All I have to do is make the object implement an interface which is used in the caller unit to catch the instance of object returned by the DLL.

Thank you all.

解决方案

The problem with putting a class in an external file is that your main application needs to know some way to refer to it. It will either have to descend from a base class that exposes all the methods you need as virtual methods, or implement an interface that contains all the functionality you need from it.

If you already know what the interface of the object should look like, and all you're changing is implementation details such as internal algorithms, probably the easiest thing would be to make your class implement an interface and put it in a DLL that exports a function that returns an instance of this interface. That way you don't need to worry about breaking your app up into packages, which can be a real hassle.

这篇关于使用BPL加载Delphi对象运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆