【发布时间】:2018-08-11 20:21:24
【问题描述】:
我有一个从TWinControl 派生的组件,其中包含更多标准组件(例如TEdit、TCombobox)。此子组件未发布,因此它们的属性不可见。
但其中一些我想让它们可见,但在我的组件下。
我成功处理了Text、Enabled、ReadOnly 等一些属性,但现在我还想从TComboBox 添加Items。
这意味着,在我编辑自己的 Items 属性后,TCombo 子组件中的 Items 也会发生同样的情况。
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
TSodaEditor = class(TWinControl)
private
FEdit: TEdit;
FCombo: TComboBox;
FAlignment: TAlignment;
FItems: TStrings; //<-------
FText: TCaption;
FOnChange: TNotifyEvent;
FOnEnter: TNotifyEvent;
FOnExit: TNotifyEvent;
FOnClick: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnKeyDown: TEvent_OnKeyDown;
FOnKeyUp: TEvent_OnKeyUp;
FOnKeyPress: TEvent_OnKeyPress;
//....
protected
//....
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
property Items: TStrings read FItems write SetItems;
property Text;
property Visible;
property Enabled;
property Align;
property Font;
property ParentFont;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnExit;
property OnEnter;
property OnClick;
property OnDblClick;
property TabOrder;
end;
有什么简单的方法,或者我应该覆盖TStrings 中的一些方法,以便捕获在Items 下所做的更改?
更新:
通过这个Items,我还想使用AddObject 处理对象。因此,当我从 TCombo 子组件中选择一个项目时,我想获得分配的对象。
【问题讨论】:
标签: delphi components items