Attila Kovacs 631 Posted January 14, 2020 (edited) Hi all, Is there any existing unit/module whatever for handling In-App clipboard functionality? App should not leak data over clipboard, but I would like to keep the feature inside the app. It's shouldn't be too hard, I'm just curious if there is already any solution. Handling text is sufficient. (VCL/Windows) Edited January 14, 2020 by Attila Kovacs Share this post Link to post
Lars Fosdal 1793 Posted January 14, 2020 I haven't seen one, but I haven't really been looking for one. I guess you have these links already... https://docs.microsoft.com/en-gb/windows/win32/dataxchg/clipboard https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-setclipboardviewer 1 Share this post Link to post
Fr0sT.Brutal 900 Posted January 14, 2020 It's unclear what do you mean. From description, following should do what you want (half-pseudocode) var Clip: string = ''; procedure TForm1.ControlOnKeyDown(Sender, Key, Shift); begin if Shift=[ssCtrl] then if Key = VK_C then Clip := Sender.SelectedText else if Key = VK_V then Sender.SelectedText := Clip; end; Share this post Link to post
Attila Kovacs 631 Posted January 14, 2020 @Fr0sT.Brutal Not quite. I think my description is also crystal clear. 😉 Share this post Link to post
Anders Melander 1815 Posted January 14, 2020 52 minutes ago, Attila Kovacs said: I think my description is also crystal clear. Not really. Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted January 14, 2020 2 hours ago, Attila Kovacs said: Hi all, Is there any existing unit/module whatever for handling In-App clipboard functionality? App should not leak data over clipboard, but I would like to keep the feature inside the app. It's shouldn't be too hard, I'm just curious if there is already any solution. Handling text is sufficient. (VCL/Windows) @Attila Kovacs you might have to end up writing your own app specific clipboard because the Windows clipboard content is accessible to all running programs. Share this post Link to post
Attila Kovacs 631 Posted January 14, 2020 7 minutes ago, Ugochukwu Mmaduekwe said: you might have to end up writing your own app specific clipboard Thanks @Ugochukwu Mmaduekwe, no problem, I just wanted to inform if there is already something for that. I'll check hooking up some windows messages. 1 Share this post Link to post
Lars Fosdal 1793 Posted January 14, 2020 A bit of Googling dug up http://delphidabbler.com/articles?article=9 with src https://bitbucket.org/delphidabbler/article-9-demo/src/master/ which demos the basics - but you'd still need to do the checks to figure out what is relevant to your own app. 1 Share this post Link to post
Attila Kovacs 631 Posted January 14, 2020 Hm, thanks Lars, this will be a good start. Hope I can isolate, not just watch. Lets see! 1 Share this post Link to post
Guest Posted January 14, 2020 @Anders Melander would not https://github.com/DelphiPraxis/The-Drag-and-Drop-Component-Suite-for-Delphi be able to provide some functionality for similar tasks? Share this post Link to post
Anders Melander 1815 Posted January 15, 2020 16 hours ago, Dany Marmur said: would not https://github.com/DelphiPraxis/The-Drag-and-Drop-Component-Suite-for-Delphi be able to provide some functionality for similar tasks? It's hard to tell from the "crystal clear" requirements but I don't think so. I'm guessing that since the OP is asking for clipboard functionality, and have rejected just copying data to and from a string, that he wants the copy/paste features of the standard Windows common controls used in the application to use his own internal clipboard. That isn't possible. It would be easy to use the clipboard with a custom data format, that is only understood by his application, but the Windows common controls are hardwired to use the standard CF_TEXT data format which is understood by everyone (thus the data can be considered "leaked"). Share this post Link to post
Fr0sT.Brutal 900 Posted January 15, 2020 My crystal ball is too tired to guess what OP wants 🙂 1 Share this post Link to post
Attila Kovacs 631 Posted January 15, 2020 so why do you comment on something you don't understand?:) Especially with ctrl-c/ctrl-v. Is that all how clipboard works in your opinion?:) Share this post Link to post
Anders Melander 1815 Posted January 15, 2020 2 hours ago, Attila Kovacs said: Especially with ctrl-c/ctrl-v. Is that all how clipboard works in your opinion?:) I don't think anyone has a clue what you are talking about. 1 Share this post Link to post
Sherlock 663 Posted January 15, 2020 Fellas, please. If Attila thinks he gave enough information, you have two options: Either write an answer based on that, or don't write at all. This should please not escalate. 1 1 Share this post Link to post
Guest Posted January 15, 2020 5 hours ago, Anders Melander said: (thus the data can be considered "leaked") Ah, yes. Did not read the OP, thread properly. Of course. [Stopping here, thanks Sherlock]. Share this post Link to post
Attila Kovacs 631 Posted January 16, 2020 Ok, here is my prototype. - The goal was to keep application data safe from the clipboard. - It tries only CF_UNICODETEXT to keep safe, every other formats are free to come and go. (for now?) - RichEdit does not pass the necessary events, so it needs further client code to protect - no extended testing yet, but I can assure that this behavior will drive the user crazy 😉 - no performance penalty tests - no clue what Antivirus programs says for modifying the import table It does capture clipboard events and keeps copied unicode text in a variable instead of the clipboard. On paste command, it pastes from this variable. (as far my basic paste algo works) On OS Clipboard change, if it's CF_UNICODETEXT, overwrites the In-App clipboard variable to be able to paste into the app from the outside. I have no clue yet if there are any flaws, but it was lot of fun to make it. InAppClipBrd.pas Share this post Link to post
Rollo62 539 Posted January 16, 2020 Not sure what exactly you are looking for, but wouldn't it be an option to register a custom, "secret" clipboard format, maybe with encrypted data ? https://blog.dummzeuch.de/2018/12/18/register-an-use-a-custom-clipboard-format-in-delphi/ Share this post Link to post
Anders Melander 1815 Posted January 16, 2020 2 hours ago, Rollo62 said: wouldn't it be an option to register a custom, "secret" clipboard format I've already suggested that: On 1/15/2020 at 10:11 AM, Anders Melander said: It would be easy to use the clipboard with a custom data format, that is only understood by his application The Windows common controls would not be able to support that format so you'd lose the standard support for copy/paste in all edit controls. There are ways to deal with this but they are not that simple. Share this post Link to post
Attila Kovacs 631 Posted January 16, 2020 You can't just register a clipboard format and expect that every control starting using it. That's not how windows clipboard works. My implementation was attached 11 hours ago, need further testing. It looks good so far. By the way, with the very same unit it would be possible to encrypt the clipboard data too. But I see no use for that, just saying. Share this post Link to post
David Heffernan 2353 Posted January 17, 2020 If lots of people tell you that they don't fully understand your question, I respectfully suggest that you clarify what you are asking. It's easy for us all to write things that we think are clear but find that others don't fully understand. My guess is that you want to stop your program putting anything onto the Windows clipboard. Exactly how to do that depends very heavily on what controls your program uses. 1 1 Share this post Link to post