2

I'm developing my first commercial Firemonkey application (also my first commercial application in any language). I have used native FMX controls and also one control from TMSSoftware (TTMSFMXGrid). The keyboard clipboard operations -- Ctrl+X, Ctrl+C, Ctrl+V -- work "out of the box". But I would like my application to provide menu items with the same functionality as the keyboard shortcuts.

I have set my program up so that there is a TMenuBar visible when compiling for Windows. When compiling for OS X, the TMenuBar is invisible but a TMainMenu comes up instead. For simplicity, we could just discuss the scenario of compiling for Windows when the TMenuBar is visible.

It's easy to program the TMenuItems of TMenuBar to perform the cut, copy and paste operations. That is not the issue. I have been unable to figure out how to disable the cut and copy menu items when nothing (or nothing relevant) is selected and how to disable the paste when there is nothing (or nothing relevant) on the clipboard.

How can I do that?

(I am using Berlin 10.1 Update 2.)

Duns
  • 418
  • 2
  • 15
  • 3
    I would use a `TActionList` for that, where each menu item is assigned a `TAction` object from the list (and you can have the `TMenuBar` items and `TMainMenu` items share the same actions). The `TAction.OnUpdate` event can be used to assign an action's `Visible` or `Enabled` property as needed (thus updating its associated menu item(s) accordingly)... – Remy Lebeau Mar 28 '17 at 22:11
  • 3
    ... For instance, the Copy and Cut actions could enable/disable themselves based on the target control's current selection (or lack of one), and the Paste action could enable/disable itself based on the clipboard's current content (see FMX's [`IFMXClipboardService`](http://docwiki.embarcadero.com/Libraries/en/FMX.Platform.IFMXClipboardService) and [`IFMXExtendedClipboardService`](http://docwiki.embarcadero.com/Libraries/en/FMX.Clipboard.IFMXExtendedClipboardService) platform services). – Remy Lebeau Mar 28 '17 at 22:16
  • @RemyLebeau With the help of your comments, I was able to program my cut, copy and paste menu items. Drawing my attention to the TAction.OnUpdate event was very helpful as I had not previously appreciated the purpose of that event. If you post your comments as an answer, I will accept it. – Duns Mar 29 '17 at 21:18

1 Answers1

0

You can read about Copy/Cut/Paste with FMX from Embarcadero here:
Multi-Device Apps and Clipboard Support

And because your question is about Windows now you should understand internals of Windows Clipboard. Good start is article from Zarko Gajic:
Basic Clipboard Operations (Cut/Copy/Paste)

And also about listening Clipboard to reseive notifications about clipboard content changing:
Listening to the Clipboard: Clipboard Delphi Spy with Custom Clipboard Formats

Another good article about clipboard in OS X and Windows with FMX:
Copying and pasting the contents of a FireMonkey TBitmap

Alex Egorov
  • 907
  • 7
  • 26
  • 1
    And while you are at it, see [this discussion](https://forums.embarcadero.com/thread.jspa?threadID=109443) on the Embarcadero forums for an example of using FMX to listen to clipboard changes on Windows. – Remy Lebeau Mar 29 '17 at 21:35