2012-05-17 46 views
2

我在寫簡單的組件。我想實現的是根據我選擇的方法,我的MethodOptions將在Object Inspector中更改。在設計時更改自定義組件中的屬性類

事情是這樣的:

From DevExpress cxGrid

到目前爲止,我編碼:

TmyMethod = (cmFirst, cmSecond); 

    TmyMethodOptions = class(TPersistent)  
    published 
     property SomethingInBase: boolean; 
    end; 

    TmyMethodOptionsFirst = class(TmyMethodOptions) 
    published 
     property SomethingInFirst: boolean; 
    end; 

    TmyMethodOptionsSecond = class(TmyTMethodOptions) 
    published 
     property SomethingInSecond: boolean; 
    end; 

    TmyComponent = class(TComponent) 
    private 
     fMethod: TmyMethod; 
     fMethodOptions: TmyMethodOptions; 
     procedure ChangeMethod(const Value: TmyMethod); 
    public 
     constructor Create(AOwner: TComponent); override; 
     destructor Destroy; override; 
    published 
     property Method: TmyMethod read fMethod write ChangeMethod default cmFirst; 
     property MethodOptions: TmyMethodOptions read fMethodOptions 
     write fMethodOptions; 
    end; 

implementation 

procedure TmyComponent.ChangeMethod(const Value: TmyMethod); 
begin 
    fMethod := Value; 

    fMethodOptions.Free; 
    // case... 
    if Value = cmFirst then 
    fMethodOptions := TmyMethodOptionsFirst.Create 
    else 
    fMethodOptions := TmyMethodOptionsSecond.Create; 

// fMethodOptions.Update; 
end; 

constructor TmyComponent.Create(AOwner: TComponent); 
begin 
    inherited; 
    fMethodOptions := TmyMethodOptions.Create; 

    fMethod := cmFirst; 
end; 

destructor TmyComponent.Destroy; 
begin 
    fMethodOptions.Free; 

    inherited; 
end; 

當然它 幾乎 什麼(除了掛IDE)和我沒有任何啓動指出在哪裏搜索合適的知識來實現​​這一點。

+3

我不認爲OI關心屬性的實際類型,它只顯示聲明類型的屬性(即我認爲這是不可行的)。 –

回答

1

如果我理解正確,我相信這是Developer Express在其Quantum Grid組件中實現的相同技術,用於爲網格中的各種字段類型動態顯示不同的屬性。這裏有一個機制的解釋:Technology of the QuantumGrid

相關問題