Delphi で、ジェネリックを使用して TForm から派生した基本フォーム クラスを定義できるかどうか疑問に思っています。私が取り組んでいるアプリケーションは、さまざまなハードウェア デバイス (シリアル ポート、USB、イーサネットなどを介して) と対話し、各デバイスがそのデバイスに固有のプロパティを含むプロパティ フォームを表示できるようにしたいと考えています。
これまでのところ、次のコードがあります...
// DEVICE MODEL...
// Interface defining a device
IDevice = interface
procedure ShowPropertyForm;
// ... Other procedures and functions
end;
// Abstract base device class
TDevice = class(IDevice)
protected
// Override this function to show their property form
procedure DoShowPropertyForm; virtual; abstract;
public
// Calls Self.DoShowPropertyForm;
procedure ShowPropertyForm;
end;
TSerialDevice = class(TDevice)
protected
// Creates and shows the TSerialDeviceForm below
procedure DoShowPropertyForm; override;
end;
// Represents a device capable of providing positioning information
TGpsDevice = class(TSerialDevice)
protected
// Creates and shows the TGpsDeviceForm below
procedure DoShowPropertyForm; override;
end;
// FORM MODEL...
// Represents a base form, with skinning functionality, etc
TBaseForm = class(TForm)
end;
// Base device properties form, allows the form to access a strongly-typed
// version of the IDevice
TDeviceForm<T : IDevice> = class(TBaseForm)
private
FDevice : T;
public
// Accessor for the associated IDevice
property Device : T read FDevice write FDevice;
end;
// Property form for a TSerialDevice, has controls for controlling port name
// baud rate, stop/start bits, etc
TSerialDeviceForm = class(TDeviceForm<TSerialDevice>)
end;
// Property form for a TGpsDevice, has controls in addition to what is
// provided by the TSerialDeviceForm
TGpsDeviceForm = class(TSerialDeviceForm)
end;
問題は、フォーム デザイナーにアクセスしようとしたときに発生します。例として、TBaseForm には「OK」ボタンと「キャンセル」ボタンが含まれています。TDeviceForm に機能を追加したいのですが、デザイナを開こうとすると、次のエラーが表示されます...
フォーム作成エラー: ルート クラスが見つかりません: ""。
同様に、TGpsDeviceForm デザイナを開こうとすると、次のエラーが発生します...
フォーム作成エラー: 'TSerialDeviceForm' の祖先が見つかりません。
Delphi フォーム デザイナーはジェネリックを処理できないと思いますが、この問題を回避するためのより良い方法はありますか?
DFM ファイルでは、TBaseForm 以外のすべてについて、最初の行を次のように変更しました。
オブジェクト DeviceForm: TDeviceForm から継承された DeviceForm: TDeviceForm
しかし、これは違いはないようです。
誰でもアドバイスを提供できますか?前もって感謝します!