Collections Editor + & -

Support forum for our custom runtime inspector controls.

Collections Editor + & -

Postby amarryat » Thu May 29, 2014 8:53 am

Is there a way to hide/disable the ability to add and remove collection items in the collections editor? We have a fixed list of items and don't want the user to be able to change the number of items in the collection.

Also, is there a way to disable the + button when a limit is reached, such as we want to limit the number of traces to 15 for example, so the button should become dark once that limit is reached.

Thanks.
amarryat
 
Posts: 5
Joined:
Thu May 22, 2014 8:35 am

Re: Collections Editor + & -

Postby Inspex » Sat May 31, 2014 8:17 am

Hi,
Yes, it is possible to create a TCollection editor preset that only allows a limited number of items, though it might not be as easy as you had hoped. Basically, what you want to do is create another TIxTCollectionPropertyPreset and have it call the IxTCollectionEditor.ShowCollectionEditor function. This function will show the collection editor and return you a pointer to that form. Then, all you have to do is change the Add and Delete Action to be visible/not visible and/or enable/disable them as you need.

After you create a TIxTCollectionPropertyPreset, make sure it matches the property you want it to edit. Then, you would add the following code:

Code: Select all
uses
  IxTCollectionEditor;

type
  TfrmIxCollectionEditorHack = class(TfrmIxCollectionEditor);

procedure TForm40.AddItem1Update(Sender: TObject);
var
   Ed: TfrmIxCollectionEditor;
begin
  Ed := (Sender as TAction).Owner as TfrmIxCollectionEditor;
  (Sender as TAction).Enabled := (Ed.Collection <> nil) and (Ed.Collection.Count < 4);
end;

procedure TForm40.DeleteSelected1Update(Sender: TObject);
var
   Ed: TfrmIxCollectionEditor;
begin
  Ed := (Sender as TAction).Owner as TfrmIxCollectionEditor;
  (Sender as TAction).Enabled := (TfrmIxCollectionEditorHack(Ed).Objects <> nil) and (Ed.Collection <> nil)
    and (Ed.ListView1.SelCount > 0);
end;

procedure TForm40.IxObjectInspector1Presets20EditButtonClick(Sender: TObject);
var
   Item: TIxItemProperty;
   Ed: TfrmIxCollectionEditor;
begin
     if not (Sender is TIxItemProperty) then Exit;
     Item := TIxItemProperty(Sender);
     if IxObjectInspector1.Component <> nil then
       Ed := ShowCollectionEditor( IxObjectInspector1, Item.GetObjectProperty as TCollection,
                           IxObjectInspector1.Component.Name +
                           IxObjectInspector1.PathDelimiter +
                           Item.FullPathName )
     else
       Ed := ShowCollectionEditor( IxObjectInspector1, Item.GetObjectProperty as TCollection,
                           Item.FullPathName );
     // Set the Add and Delete actions to not visible if you don't want user to
     // see them at all
     //Ed.AddItem1.Visible := False;
     //Ed.DeleteSelected1.Visible := False;
     // Alternatively, you can override the Add and Delete actions to only be
     //  enabled when you want
     Ed.AddItem1.OnUpdate := AddItem1Update;
     Ed.DeleteSelected1.OnUpdate := DeleteSelected1Update;
end;



Regards,
Tom
---------
Tom Grubb - Inspex Support
Inspex@raize.com
Inspex
 
Posts: 5
Joined:
Fri Apr 15, 2011 6:37 am

Re: Collections Editor + & -

Postby amarryat » Tue Jun 10, 2014 3:16 pm

Thanks for the detailed answer!
amarryat
 
Posts: 5
Joined:
Thu May 22, 2014 8:35 am

Re: Collections Editor + & -

Postby Inspex » Tue Jun 10, 2014 5:49 pm

amarryat wrote:Thanks for the detailed answer!

You're quite welcome. :)
Tom
---------
Tom Grubb - Inspex Support
Inspex@raize.com
Inspex
 
Posts: 5
Joined:
Fri Apr 15, 2011 6:37 am

Re: Collections Editor + & -

Postby amarryat » Wed Jun 11, 2014 3:39 pm

This is doing the trick for me, but I have 2 comments/questions.

1). I have disabled the popupmenu in the collection editor by setting ListView1.PopupMenu=nil. If I use the popupmenu and select "Add New", I get an access violation. Maybe I have done something wrong, otherwise this looks like a bug.

2). When you are in a collection editor, how do you make the object inspector 'back out' to the previous level when you close the collection editor? I'm having to deselect my object and then select it again for the object inspector to reset.
amarryat
 
Posts: 5
Joined:
Thu May 22, 2014 8:35 am

Re: Collections Editor + & -

Postby Inspex » Thu Jun 12, 2014 8:32 am

amarryat wrote:This is doing the trick for me, but I have 2 comments/questions.

1). I have disabled the popupmenu in the collection editor by setting ListView1.PopupMenu=nil. If I use the popupmenu and select "Add New", I get an access violation. Maybe I have done something wrong, otherwise this looks like a bug.

I can confirm this is a bug. I have a fix for it. Until there is a point release, you can fix the bug by editing the IxTCollectionEditor.pas:
Code: Select all
procedure TfrmIxCollectionEditor.AddItem(AClass: TCollectionItemClass);
var
   Item: TCollectionItem;
begin
     DeselectObjects;
     if AClass = nil then
       Item := Collection.Add
     else
       // Tag contains ClassName
       Item := AClass.Create(Collection);
     ListView1.Selected := nil;
     RefreshView;
     SelectItem(Item);
end;


amarryat wrote:2). When you are in a collection editor, how do you make the object inspector 'back out' to the previous level when you close the collection editor? I'm having to deselect my object and then select it again for the object inspector to reset.

Yes, that is what you have to do.

Regards,
Tom
---------
Tom Grubb - Inspex Support
Inspex@raize.com
Inspex
 
Posts: 5
Joined:
Fri Apr 15, 2011 6:37 am


Return to Inspex

Who is online

Users browsing this forum: No registered users and 2 guests