Implement clipboard operations via menu - delphi

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.)

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

Related

Can we use Popupmenu in FMX?

I am developing a mobile app in FMX where i need Popupmenu but it is showing disable in Tool Palette i cant use it but in VCL its enabled in Tool Palette and can use it. I just want to know if Firemonkey supports Popupmenu or my installation is having problems or we have to use other tools instead of Popupmenu in FMX? or what else can I do?
and actually i opened one VCL project and copied popupmenu from there to FMX and wrote code on one button and that code is
procedure TFRM_Party.BTN_Party_OptionClick(Sender: TObject);
begin
PopupMenu1.Popup(10,10);
PopupMenu1.Parent := Self;
end;
this code is not showing any error and also not performing also.
what to do? anybody having idea?
The short answer to your question is "Yes", you ought to be able to use the FMX version of TPopupMenu in a project created from File | New |Multi-Device Application in the IDE. If you can't find the FMX TPopupMenu on the Component Palette, something must be wrong with your Delphi install. I'm not quite sure what you mean when you say that it's "disabled" - components are usually either on the Component Palette or not, I don't recall seeing one looking disabled there.
You don't say in your question which version of Delphi you are using, but if it has FireMonkey at all, AFAIK it definitely ought to have the FMX version of TPopupMenu.
In Delphi 10.2 Seattle, for example, the FMX TPopupMenu appears on the "Standard" tab of the component palette, and is contained in the source unit FMX.Menus along with TMenuBar and TMainMenu, amongst others.
If you go to Component | Install packages in the IDE, the pop-up should show Embarcadero FMX Standard Components in the list, which is the file dclfmxstd250.bpl in the bin folder of your Delphi install. If that package isn't listed, that explains why you can't find the FMX TPopupMenu, but if that's the case for you, your Delphi ought to be lacking a lot more FMC components besides TPopupMenu. However, it should be easily solved by installing the .bpl file (or equivalent in your Delphi version). If the package is there, clicking the Components button to the bottom right of the pop-up should bring up the entire list of FXM standard components (which in my case does include TPopupMenu).
If your Delphi does include the Embarcadero FMX Standard Components but is still lacking TPopupMenu, you might try creating a new Package, adding FMX.Menus.pas to it and compiling and installing it in the IDE.
BTW, although it is possible to set up a combined FMX + VCL project (Google for how), just because you might be able to put a VCL TPopupMenu on an FMX Form doesn't mean that it's going to work.
Components are Grayed if you can't use its on current OS(your current choice in top combobox)

How to simulate touch with left mousebutton

I'm developing a Firemonkey Application wich should run on Windows with touchscreen.
Because I have no touchscreen for my development system, I can't test the behavior of some controls. For example the panning in a TListbox doesn't work with the mouse-button. It only works if ssTouch in KeyState is set.
Is there a way to simulate the touch via the mouse?
Regards,
Michael
Well, aside from the obvious answer (save up and get that touchscreen!), there are some solutions, but they might be a bit involved.
If I wanted to do this on PC, I would start by making a copy of the Firemonkey source code and including it in my project.
After checking to see that your 'local' copy of Firemonkey is compiling properly, you will have to edit this file: "FMX.Platform.Win.pas". Open this file and then search for "ssTouch".
Inside of the WM_LBUTTONDOWN handler, there must be some logic which determines whether "ssTouch" is part of the KeyState or not. Add it in yourself, and then the left button should be evaluated as a touch input.

How do I do Drag and Dock like the Delphi IDE with pins and tabs?

I would like to make Drag and Dock work as well in my applications as it does in the Delphi IDE (i.e. being able to drag around the Object Inspector / Structure View and Dock them at suitable sites). I've had pretty good success with docking forms into a PageControl, but was wondering if anyone knows how to get it to work with the the little close buttons and pins and so on.
I'd also be interested to know what components the Delphi IDE uses to achieve this.
The reason for my question is I want to make much more advanced videos on how to do this, the two that I have done previously are here and here.
You can use JVCL JvDocking components to drag and dock, in almost any version of Delphi. It's free and open source. The style with pins and close buttons is available using a docking style called the VID (visual interdev) style, that comes with JvDocking.
There are already a bunch of commercial alternatives also, and there is some support built into Delphi, which I find insufficient for my needs. While the Delphi IDE has its own internal docking library, tab support is very limited, slow, and in my subjective opinion, broken.
However, even on ancient delphi versions, Delphi 7 and up, JvDocking, provides all the functionality that the VCL's docking provides, plus more, so there's no problem ignoring the built in VCL functionality, which is to docking as TStringGrid is to real Grids.
Steps with JvDocking:
Drop dock server and dock style object on main (host form) and connect them.
Drop dock client component on the client (form to be docked) and connect it to the dockstyle.
Configure properties of dock server.
Run app. Have it create a form. Now drag the client form to an area that is made dockable by the dock server. Watch it dock nicely.
For docking in code demos see the JvDocking demos in the JVCL Examples folder.
Update
Or you can use what is built into the Delphi VCL since XE and XE2. XE and XE2 include a docking demo project named dockex.dpr.
On Win7/Vista the demo is located at:
C:\Users\Public\Documents\RAD Studio\9.0\Samples\Delphi\VCL\Docking
Look here for the demo on Win XP:
C:\Documents and Settings\All Users\Documents\RAD Studio\9.0\Samples\Delphi\VCL\Docking
You should also check out the documentation for TDockTabSet in the VCL, and the EDN article linked in the comments, which has source code you can download here. In my humble opinion, the Jedi JvDocking stuff is more professional and slick than the Docking Demo that ships with Delphi, but the built in stuff has the advantage of working without installing anything additional. I just tried the DockTabSet demo and the built in docking demos, and they are slow, and the painting is ugly and flickers. JvDocking looks professional. It's your call.

WM_Copy, wm_gettext and wm_keydown fail?

The problem: I need to obtain the selected text from a window in a Windows application (not my program). I am doing my work in Delphi XE and the software I am attempting to access is a kluge built over the past 15 years with C, C++, VB and who knows what else. I do not have the source code. The edit box (an RTF memo) I am attempting to read is of the class "Ter32Class". When I use wm_copy, nothing goes to the clipboard. when I use wm_gettext, nothing. When I use wm_keydown commands (to simulate Ctrl-Ins or Ctrl-C) nothing happens. Note that I can get all of these alternatives to work in wordpad, notepad, and FireFox but not this application (or OpenOffice, incidentally, but that's not the issue). The only way I have been able to programmatically obtain text from this box is to use autohotkey with the simple "send ^c" command. While it works, it is inelegant. HELP?!?
More information: Window hierarchy: Ter32Class is a child of OI_Mdi which is a child of MDIClient, which is a child of OI_Window . I am drilling down to obtain the appropriate handle as it will respond to a paste command.
I am using Delphi XE but I'd love any solution in C++ or VB if no Delphi XE gurus have the answer.
From Quick Macros Forum
One of the windows I need to talk to is of class Ter32Class which
apparently is a TE Edit Control, an editor that doesn't inherit from
the standard RichText Control
and
The published method of talking to this control is via it's DLL
so unless something has changed (post is 2006), it appears you'll need to use it's dll to get the text.
From Sub Systems (TE Edit control website)
Application Interface functions
GetTerBuffer: Retrieve Window Text
HANDLE GetTerBuffer(hWnd, size)

How do I add recent items to my program's jump list on the Windows 7 taskbar?

I'm using Delphi XE and would like to add "recent items" in the Windows 7 taskbar jump list for my application, like when right-clicking on Microsoft Word brings up recently opened documents.
I've found information on how to set the progress but nothing on jump-list items. Any help would be greatly appreciated.
This will happen automatically if, for instance, you only use the standard Windows file dialogs. At least my text editor, Rejbrand Text Editor, has got such a MRU list by Windows. It lists all files I have recently edited using Rejbrand Text Editor, even though I have not written any code at all for it.
I think that Windows observes the files you
open and save in your application by means of standard Windows file dialogs
open in your application by starting yourapp.exe <file name>, for instance by double-clicking a file that opens in your application
and automatically display these in the list.
If you want to control the task bar button and menu programmatically, you can use the Windows API. Delphi-specific examples are found in this blog post.
In my opinion the best way to do this is to make the following simple API call:
SHAddToRecentDocs(SHARD_PATH, PChar(FileName));
This not only deals with Windows 7 jump lists but also adds your file into the system's list of recently used documents which has an effect on early versions of Windows too.
Call the function whenever you open or save a file.
For your convenience, a link to the documentation of SHAddToRecentDocs().
Here are some resources that I have found useful when making my programs vista ready
http://code.google.com/p/theunknownones/wiki/TaskbarListComponents
http://www.installationexcellence.com/articles/VistaWithDelphi/Index.html
http://www.theabsolute.net/sware/delphivista.html

Resources