Hi,
Prelim
First up, I am an old programmer. Second, I cannot use 3 words instead of 30

. My hey day was 80s and 90s, so forms are still a mystery to me. I still prefer to program in DOS when possible, but at times forms are indispensable.
The project is in Windows 10.
Currently adding a tab system to my project using TButtons (I found TTabControl very unsound and did some very odd things, like shifting a hard coded Left to a minus value and starting the tabs way off the screen). Have got the button system basically working, including a right click menu.
But ran into the classic Autosize problem. Because the captions can vary, need Autosize True, but this returns the wrong Width value. If I turn Autosize off, then it reduces the size of the button if the caption was longer than standard button size.
So the core problem is how to calculate the length of a button when Autosize is True. What I've got which is not ideal but works is using a hidden label and using that to calc the size of the text via canvas. Then just guessed the border spacing.
Main
What I had hoped for was a more precise way to either get the actual width of the button, ideal, or get an accurate value of the border spacing. Clearly it seems I have not understood the border values, as they nearly all came back as 0.
This is a snippet from the add tab code, with the core of the working system. The following is inside a With block. If it makes any difference it uses a child to TButton (a little trick from Remy in a forum long ago as to how to know which button was pressed in a set of created).
// attempts to get width direct
//w := Width;
//r := ClientRect; // local var TRect
//w := r.Width;
//w := ClientWidth;
// this works, but does not look good or feel sound
hidden_Label.Font := Font; // need to set the same font to get the accurate size
w := hidden_Label.Canvas.TextWidth( Caption ); // just the text
Inc( w, 20 ); // guess work, good value
// attempts to find the accurate border spacing or other value I could use
//s := BorderWidth;
//s := BorderSpacing.Left;
//s := BorderSpacing.AroundLeft;
//s := BorderSpacing.ControlLeft; // returned values, but no use, but did lead to Right
//s := BorderSpacing.ControlRight; // returned values, but they were wrong, assume fixed width again
//s := BorderSpacing.Around;
//s := BorderSpacing.InnerBorder;
//ShowMessage( 'BorderWidth = ' + s.ToString );
Inc( working_left, w ); // working_left is a Word var used to know where to start the next button
As I mentioned, I have a working system, so not critical if I don't get an improved answer, but it would be helpful to know first how other people calculate variable button width, it must be fairly common, and secondly whether I set up something wrong which caused nearly all the values to come back 0.
Thanks for any info offered.
Phil