How can I create a context menu for a Delphi component? - delphi

I want to create a context menu for Delphi components like TDBGrid, TTreeView or similar. How can I do that?

Place a TPopupMenu onto your form and design your menu with it. Then select the component the popupmenu is meant for (DbGrid, TreeView, ...) and set it's PopupMenu property to the PopupMenu you just designed.
You can have different PopupMenus for different components.

After placing a TPopupmenu control and linking it to the desired control, if you want to change the available items in the popup menu according to the selected cell or node in a treeview use the OnContextPopup event of the control, that gives you a chance to alter the default behaivor of the Popupmenu

Related

Delphi: What is type of window appears after you click a ComboBox

There is a window appear after you click that triangle icon of ComboBox. This I know it's not just a panel like object because for example in the following picture it' out of main form.
What is its type and how can I create something like this?
It is a standard ListBox control that the ComboBox creates internally (its HWND is accessible via the CB_GETCOMBOBOXINFO message). It is implemented as a free-floating window (so it can appear outside the ComboBox's parent window), except when the Style property is set to csSimple, in which case the ListBox resides as a child within the ComboBox's client area instead.

What control should I use to create this UI in Delphi Firemonkey

I am developing an application for mobile (android and ios) by Delphi xe5.
I am willing to create this UI:
I tried TListBox but image on left and right cant be set.
I tried TListView but same problem as TListBox
I tried TGrid with custom column, The problem of texts and images is solved but I can't create headers of each rows (it hasn't something like colspan)
What I need is to create a custom control and repeat it.
What is the best solution?
Any solution or guide line will be appreciated.
Solution
Thanks #Mike Sutton for answer, this is the result
The style here is so different from a standard TListBoxItem style that is probably makes sense to start from scratch, in which case the issues with accessing the default styles become immaterial.
Add a TStyleBook to your form.
Set the StyleBook property of the form to point to it.
Double click the icon to open the editor.
Drag a TLayout to the structure panel and drop it on the only item which will be there.
Set the StyleName property of the TLayout (e.g. ScoreListBoxItemStyle).
Drag/drop other components to build up the layout you want (remember TLayouts for 'hidden' positioning).
Set the StyleName property of any components you want reference from your code.
Subclass TLIstBoxItem to TScoreListBoxItem (if using the StyleName suggested above).
Add properties for your text, images etc.
In the setter methods for each of these, cache the data and call a method such as:
procedure SetFlag1;
var O: TFMXObject;
begin
O := FindStyleResource('flag1'); //StyleName of the item
if O is TImage then
TImage(O).Bitmap.Assign(FFlag1);
end;
Override the ApplyStyle method and call all of your methods that set the data in the style.
Now create your items in code:
Item := TScoreListBoxItem.Create(Self);
ListBox1.AddObject(Item);
Item.Flag1.LoadFromReource ...
...
Here's an idea that I don't have time to test:
Create a descendant of a TListBoxItem and in that add you two images as normal TImages. I'm pretty sure that a TListBoxItem can parent an object. You'll have to place the images on the listbox item where you want them. Then whenever you add an item to the listbox item just pass in your own descendant.
(If this doesn't work someone let me know and I'll delete this.)

How to disable menu, sub-menu in ActionMainMenuBar?

Using: Delphi XE3, VCL Forms application
I have a menu containing a sub-menu in a ActionMainMenuBar. How can I via code:
disable the menu
disable the sub-menu
Create a 'TAction' per menu/submenu that you want to enable disable. Do not assign them to any category.
Create an 'OnExecute' event handler for these actions, so that these can be enabled. You don't have to put any code in the handler, a comment ('//') is enough for the IDE to not to delete the handlers.
Select the 'TActionClient' that represents the menu/submenu from the form designer, just click on the item.
Assign one of the actions to its 'Action' property in the object inspector.
Enable/disable the action associated with the 'TActionClient' that represents the menu/submenu at run time for the menu/submenu to be enabled/disabled accordingly.
By using the 'enabled' property of the menu? or the menu-item that is the starting point of the submenu...
You can actually disable it at runtime (in Delphi 7 anyway) if you know the index of the top-level menu item for the category as follows:
ActionMainMenuBar.ActionControls[2].Enabled := False;
ActionControls[2] would be the category showing as a top-level menu item (after dragging the category onto ActionMainMenuBar from ActionManager.

Delphi: Styled TMainMenu and TToolBar in TCoolBar

I'm attempting to create an application menu and toolbar in Delphi XE3 that looks like the following (from a program I have):
I'm able to replicate a portion of this look by doing the following:
Create a new VCL Forms application
Add a TMainMenu and insert template menus for File/Edit/etc.
Add a TCoolBar to the form
Add a TToolBar to the TCoolBar
Add a TToolButton to the TToolBar for each of File/Edit/etc. and choose the Group property
Delete the Menu property from the form (so no program menu shows)
Assign the MenuItem property for each TToolButton to the corresponding File/Edit/etc.
Add a second TToolBar to the TCoolBar beneath the first one
Here's what it looks like:
It's somewhat similar but is still missing all the style elements to modify the look of the new application menu.
My question is, does anyone know of how to achieve a similar look, perhaps with a third-party component library? It seems likely that the original developer used a third-party VCL library. I'd like the drop shadow in addition to the styled menus and TCoolBar.
I've tried Raize Components, TMS Advanced Toolbars & Menus, and am in the process of trying DevExpress VCL components. None of them seem to provide a solution, but perhaps I'm not familiar enough with them yet to figure it out.
Delphi has come with an ActionBands demo that can show you how to obtain this appearance "out of the box" for your menus using TActionMainMenuBar (and TActionToolBar). Just change the Style menu to XP Style in the demo:
The rest of your steps seem pretty well complete. For the images on the menu items and toolbar buttons, see the use of ImageList components in association with the TActions on the menu and toolbar in the demo.

Is there a way to activate component editor menu for a concealed component in Delphi

I implemented two menu items for my component in Delphi IDE with TComponentEditor descendant. They're both supposed to be used with "right-clicking" a component on the form. But can I do this for component that is currently hidden (concealed) by other components? So I select a component with other tools (for example object inspector) and would like to activate one of my context menu items.
Shift-F10 doesn't work (at least in D5).
Bringing the component to top for this task is not an option.
Right-click the component in the Object TreeView (Shift-Alt-F11).
D7: Menu > View > Object TreeView
XE2: Menu > View > Structure
Or make a property editor with paDialog in the attributes and forward the Edit method to your component editor. Then double clicking that property or clicking the ellipsis will bring up the component editor, just like the Colums property for TDBEdit does.
If you feel like writing a something mimicking Delphi IDE's Object TreeView, I suggests you the following resources:
Populating all controls of a container object using recursion (Blog post). Using TVirtualTreeView like the Delphi IDE is better than the stock TTreeView to my opinion.
Study the commercial TLMDComponentTree
of the LMD IDE-Tools (Excerpt: This powerful control allows to use a Delphi IDE like Object TreeView. Collections, child controls etc. are automatically handled).

Resources