组件:从 TComboBox 更新 Items
Component: Update `Items` from `TComboBox`
我有一个派生自 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
来处理对象。因此,当我 select 来自 TCombo
子组件的项目时,我想分配对象。
您可以简单地公开 直接 从您自己的 Items
getter/setter 访问 TComboBox.Items
。根本不需要 FItems
成员。
property Items: TStrings read GetItems write SetItems;
function TSodaEditor.GetItems: TStrings;
begin
Result := FCombo.Items;
end;
procedure TSodaEditor.SetItems(AValue: TStrings);
begin
FCombo.Items.Assign(AValue);
end;
我有一个派生自 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
来处理对象。因此,当我 select 来自 TCombo
子组件的项目时,我想分配对象。
您可以简单地公开 直接 从您自己的 Items
getter/setter 访问 TComboBox.Items
。根本不需要 FItems
成员。
property Items: TStrings read GetItems write SetItems;
function TSodaEditor.GetItems: TStrings;
begin
Result := FCombo.Items;
end;
procedure TSodaEditor.SetItems(AValue: TStrings);
begin
FCombo.Items.Assign(AValue);
end;