Recent

Author Topic: Problems with TClipboard  (Read 10072 times)

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #15 on: December 24, 2017, 11:54:10 pm »
Thanks Jamie. I will try to follow your suggestions.
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problems with TClipboard
« Reply #16 on: December 26, 2017, 06:46:08 am »
It seems that something  goes wrong with Canvas.CopyRect... See attached images...
there are two things you should pay attention to
1) the BmpDst dimensions look like they are bigger than the bmpsrc dimensions that can create problems.
2) the canvas.copymode might have something to do with the problem.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #17 on: December 26, 2017, 12:21:28 pm »
Thanks Taazz.

The strange thing for me is that with the following code, very similar to the last I posted, where I don't work with the canvas of a TEvsSimpleGraph, but with the canvas of a TForm, SendToClipBoard works properly...

For what concerns Canvas.CopyMode, documentation defines it as 'arbitrary number'... So I thought that it exists only for Delphi compatibility

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3.  
  4. interface
  5.  
  6. uses
  7.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Clipbrd, USimpleGraph;
  8.  
  9. type
  10.  
  11.   { TForm1 }
  12.  
  13.   TForm1 = class(TForm)
  14.     Graph : TEvsSimpleGraph;
  15.     procedure FormPaint(Sender: TObject);
  16.  
  17.   private
  18.     procedure SendToClipBoard(aCanvas : TCanvas; SrcRect : TRect);
  19.  
  20.   public
  21. end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27. {$R *.lfm}
  28.  
  29. procedure TForm1.FormPaint(Sender: TObject);
  30. begin
  31.   Canvas.Rectangle(50,50,110,110);
  32.   SendToClipBoard(Canvas,Rect(49,49,111,111));
  33. end;
  34.  
  35. procedure TForm1.SendToClipBoard(aCanvas : TCanvas; SrcRect : TRect);
  36. var
  37.   BmpSrc,BmpDst : TBitmap;
  38.   DstRect : TRect;
  39. begin
  40.   BmpSrc:=TBitmap.Create;
  41.   BmpDst:=TBitmap.Create;
  42.   DstRect:=Rect(0,0,SrcRect.Width,SrcRect.Height);
  43.   BmpDst.Width:=DstRect.Width;
  44.   BmpDst.Height:=DstRect.Height;
  45.   BmpDst.Canvas.CopyRect(DstRect,aCanvas,SrcRect);
  46.   Clipboard.Assign(BmpDst);
  47.   BmpSrc.Free;
  48.   BmpDst.Free;
  49. end;
  50.  
  51. end.
« Last Edit: December 26, 2017, 01:47:01 pm by simone »
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #18 on: December 26, 2017, 05:17:35 pm »
Perhaps I understood my mistake: calling copyrect on a canvas of a form inside the oncreate handler...
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problems with TClipboard
« Reply #19 on: December 26, 2017, 05:30:12 pm »
Perhaps I understood my mistake: calling copyrect on a canvas of a form inside the oncreate handler...
What form? the code you shown it draw the graph to a bitmap and then it copy from that bmp canvas to a new bmp canvas. Sorry but it should have no difference if it is called on the create event or a button click.

PS: oops I see you are referring to the last code post sorry that code might have different results on creation and after paint yes.
« Last Edit: December 26, 2017, 05:55:44 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #20 on: December 26, 2017, 06:33:54 pm »
yes taazz I'm referring to this code. thanks for patience and excellent support!
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problems with TClipboard
« Reply #21 on: December 26, 2017, 07:47:55 pm »
I've tried a couple of things tonight,
1) since the location is not kept in the final bitmap instead the bitmap is as big as needed to encompass all the controls only, I added an extra control at the end to make sure that the coordinates given are inside the bitmap.
2) I save and loaded the bitmap from a memory stream before copying it to the BmpDst to avoid any and all irregularities that simple graph might produce.
In both cases the results are the same which drives me to believe that the problem is in the lcl and not the bmp created by the library.

I have one last test to run (most likely tomorrow afternoon) to make absolutely sure. Open a 24bit bitmap created from an external application (like mspaint) and use that to copy a portion on the clipboard. If that fails too then the problem is 100% on the lcl not the Simplegraph library, at that point I'll simple post my findings and probably focus on fixing the library letting more experienced developers with the windows api to take a shot at it.

PS:
After the save and load test I'm fairly certain the problem is in the LCL and most notably in the way it manages images internally but just to be sure I'm going to do that extra test removing the simplegraph library completely from the behavior. Oh and I need to run the tests on 1.6.4 or 1.8 too not only on 1.4.4.

There is one last thing you can do assuming that you only wish to copy the rectangle in its original size and no resampling is needed you can use the pixels property to read and set the pixels directly. Its a bit slow but if it works there are other ways to speed it up.
« Last Edit: December 26, 2017, 08:09:57 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #22 on: December 27, 2017, 12:18:46 pm »
Thanks for your very accurate analysis. Unfortunately I do not have such a deep knowledge of LCL. For the moment I found a dirty and a bit slow workaround to copy the selected objects in the system clipboard. I create a temporary invisibile graph, where I copy&paste selected objects of main graph. At this point I call ScrollInView(Point(0,0)) on the temporary graph, in order to avoid the scrolling problem. Finally I call CopyToClipboard, again on the temporary graph. It seems to works...
« Last Edit: December 27, 2017, 01:06:34 pm by simone »
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problems with TClipboard
« Reply #23 on: December 27, 2017, 03:42:39 pm »
Thanks for your very accurate analysis. Unfortunately I do not have such a deep knowledge of LCL. For the moment I found a dirty and a bit slow workaround to copy the selected objects in the system clipboard. I create a temporary invisibile graph, where I copy&paste selected objects of main graph. At this point I call ScrollInView(Point(0,0)) on the temporary graph, in order to avoid the scrolling problem. Finally I call CopyToClipboard, again on the temporary graph. It seems to works...
well to gain some speed you can create the hidden SimpleGraph once at start up make sure that it has no controls paste the copied controls and after copy the bitmap delete the controls again. That will probably gain you some minimal speed but not enough. The main problem on the speed of paste is in the paste routine, specifically the routine to search and replace duplicate IDs. I have a modified version that it disregards the existing IDs and replacing them with a unique number from the current auto numbering pool which is a few times faster. In the next update.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: Problems with TClipboard
« Reply #24 on: December 27, 2017, 05:41:49 pm »
Please consider using a Timage on the form, send all graphics to that control instead..

 Timage contains a bitmap that holds your output, the canvas on the screen can scroll the
image in/out as needed to view it but you'll never have an issue when using the Timage
as the source for your clipboard.

 However, don't expect to drop controls on it and have the controls also appear in your
clipboard display.
The only true wisdom is knowing you know nothing

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #25 on: December 28, 2017, 08:13:14 am »
I rely on the EvsSimpleGraph component because I have to manage the drawing of custom flow chart diagrams in my application. I'm not sure I can use TImage together with the aforementioned component. However, thanks for the help.
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problems with TClipboard
« Reply #26 on: January 04, 2018, 08:04:36 pm »
an Update has been pushed to github and attached in this message.
1) Minor enhancements have been done to the internal ID management to speed up, load and paste from the clipboard processes.
2) isvisible has been changed to use the enhanced EvsXXXXCanvas classes to decide visibility instead of the owner.

Testing so far shows correct results both on copy and drawing, draw speed has not been affected but as it stands now the copy to bitmap can not use any antialised aware canvases (eg GDI+) this will be made available in a later update.
« Last Edit: January 04, 2018, 11:43:03 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #27 on: January 05, 2018, 01:17:29 pm »
Thanks Taazz! Now the copy of selected objects to system clipboard works well.
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 668
Re: Problems with TClipboard
« Reply #28 on: January 05, 2018, 03:55:46 pm »
In your opinion, can your changes compromise backward compatibility? However I integrated the new version of library with my application and all the regression tests has been passed. Moreover I noticed that you have resolved another bug I forget to report, relating to TEvsSimpleGraph.SaveAsBitmap. Before your update, the exported bitmap was cut when the graphic were bigger than visible window.
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problems with TClipboard
« Reply #29 on: January 05, 2018, 04:06:29 pm »
In your opinion, can your changes compromise backward compatibility?
there is no change in the format or the interface  ( components and unit) that will be incompatible with existing versions. If your old files are loaded and shown correctly then there is no problem with the compatibility.
However I integrated the new version of library with my application and all the regression tests has been passed. Moreover I noticed that you have resolved another bug I forget to report, relating to TEvsSimpleGraph.SaveAsBitmap. Before your update, the exported bitmap was cut when the graphic were bigger than visible window.
same bug, different take.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018