ある状況: 2 つのパッケージ: "Base" と "Descendant"、およびアプリケーションの "Example"。ベース パッケージとサンプル アプリケーションは 1 つのプロジェクト グループにある場合がありますが、子孫パッケージは別のプロジェクト グループにある必要があり、ベースとサンプルのソース コードはありません。
このような操作の目的は、子孫パッケージを操作するワーカーから Base および Application ソースを隠すことです。
基本パッケージには、いくつかのコンポーネントといくつかのコードを含むフォーム 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