Xojo2023r3 WebToolbar: adding button

I like the dynamic creation of web toolbar. I have several web pages with their own toolbars. In the Opening event of the Toolbar1 control on WebPage1 I have following code:

AddToolbarButton(Me,“EditReasonButton”,“Edit Reason”,Questionicon)

The WebPage1.AddToolbarButton method adds button to the toolbar.
I would like to avoid duplication of this method in WebPage2 that has another web toolbar control ex: Toolbar2.

I could place AddToolbarButton to the Session object and call it to handle adding buttons to any web toolbar from the Opening event.

Would this be the best way or should I consider different technique (ex. creating custom MyWebToolbar class as a super classs for each toolbar?).

Is App a better place to put common method like that?

Subclass WebToolbar and in the subclass Opening event create your reusable toolbar. You can then add your subclass to pages and the toolbar will be consistent without copying & pasting code.

1 Like