TCustomControl クラスから派生したカスタム コンポーネントを開発しています。たとえば、TLabel コンポーネントのように、設計時に編集できる新しい TFont ベースのプロパティを追加したいと考えています。基本的に私が望むのは、フォントのさまざまな属性 (名前、サイズ、スタイル、色など) を変更するオプションをユーザーに追加することです。これらの属性を個別のプロパティとして追加する必要はありません。
私の最初の試み:
class PACKAGE MyControl : public TCustomControl
{
...
__published:
__property TFont LegendFont = {read=GetLegendFont,write=SetLegendFont};
protected:
TFont __fastcall GetLegendFont();
void __fastcall SetLegendFont(TFont value);
...
}
コンパイラがエラー「E2459 Delphi スタイル クラスは、演算子 new を使用して構築する必要があります」を返します。また、データ型 TFont と TFont* のどちらを使用する必要があるかもわかりません。ユーザーが単一の属性を変更するたびに新しいオブジェクト インスタンスを作成するのは効率が悪いように思えます。これをどのように達成できるか、コードサンプルをいただければ幸いです。