Finding a ribboncontrol

Add-in Express™ Support Service
That's what is more important than anything else

Finding a ribboncontrol
 
Michiel




Posts: 11
Joined: 2021-10-25
Hello,

I use a TadxRibbonTab in my Project on which I have added several controls through the visual designer.
Amongst the controls is one checkbox control and in my code I would like to read out the state of this control.

I can reach the control by using a line of code such as:

adxRibbonTab1.Controls.Items[1].AsRibbonGroup.Controls.Items[0]


However this code is not very robust, if I would replace components to a different location in the tab the index would change and the code would fail. Also the code contains no context about what actual checkbox is refered to, with that I mean a name or some sort.

Is there a way to define a name for the control which I can use to access it instead of using this collecion item?

I see controls get a (probably) unique ID. This could also act as kind of a name.. Using this would at least make the code stable, as the index in the collection can change, but the ID does not. Is there perhaps a function so I can use this ID to get to the controlobject by code?
Posted 03 Feb, 2022 11:27:50 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
Hello Michiel,

I agree with you: that approach is tedious and error-prone. To minimize consequence, you can create a custom variable holding a given Ribbon control and initialize it e.g. in TAddInModule.OnCreate.

The Ribbon API requires that the Id is unique. There's no function returning a Ribbon control if provided with the control's ID.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 04 Feb, 2022 07:44:31 Top
Michiel




Posts: 11
Joined: 2021-10-25
Hello Andrei,

If I understand you right you suggest to define ribbon control class variables ('pointers') in the code and reference them to the TAdxRibbonTab ribbon controls I need in the create function (for example), am I correct?
I would still then have to maintain the collection index in code to make the reference.. But it would be only at one place, so that's propably a little better.
It's unfortunate to hear there's no such thing as a name or getbyID function. I could roll my own by having a function which accepts an ID and just loops through all the collections and comparing the ID.
Perhaps this could also be a feature of the TAdxRibbonTab in future releases?
In any case, thanks for your suggestion and thinking along.

Regards,
Michiel
Posted 04 Feb, 2022 16:06:10 Top
Andrei Smolin


Add-in Express team


Posts: 18218
Joined: 2006-05-11
Hello Michiel,

Thank you for the suggestion!

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Feb, 2022 06:17:24 Top