[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

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
0
JacekH
Asked:
JacekH
  • 2
1 Solution
 
JacekHAuthor Commented:
More points.... :)
0
 
diniludCommented:
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:
Thank you.

Best regards,
Jacek
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now