有一种情况:两个包:“Base”和“Descendant”以及一个应用程序“Example”。Base 包和 Example 应用程序可以在一个项目组中,但 Descendant 包必须在另一个项目组中,并且没有任何 Base 和 Example 的源代码。
这种操作的目的是向将使用 Descendant 包的工作人员隐藏 Base 和 Application 源。
Base 包包含一个表单:TFormBase,其中包含一些组件和一些代码。我构建它并获取一些二进制文件:bpl、dcp 等...
type
TFormBase = class(TForm)
Panel1: TPanel;
BOk: TButton;
BCancel: TButton;
procedure BOkClick(Sender: TObject);
procedure BCancelClick(Sender: TObject);
private
protected
function GetOkButtonCaption: string; virtual;
function GetCancelButtonCaption: string; virtual;
public
end;
implementation
{$R *.dfm}
procedure TFormBase.BCancelClick(Sender: TObject);
begin
ShowMessage('"' + GetCancelButtonCaption + '" button has been pressed');
end;
procedure TFormBase.BOkClick(Sender: TObject);
begin
ShowMessage('"' + GetOkButtonCaption + '" button has been pressed');
end;
function TFormBase.GetCancelButtonCaption: string;
begin
Result := 'Cancel';
end;
function TFormBase.GetOkButtonCaption: string;
begin
Result := 'Ok';
end;
后代包包含 TFormDescendant = class(TFormBase)
type
TFormDescendant = class(TFormBase)
private
protected
function GetOkButtonCaption: string; override;
function GetCancelButtonCaption: string; override;
public
end;
implementation
{$R *.dfm}
function TFormDescendant.GetCancelButtonCaption: string;
begin
Result := 'Descendant Cancel';
end;
function TFormDescendant.GetOkButtonCaption: string;
begin
Result := 'Descendant Ok';
end;
以及 Descendant.dfm 的代码:
inherited FormDescendant: TFormDescendant
Caption = 'FormDescendant'
end
后代.dpr:
requires
rtl,
vcl,
Base;
contains
Descendant in 'Descendant.pas' {FormDescendant};
创建 FormDescendant 时,它应该看起来像 FormBase,因为它只是从它继承而来。我们可以在这个 FormDescendant 保存 FormBase 外观上添加一些其他组件。
但是当我们尝试在 Delphi IDE 中打开 FormDescendant 时,它会因“创建表单时出错:未找到‘TFormBase’的祖先”而崩溃。没错:Base.bpl 只包含二进制代码,而 Delphi 不知道 TBaseForm 在设计时的样子。
在 Delphi 中打开 FormDescendant 应该怎么做?
我已阅读如何在 Delphi 中使用或解决可视化表单继承问题?并注册自定义表单,以便我可以从多个项目继承它,而无需将表单复制到对象存储库文件夹 但这些建议没有帮助。 有没有办法在没有 TFormBase 来源的情况下在设计时打开 FormDescendant?
这是实验示例的项目:http: //yadi.sk/d/IHT9I4pm1iSOn