Home Extend items from the "Buttons" collection in "TcxButtonEdit" in Delphi VCL
Reply: 2

Extend items from the "Buttons" collection in "TcxButtonEdit" in Delphi VCL

AnselmoMS
1#
AnselmoMS Published in 2017-11-10 14:35:46Z

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
2#
AnselmoMS Reply to 2017-11-10 20:47:43Z

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

Aqil
3#
Aqil Reply to 2017-11-10 21:22:22Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.355503 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO