0

I'm trying to extend the collection "Buttons" of type "TcxEditButtons". The purpose is to add an "OnClick" event and a "Shortcut" property on all buttons of a legacy TcxButtonEdit component. I started by overwriting the "Properties" property with the code below:

type
  TMycxDBButtonEditProperties = class(TcxCustomButtonEditProperties)
  private
    FButtons: TMycxEditButtons;
    procedure SetButtons(const Value: TMycxEditButtons);
    function GetButtons: TMycxEditButtons;
    public
      constructor Create(AOwner: TPersistent); override;
      procedure AfterConstruction; override;
    published
      property Buttons: TMycxEditButtons read GetButtons write SetButtons;
  end;

... in my component i do this ...

    type
      TMycxDBButtonEdit = class(TcxCustomButtonEdit)
    FProperties: TMycxDBButtonEditProperties;
  published
    property Properties: TMycxDBButtonEditProperties read FProperties write SetProperties;

The problem is somewhat obvious: the collection is available for editing, but does not reflect the actual ancestral property "Buttons". The question is: How do I make my collection affect the buttons on the component?

I tried to understand and apply what is described in the links below the support of Dev Express, but without success (incompetence)

https://www.devexpress.com/Support/Center/Question/Details/Q136143/creating-custom-tcxbuttonedit

https://www.devexpress.com/Support/Center/Question/Details/Q35461/do-you-have-information-on-creating-own-tcxcustomedit-descendant

https://www.devexpress.com/Support/Center/Question/Details/A483/how-to-hide-default-button-s-in-a-dropdown-editor-or-add-extra-buttons

AnselmoMS
  • 467
  • 3
  • 18
  • I added the links to my queries. On the editor, I'd like to use the same collection editor, where each item is a "TcxEditButton" extended with my new properties. – AnselmoMS Nov 10 '17 at 14:44
  • Does your DevEx version have `class function GetButtonsClass: TcxEditButtonsClass; virtual;` for class `TcxCustomEditProperties` in unit cxEdit? – nil Nov 10 '17 at 14:57
  • yes, my version is 15.2.2 and have this class function – AnselmoMS Nov 10 '17 at 15:02
  • 2
    I think that would be the way then. override it at your `TcxCustomEditProperties` decendant. Implement it as `Result := TMycxEditButtons`. If you don't have already a working Properties decendant, it is similar. `class function GetPropertiesClass: TcxCustomEditPropertiesClass` in the Edit control. – nil Nov 10 '17 at 15:07
  • @nil Thank you so much, your response was enough to find the right way to reach my goal. – AnselmoMS Nov 10 '17 at 20:30

2 Answers2

1

Based on the @nil comment, I got the expected result. Below is the code snippet for those with the same type of need.

  type
      TZcxEditButton = class (TcxEditButton)
    ...
    published
    property Shortcut: TShortCut read FShortcut write SetShortcut;
    property OnClick: TNotifyEvent read FOnClick write SetOnClick;
    end;

    type
      TZcxEditButtons = class(TcxEditButtons)
    public      
    class function GetButtonClass: TcxEditButtonClass; override;
    end;

    type
      TZcxButtonEditProperties = class(TcxButtonEditProperties)
      public
      class function GetButtonsClass: TcxEditButtonsClass; override;
    end;

    type
      TZcxButtonEdit = class(TcxButtonEdit)
        public
        class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
      end;

implementation

    class function TZcxEditButtons.GetButtonClass: TcxEditButtonClass;
    begin
      Result := TZcxEditButton;
    end;

    class function TZcxButtonEditProperties.GetButtonsClass: TcxEditButtonsClass;
    begin
      Result :=  TZcxEditButtons;
    end;

class function TZcxButtonEdit.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TZcxButtonEditProperties;
end;

Note: I accept suggestions for improvement

AnselmoMS
  • 467
  • 3
  • 18
-1

You should extend your new class from main class TcxEditButton . It is not a good way to extend Property Class TcxCustomButtonEditProperties. So create a new class, extended from TcxEditButton and add your new Methods and property to it.

Aqil
  • 360
  • 2
  • 16
  • 1
    What does this add to the other answer? – MartynA Nov 10 '17 at 22:22
  • _"It is not a good way to extend Property Class TcxCustomButtonEditProperties"_ @aqil, why would not I do that if the component manufacturer created the means to get it done? did you read the links on the Dev Express support page that I posted? – AnselmoMS Nov 11 '17 at 10:49
  • Yes you are right, I read that notes. As that note and because of protected property ,we should use this solution. But I wrote this answer for common solutions and delphi component development. – Aqil Nov 11 '17 at 12:36