我有一个加载BPL的应用程序,它是一个简单的表单。访问Delphi中的公共方法和属性BPL
此表单是主应用程序的一个可选选项。
BPL加载正确,窗体显示正确,但我不知道如何访问bpl中窗体的公共方法和属性。
任何人都可以提供一个简单的例子吗?
我的代码:
// Load the BPL on aplication Load
LoadPackage('About.bpl');
// CAll for TForm1 inside the About.BPL
var
AClass: TClass;
AForm: TForm;
begin
AClass := GetClass('TForm1');
if AClass <> nil then
begin
Application.CreateForm(TComponentClass(AClass), AForm);
AForm.Show;
end;
// The unit TForm1 inside the BPL package
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
PublicMthd;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Procedure TForm1.PublicMthd;
Begin
ShowMessage('Inside call');
End;
initialization
RegisterClass(TForm1);
finalization
UnRegisterClass(TForm1);
end.
我怎么能在Tform1访问 “PublicMthd”?
向我们展示您的代码的样子。有多种方法可以加载BPL文件,答案取决于你如何做。 – 2011-12-18 23:55:16
另请参阅此SO问题:[执行从表单创建类的引用德尔福](http://stackoverflow.com/questions/2991934/execute-a-method-from -a-form-created-by-class-reference-delphi) – 2011-12-19 00:01:50
你写过这个BPL吗?为什么不导出名为GetMainForm的函数,然后调用'function GetMainForm:TForm',然后可以访问它?有没有理由不能使用常识方法?一旦你知道这些类,并且可以枚举它们,甚至可以创建它们的实例,你打算做什么?是否有理由不指定适合问题域的IPluginInterface,而不是直接从主应用程序转到基础类类型? – 2011-12-21 21:35:33