TOwnedCollection and RTTI editor no insert or delete

I have two classes derived from TOwnedCollection and TCollectionItem used as a Component. They're working ok, I can see items in ObjectInspector window and I can edit (add, delete, change properties) of collection items. What I want to do is blocking adding or removing items in RTTI editor (or from code).  Please, take a look at this code:

TMyCollection =  class (TOwnedCollection)
private
  function Add  :TCollectionItem;
  function Insert(const AIndex : Integer) : TCollectionItem;
protected
  function  GetItem (const AIndex : Integer) : TCollectionItem;
  procedure SetItem (const AIndex : Integer;
                    const AValue : TCollectionItem);

public
  constructor Create (const AOwner : TComponent);
  function FindItemID (const AID    : Integer) : TCollectionItem;
  property Items      [const AIndex : Integer] : TCollectionItem read
GetItem write SetItem;
end;

TTestComponent = class(TComponent)
     private
      FMyCollection: TMyCollection;
    procedure SetMyCollection(const Value: TMyCollection);
     public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
     published
      property MyCollection: TMyCollection read FMyCollection; // here's my problem I think
   end;

It's an example only. The real code is used for many purposes - as components. One of them is creating a list (TOwnedCollection) of audio ports (TCollectionItem). When I create TOwnedCollection I also create as many TCollectionItems as waveOutGetNumDevs returns. I don't want to allow adding or removing new audio ports, just want to allow editing in RTTI editor ports activity, buffer size etc.  How can I do that?

Regards,
Jacek
JacekHAsked:
Who is Participating?
 
diniludConnect With a Mentor Commented:
For achiving this you have to registor a property editor class.

Try this along with your Code.

Pas
=====

unit RegCollectionEditor;

interface

procedure Register;

implementation

uses DesignIntf, MyTestcomponent,ColnEdit;

Type
  TMyCollectionProperty=Class(TCollectionProperty)
     function GetColOptions: TColOptions; override;
  end;

  function TMyCollectionProperty.GetColOptions: TColOptions;
  begin
    Result := [coMove];
  end;


procedure Register;
begin
  RegisterPropertyEditor(TypeInfo(TmyCollection), nil, '', TMyCollectionProperty);
end;


end.

0
 
JacekHAuthor Commented:
More points.... :)
0
 
JacekHAuthor Commented:
Thank you.

Best regards,
Jacek
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.