我希望我的非视觉组件将其发布的属性放在不在Object Inspector顶层的类别下.
以下面的例子为例:

type
TMyComponent = class(TComponent)
protected
function GetSomeValue: string;
function GetSomeValueExt: string;
published
property SomeValue: string read GetSomeValue;
property SomeValueExt: string read GetSomeValueExt;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('My Component', [TMyComponent]);
end;
function TMyComponent.GetSomeValue: string;
begin
Result := 'test';
end;
function TMyComponent.GetSomeValueExt: string;
begin
Result := 'extended..';
end;
Run Code Online (Sandbox Code Playgroud)
如何使用名为MyProperties的类别下的SomeValue和SomeValueExt在Object Inspector中注册我的组件?
插图:

我的组件可能有很多已发布的属性,我宁愿它们在Object Inspector的自有级子类别下面,以使它远离公共属性,如Name和Tag.
谢谢 :)
我正在尝试使用集合属性创建自定义组件.但是,如果我在设计时通过单击对象检查器中的"..."按钮尝试打开集合编辑器,则不会发生任何事情.我错过了什么?
这是我的TCollection后代:
TMyCollection = class(TOwnedCollection)
private
function GetItem(Index: Integer): TMyCollectionItem;
procedure SetItem(Index: Integer; const Value: TMyCollectionItem);
public
function Add : TMyCollectionItem;
property Items[Index: Integer]: TMyCollectionItem read GetItem write SetItem;
end;
Run Code Online (Sandbox Code Playgroud)
和项目:
TMyCollectionItem = class(TCollectionItem)
private
FValue: integer;
protected
function GetDisplayName: string; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
published
property Value : integer read FValue write FValue;
end;
Run Code Online (Sandbox Code Playgroud) 我需要了解制作组件生成和管理子组件背后的基础知识.我最初尝试通过创建一个TCollection,并试图在每个上添加一个名称TCollectionItem.但我知道这并不像我希望的那么容易.
所以现在我将再次从头开始这个项目,这次我想说得对.这些子组件不是可视组件,不应该有任何显示或窗口,只是基于TComponent.保存这些子组件的主要组件也将基于TComponent.所以这里没有什么是视觉的,我不希望在我的表格(设计时间)上为每个子组件添加一个小图标.
我希望能够以类似集合的方式维护和管理这些子组件.重要的是应该创建,命名这些子组件并将其添加到表单源,就像菜单项一样.这是这个想法的重点,如果它们不能被命名,那么整个想法就是kaput.
哦,另一个重要的事情:作为所有子组件的父组件的主要组件需要能够将这些子组件保存到DFM文件中.
例:
而不是访问其中一个子项,如:
MyForm.MyItems[1].DoSomething();
Run Code Online (Sandbox Code Playgroud)
我宁愿喜欢这样做:
MyForm.MyItem2.DoSomething();
Run Code Online (Sandbox Code Playgroud)
所以我不必依赖于知道每个子项的ID.
编辑:
我觉得有必要包含我的原始代码,以便可以看到原始集合的工作原理.这是从整个单元中剥离的服务器端集合和集合项:
// Command Collections
// Goal: Allow entering pre-set commands with unique Name and ID
// Each command has its own event which is triggered when command is received
// TODO: Name each collection item as a named component in owner form
//Determines how commands are displayed in collection editor in design-time
TJDCmdDisplay = (cdName, cdID, cdCaption, cdIDName, cdIDCaption);
TJDScktSvrCmdEvent = …Run Code Online (Sandbox Code Playgroud) delphi delphi-7 tcollection custom-component tcollectionitem