I'm trying to create and register a custom editor for TCollection
in Delphi XE5. I tried several things, including inheriting the TCollectionProperty
class. I figured it's enough to override the GetColOptions
function as follows:
function TMycollectionEditor.GetColOptions: TColOptions;
begin
Result: = [];
end;
But nothing happened, it is still possible to add, remove and move items. so by searching more I found the code of the Edit
function and wrote the following:
procedure TMycollectionEditor.Edit;
var
ACollection: TCollection;
APersistent: TPersistent;
begin
APersistent: = GetComponent (0);
while (APersistent <> nil) and not (APersistent is TComponent)
APersistent: = GetPersistentOwner (APersistent);
ACollection: = TCollection (TMy component (APersistent) .MyCollection);
ShowCollectionEditorClass (Designer, GetEditorClass, TComponent (APersistent), ACollection, GetName, GetColOptions);
end;
This also did not change anything in the native editor's workings.
What am I doing wrong? Is this a good practice to do what I'm trying to do? Note: my goal is not the same as this post
Update
I made a temporary change to the method that works (except via context menu or double click [using the ExecuteVerb
method of the inherited property of TCollection])
procedure TMycollectionEditor.Edit;
var
ACollection: TCollection;
APersistent: TPersistent;
begin
APersistent: = GetComponent (0);
while (APersistent <> nil) and not (APersistent is TComponent)
APersistent: = GetPersistentOwner (APersistent);
ACollection: = TCollection (TMy component (APersistent) .MyCollection);
// [update bellow]
with ShowCollectionEditorClass (Designer, GetEditorClass, TComponent (APersistent), ACollection, GetName, GetColOptions) do
begin
AddCmd.Enabled := False;
ListView1.DragMode := dmManual;
ToolBar1.Visible := False;
ToolBar2.Visible := False;
end;
end;