2012-05-17 47 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

相关问题