How do I 'revert to inherited' if control is not clickable? - delphi

Assume the following situation:
FrmBase has a TPanel named PnlClient, align alClient
FrmDescendant inherits from FrmBase
In FrmDescendant I change a PnlClient property
In FrmDescendant I place another control (say another TPanel named PnlDescendant) on PnlClient and align it alClient.PnlDescendant now completely covers PnlClient
I place lots of other components on PnlDescendant, not necessarily aligned, so I'm afraid to change PnlDescendant (e.g. setting align to alNone and resizing) and lose positions
How can I execute 'revert to inherited' for PnlClient?
There's nothing in the main menu, or in the popup menu for the controls in the Structure View...
Currently using Delphi 10.4.1 Sydney

This is easy for a keyboard user like myself:
Click on PnlDescendant in the form editor to make it the focused and selected control.
Press Esc to select its parent, PnlClient.
Press the Menu key on your keyboard to display the context menu of PnlClient. If you have a cheap keyboard without a Menu key, press Shift+F10 instead.
Click on "Revert to Inherited". (Or, much faster: press the menu item's underlined character, probably I.)
(But notice that this will remove PnlDescendant completely. Probably you didn't want that, but that's how it works.)

Related

How to place a component above a TMainMenu?

When I add, for example, a TPanel to a form and align it using alTop and then add a TMainMenu to the same form, the main menu position overrides the panel position such that the Main Menu remains topmost on the form with the panel appearing below it.
Is it possible to override the TMainMenu position so I can add a component like a Panel above it and the Main Menu below it?
Alternatives like TActionManager and/or TToolBar are not suitable because of BiDi compatibility issues.
No, the main menu is a Windows component and its location is fixed. This isn't a Delphi limitation but a restriction on how menus work with windows in Windows.
From MSDN (emphasis mine) :
Only an overlapped or pop-up window can contain a menu bar; a child window cannot contain one. If the window has a title bar, the system positions the menu bar just below it. A menu bar is always visible.
If you want menu-like behaviour in a component which you can freely place anywhere on your form, you would need to either write one yourself or look for third-party alternatives.

How to make an edit control in fmx transparent and hide its border?

How can I make an edit control in fmx transparent and at the same time hide the borders of the control, so it will blend into the control in the back?
What I am trying to do is to make a small Notes program where, when I double-click a tabitem, it shows an edit control to change the text of the tabitem.
Right click the edit control (let's say Edit1) and click 'Edit Custom Style'.
Expand 'edit1style1'.
Click background:TActiveStyleObject.
Clear the SourceLookup property.

TSpTbxDock vs TSpTbxMultiDock

In my current project I have a TTbxDock with toolbars and panels (TTbxDockablePanel). After moving TBX-->SpTBX I can't place a panel (TSpTbxDockablePanel) on a TSpTbxDock. I see a runtime error message saying I can't place a panel on a dock.
Do I need to use a TSpTbxMultiDock instead for panels? Why?
Can I place toolbars on a TSpTbxMultiDock instead of a TSpTBXDock?
i.e. why such code is written:
procedure TSpTBXCustomMultiDock.ValidateInsert(AComponent: TComponent);
begin
inherited;
if not (AComponent is TSpTBXCustomDockablePanel) then
raise EInvalidOperation.CreateFmt('Cannot insert %s into MultiDock', [AComponent.ClassName]);
end;
procedure TSpTBXCustomDockablePanel.ValidateContainer(AComponent: TComponent);
begin
inherited;
if (AComponent is TTBDock) and not (AComponent is TSpTBXCustomMultiDock) then
raise EInvalidOperation.CreateFmt('Cannot insert %s into %s. Place it on a MultiDock instead', [Self.ClassName, AComponent.ClassName]);
end;
Why can't I just use one type of dock?
"I need to use TSpTbxMultiDock instead for panels? Why?"
The short answer is, because the TSpTBXMultiDock component is written to handle and dock only TSpTBXDockablePanels.
The long answer is that the TSpTBXMultiDock component is written to handle and dock only TSpTBXDockablePanels because the docking code relies on specific methods / properties in the controls it is docking. See TSpTBXCustomDockablePanel.SetParent, which looks after this: it accesses the properties and methods TSpTBXCustomMultiDock.
UpdateDockablePanelsDockPos
ClientAreaWidth
ClientAreaHeight
In other words, the docking and layout code needs to know certain information and ask the docked controls to do certain things. The easiest way to do this is to constrain the type of the controls it can dock to descendants of a specific class which declares and implements the required interface (using interface loosely, there is no (class) interface declared, it's just an informal set of methods / properties.)
From scanning the code quickly, I think only the first of these, UpdateDockablePanelsDockPos, is really essential. I may have missed something. But this method gets a list of all docked panels and updates each one's DockPos, which is the one-dimensional position of the dock in the panel. That is, for a horizontal panel it is the left / horizontal start, and for a vertical panel it is the top / vertical start. It also updates the total so the panel knows how big is has to be, or can be if it chooses.
I'm not quite sure I've answered your question. I feel I've given a correct answer but not a helpful answer (the above are technical reasons, not conceptual reasons), which requires insight into what you're doing. My guess is you are asking this because you're struggling with a TBX -> SpTBX migration and you want docking areas which can handle both toolbars and dockable panels. Luckily, both these lead to your second question...
"Can I place toolbars on a TSpTbxMultiDock?"
I'm stepping into remembered territory here and I can't guarantee that this part of the answer is correct, because I converted our app from TBX to SpTBX a long, long time ago.
First of all, no, you cannot place a TSpTBXToolbar on a dockable panel. Nor can you dock a TSpTBXDockablePanel on a TSpTBXDock. A toolbar can dock into a dock, and a dockable panel can dock into a multidock.
The reason for this is guesswork, but I would guess it's because of the different behaviour of the two docked controls and their purpose.
Toolbars:
Are meant to contain SpTBX items (buttons, dropdown, etc, not any normal VCL controls, buttons, etc) and can dynamically change from being toolbars to menus etc, eg as the form is resized and the toolbar shrinks.
Stack: as well as having any amount of space between them (unlike docked panels, which always sit adjacent to each other) toolbars can have space between them; they sit whereever the user put them. They also often sit in several rows, and the one dock expands and contains several rows.
Are designed to shrink: a form can get too small or a user can drag a toolbar over another, and a toolbar will show only the items it can, and either hide the others or show a chevron (a tiny >> button to open a menu containing the other items.)
Dockable panels:
Are meant to hold complex controls, including standard VCL controls - they're meant as a toolbar and docking system-compatible way to build complex docked forms. (We design ours as frames and client-align a frame to the dockable panel.)
Rarely are on several rows. This is up to you as the UI implementer, but many panels docked next to each other could rapidly fill up form space. We keep LimitToOneRow turned on for dockable panels, so they they can only fill up one dimension (ie, on the left and right side of the form, dockable panels can only sit above and below each other, not to the left and right of each other.)
Resizing behaviour is different: they are always adjacent with no gap in between (toolbars can be positioned anywhere) and usually stretch one or more of the panel to fill the whole size of the dock (toolbars don't, unless MenuBar is set (see below)) and in fact toolbars are designed to shrink, not grow, and show a chevron and a drop-down menu. Panels don't have that behaviour.
After that diversion, back to your question. When we were converting our app I remember wondering what would happen if a user wanted to create a layout such that there were toolbars, then a dockable panel, and then toolbars again, in order to get as close as possible to mixing the two types. Doing so would require a dock, then a multidock, and then a dock again, but in practice this actually leads to users being able to create quite complex and confusing layouts. One problem with dockable UIs is that many users find them confusing (honestly, you'd be surprised), and can accidentally move or dock items where they don't want them. (It's good practice to contrain the menu bar to the top, for example - don't allow that one to be moved. It's just confusing.)
Our current design is that each side of our main window has two docks: one normal dock and then next to that that (closer to the center of the form) a multidock. The resulting behaviour is that all toolbars, such as menus and normal toolbars, can only dock next to the edge of the window. Dockable panels are then closer to the inside of the form than that. Keeping pairs of docks and multidocks next to each other on each form edge lets both types of controls be docked at any side of the form, but constrains toolbars to always be on the very edge of the form. This makes UI sense, actually: dockable panels tend to contain more complex things inside them than a toolbar, and it follows that they are more central controls. Of course, if one particular edge of the form has only a dockable panel on it, not a dockable toolbar, then the toolbar dock is invisible (width or height of 0) and so the panel sits next to the edge of the window too.
Written as text, it's hard to explain the previous two paragraphs (how this scheme works, and why this is okay / good.) You need to try it in practice and have a sense for user's behaviour. But basically, I recommend having both types of docks on your form, and keep the TSpTBXMultiDocks aligned 'inside' or 'inner to' the normal toolbar docks. Hopefully this image helps.
Other
You might be interested in the following properties:
DockableTo (toolbar and dockable panel): constrains which sides (top, bottom, left, right) a toolbar or panel can dock. Use this to make some controls only able to be docked in certain specific docks - a main menu to only dock on the top, for example.
DefaultDock (again, both): when users double-click to dock, rather than drag-docking, where does it go?
CurrentDock: I think you've already found this, but set it in the designer to move a toolbar or panel between docks, and read at runtime (or, I suppose, set at runtime if you programatically want to move things to specific docks.)
DockMode: controls whether a toolbar or panel can float (be undocked and be its own window), or not, including whether it can change docks. An example of using this is the main-menu constraint again.
FixedDockSize (panels only): stops the panel being resizable, either by the user or by the docking code referred to above.
MenuBar (toolbars only): gives the toolbar slightly different behaviour, I think that it always takes up the full width of the dock and doesn't allow other toolbars to be docked next to it. It may also change how items render slightly.

How do I add buttons to a FireMonkey toolbar?

With 10 years of experience in development, I could not put new buttons on the Toolbar FireMonkey. Could anyone help me?
There is no component editor menu-item to add buttons or seperators, but you can drag buttons from the toolpallet to the toolbar. Or select the toolbar in the form and press F6. Type the name of the control you want on the toolbar and press enter.
TToolBar is now simply a container. You must drop your own controls onto it.
To add a control to a ToolBar, make sure that your ToolBar is selected on the form, select your child control in the Tool Palette, and then click the location in the ToolBar that you wish your child control to appear.
Another way to do this is to ensure that the ToolBar is selected and double-click the control in the Tool Palette. Whatever control is selected becomes the parent.
Many of the new FireMonkey UI controls are now simply containers, including TStatusBar.
To add a text line to TStatusBar, you must add your own TLabel or other control.
I found that the best way to put an image on a button was to literally drop a TImage onto the button and unset the TImage's HitTest property.
All FireMonkey controls are containers and can have child controls now. It might take a little longer to configure your UI, but you have a lot of flexibility.
Use the TLayout control for dividing up the parent control and aligning your controls. Use the Margin and Padding properties to adjust the spacing.

How to set the glyph for a toolbar button to blank?

I add a toolbar with some standard Delphi components to my application. Unfortunately, the stupid arrow is first glyph (does anyone even know what it is for?)
I would like to destroy it totally, or, at least, set itcs icon to blank, so that it blends in with the toolbar.
How can I do this?
I need some code which can be executed twice without causing an exception. Thanks
TToolButton gets its image from combining its ImageIndex property with the enclosing toolbar's Images property, which refers to a TImageList. To make a toolbar button have no image, assign ImageIndex := -1.
To remove the glyph from a TSpeedButton at design time, select the button, and then select the Glyph property in the Object Inspector. Press Del to clear the property. To do the same at run time, assign Button.Glyph := nil.
If you have a pre-made toolbar, such as TMediaPlayer or TDBNavigator, then you can't customize the buttons. They always show the arrow glyphs that are hard-coded in the control. You can choose to hide or show certain buttons, though. If you placed the control just to get a row of buttons and have no intention of using them to play media or navigate a database, then don't use that control. Just place a TPanel and put standalone buttons on it.

Resources