ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder


ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PasteFromClipboard() doesn't work as I would expect

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List


Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

Check here to subscribe to this topic.

T O P I C    R E V I E W
Homer Posted - Dec 16 2021 : 17:47:17
If I open Windows File Explorer and copy a valid image file by right clicking the name and selecting "Copy", PasteFromClipboard always returns False. However, in Paint, if I "select all" and copy an image file, it will save as long as I add an appropriate file extension. I've included code snippets, but if you'd like to see the entire procedure if you wish.

I haven't found a demo that shows code for pasting so if someone can please suggest a course of action it would be very much appreciated.

Before I execute the code below, I make sure the file extension matches the ones allowed in my code. I also enable the "paste" menu, and therefore Ctrl-V, with:

mnuPaste1.Enabled := ImageEnView1.Proc.CanPasteFromClipboard();

This is just a code segment of what I'm having trouble with:

if ImageEnView1.Proc.PasteFromClipboard() then
    if (Extn = '.JPG') or (Extn = '.JPEG') then
      ImageEnView1.IO.SaveToFileJpeg(gsDocManPath + NewFileName);
    if (Extn = '.PNG') then
      ImageEnView1.IO.SaveToFilePNG(gsDocManPath + NewFileName);
    if (Extn = '.BMP') then
      ImageEnView1.IO.SaveToFileBMP(gsDocManPath + NewFileName);
    if (Extn = '.TIF') or (Extn = '.TIFF')then
      ImageEnView1.IO.SaveToFileTIFF(gsDocManPath + NewFileName);
    if (Extn = '.PDF') then
      ImageEnView1.IO.SaveToFilePDF(gsDocManPath + NewFileName);

    {save filename and path in the database.}

6   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Dec 18 2021 : 19:38:19

Nice work finding a good solution to this.

Xequte Software
Homer Posted - Dec 18 2021 : 16:56:24
Sometimes I have to overcome my own stupidity. I was making this much harder than it needed to be. As you suggested, I used the clipboard object to find the fully resolved file name. Then simply copied it into my "document" folder, changing the name in the process. I have a function that creates unique names with some human understandable info in the name. Then it was a simple matter to display the "new" file using ImageEn. Sometimes my light bulb is very dim. Nigel, thanks for pointing me in the correct direction.

If it were only graphic files, it could have been done in a half-dozen lines of code. Mine was a little more complicated because I had to accept Word and other kinds of documents. Even so, It was much easier than I was trying to make it. Thanks again.
xequte Posted - Dec 17 2021 : 04:27:54

It wouldn't surprise me if some applications do a similar thing to what I suggested above (using the filename to load the content).

There are many examples on the web of iterating the content of the clipboard if you want to see what formats are there, e.g.

Xequte Software
Homer Posted - Dec 17 2021 : 03:15:17
I've had a chance to experiment a bit. I copied a .BMP file from Windows explorer and pasted it into Open Office Writer. The picture appeared, not the file name. The same was true for a .JPG, .TIF, and .PNG. I'm sure I'm missing something from your earlier reply, but I would like my app to behave the was pasting does in Open Office Writer does (and other word processors I've used). I'm sure that's the way my users would want to paste documents they've saved to their HD.
Homer Posted - Dec 17 2021 : 02:42:33
Thanks, Nigel. That looks like a very handy function. Since my app is for document management, the end user could try to paste a Word document, or a copy of an incoming email in addition to the image files ImageEn handles. I'll do some testing. Thank you very much for the tip.
xequte Posted - Dec 17 2021 : 01:48:07

If you copy from Windows Explorer, a filename is added to the clipboard. This can only be pasted as a file to TImageEnFolderMView:

If you copy from MS Paint, a bitmap is added to the clipboard, which can be pasted to TImageEnView, using ImageEnView1.Proc.PasteFromClipboard();

It is not possible to paste a filename directly into a paint program or ImageEnView, but you could easily right a method to do this:

1. Use PasteFilesFromClipboard to get the list of files on the clipboard:

2. If there's an image file in the list, load it into your TImageEnView.

Xequte Software