delphi - 在设计时更改自定义组件中的属性类

标签 delphi delphi-xe2

我正在编写简单的组件。我想要实现的是,我的 MethodOptions 将根据我选择的方法在对象检查器中更改。

类似这样的事情:

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),而且我没有任何起点来搜索合适的知识来实现​​这一点。

最佳答案

如果我理解正确的话,我相信这与 Developer Express 在其 Quantum Grid 组件中实现的技术相同,用于动态显示网格中各种字段类型的不同属性。这里有对该机制的解释:Technology of the QuantumGrid

关于delphi - 在设计时更改自定义组件中的属性类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10635326/

相关文章:

delphi - 如何为所有私有(private)/ protected 方法生成 Rtti 信息?

delphi - 泛型类中的内部 const 似乎不是由编译器计算的

windows - 应用效果时,MakeScreenshot 未正确渲染

delphi - VirtualTreeview 节点,将它们传递给另一种形式?

image - 使用自定义图像网格

delphi - 如何在 Delphi 搜索路径中使用系统变量?

delphi - DBGrid 滚动页面而不是行

Delphi IFilter 实现

delphi - 方法之前或之后的数据字段是否有约定? (在类,对象或记录中)

delphi - 如何检查加载到 FMX.TBitmap 的 PNG 图像是否具有 alpha channel ?