Recent

Author Topic: CopyToClipboard  (Read 7731 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 444
CopyToClipboard
« on: September 03, 2021, 01:34:47 pm »
I am trying to use CopyToClipboard and PasteFromClipboard because they are the only way that I have found where text and formatting attributes can be transferred together. In particular I am wanting my Search and Replace functions to replace with both text and formatting.

What I have encountered is that CopyToClipboard can be hit, miss, and otherwise late on delivery. So I hear a horn warning, but the code keeps running without a proper execution.

Oddly, if I activate a showmessage('message'), just after CopyToClipboard, it performs correctly every time. But doing the same with sleep(1000), or at any value, it does not execute properly. So 'showmessage' is doing something different from 'sleep'.

Moreover, the hit and miss behavior is that the identical code in another 'begin ... end' section will have no problem at all. Yet if I use CopyToClipboard and PasteFromClipboard  in a 'replace every occurrence' routine it will miss all but the first instance.

However, the same routines with using PageMemo.SelText:=ReplaceBox.Lines.Text, instead of the clipboard functions is always faithful ... but I lose all of the formatting. Wherewith I have to do a CopyToClipboard as an independent function; then do a search; then activate an independent PasteFromClipboard again; in order to retain the formatting. Oddly, CopyToClipboard and PasteFromClipboard will always perform properly with that method.

So what's up with CopyToClipboard?

Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: CopyToClipboard
« Reply #1 on: September 04, 2021, 05:24:15 am »
is it Windows? or Gtk?
---
I've just committed CopyRichText() function under RichMemoUtils.
You might want to try to use, instead of clipboard operations.

It should copy the text formatting, BUT it will not copy paragraph formatting (and this is something yet to be done)
« Last Edit: September 04, 2021, 07:48:20 am by skalogryz »

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #2 on: September 04, 2021, 10:38:40 am »
Thank you much! I will try to find it.

I am using Windows 10.
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #3 on: September 04, 2021, 12:33:27 pm »
Code: Pascal  [Select][+][-]
  1. SearchBox.clear;  // RTF container
  2. CopySum:= CopyRichText(PageMemo, // RTF container
  3.                                          PageMemo.SelStart,
  4.                                          PageMemo.SelLength,
  5.                                          SearchBox, // RTF container
  6.                                          SearchBox.SelStart,
  7.                                          SearchBox.SelLength,
  8.                                          []);
  9.  

The above is my implementation. It worked perfectly. Thank you much!!

I have a couple of questions:
How might I employ CopySum?
What options can I add to []?
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: CopyToClipboard
« Reply #4 on: September 08, 2021, 01:40:45 am »
How might I employ CopySum?
what is CopySum?

What options can I add to []?
There's only one option available currently "coCopyBuf".
It forces the copy of the formatted text to be done via an intermediate buffer.

It is always used (even if not specified), if the source and destination of the copy is the same richmemo. Can be specified when the text is copied over from different richmemos.
« Last Edit: September 08, 2021, 02:55:06 am by skalogryz »

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #5 on: September 12, 2021, 01:48:47 pm »
CopyRichText returns a lonint, so I assume that it is the length (sum) of what is copied. Since you ask the question, I now assume that it is something different. What is it, and how do I use it?
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: CopyToClipboard
« Reply #6 on: September 13, 2021, 05:29:36 pm »
CopyRichText() returns the number of characters copied over.
Usually it is expected to be equal to the number specified by SrcLen.
However, SrcLen can be set to -1 (meaning default whatever number of text is available). In this case the function returns the actual number of characters copied.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #7 on: September 14, 2021, 07:23:52 pm »
I was testing what attributes can be copied. I found that the text comes through but the colors are hit and miss. I also found that superscript and subscript are copied as text, but not with the attributes.

Then it all crashed. RichMemo reverted to an older version without the RichMemoUtils. I also cannot reinstall the new RichMemo. It has problems with the QT files.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: CopyToClipboard
« Reply #8 on: September 14, 2021, 07:45:39 pm »
I was testing what attributes can be copied. I found that the text comes through but the colors are hit and miss. I also found that superscript and subscript are copied as text, but not with the attributes.
that is interesting. I presume you're trying richmemo with Qt5?

It has problems with the QT files.
what problem?

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #9 on: September 14, 2021, 08:12:55 pm »
No, I am not trying or using it. However, I reinstalled Lazarus, then I tried to reinstall RichMemo. It took several tries, but then I succeeded. Installing packages is not an intuitive process, and nobody (by what I have not found) has posted the rules.

Nevertheless, I am operating again. What stands is that "Size8, Size16, Size12, Strike, Italic, Bold, Underscore, and ColorRed" are being copied. Unfortunately, my RTF search box is also highlighting the import, and that is automatically turning all colors to the first color ... black. But nothing is highlighted (selected) with my RTF replace box, so it is keeping the color.

But superscript and subscript is being copied without the attributes ... and causing a crash. With this rebuild I am not even attempting to test them.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: CopyToClipboard
« Reply #10 on: September 14, 2021, 08:30:15 pm »
are you using Win32 or Qt widgetset?

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #11 on: September 15, 2021, 11:52:06 am »
I am using Win32. The QT got activated because RichMemo was corrupted by the crash.
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #12 on: September 15, 2021, 12:21:26 pm »
I have updated my account signature.

I am attempting to RichCopy the following ...

Size8 Size16 Size12 Strike Italic Bold
Underscore ColorRed Superscript Subscript

... where each word describes its attribute.

If I copy Size8 through ColorRed it works perfectly.
If I copy Size8 through Superscript it works until it hits Superscript ... which has no attribute.
If I swap Superscript and Subscript it does the same on Subscript ... no attribute.
If I include both Superscript and Subscript it hangs, and I have to hit the STOP button to recover.

I may have hit the Windows TaskManager and EndTask for Laz when it had crashed.
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #13 on: September 15, 2021, 05:20:44 pm »
I am finding that when a plain-word is selected, and sent by CopyRichText to the Search box, it frequently converts it to italics. The following is my code to do so ...

Code: Pascal  [Select][+][-]
  1. PagePassive:= true;
  2.           PageMemoOn:= false;
  3.           SearchBoxOn:= true;
  4.           ReplaceBoxOn:= false;
  5.           FindActive:= false;
  6.           SearchPanel.Visible:= true;
  7.  
  8.           SearchBox.clear;
  9.           SearchBox.SelStart:= 1;
  10.           SearchBox.SelLength:= 0;
  11.  
  12.           ReplaceBox.clear;
  13.           ReplaceBox.SelStart:= 1;
  14.           ReplaceBox.SelLength:= 0;
  15.  
  16.           SentLength:= CopyRichText(PageMemo,        // substitute for CopyToClipboard & PasteFromClipboard
  17.                                     PageMemo.SelStart,
  18.                                     PageMemo.SelLength,
  19.                                     SearchBox,
  20.                                     SearchBox.SelStart,
  21.                                     SearchBox.SelLength,
  22.                                     []);  // option: coCopyBuf
  23.  
  24.           //The only option available is "coCopyBuf".
  25.           //It forces the copy of the formatted text to be done via an intermediate buffer.
  26.           //It is always used (even if not specified) when the source and destination are the same.
  27.           //It can also be specified when the text is copied from a different richmemo.
  28.  
  29.           SearchBox.SelectAll;
  30.           SentLength:= CopyRichText(SearchBox,
  31.                                     SearchBox.SelStart,
  32.                                     SearchBox.SelLength,
  33.                                     ReplaceBox,
  34.                                     ReplaceBox.SelStart,
  35.                                     ReplaceBox.SelLength,
  36.                                     []);  // option: coCopyBuf
  37.           SearchBox.SelStart:= 1;
  38.           SearchBox.SelLength:= 0;
  39.  
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: CopyToClipboard
« Reply #14 on: September 16, 2021, 01:43:23 pm »
I have noticed that it may not go italic if more than one word is selected (though not a reliable rule). It also happens with one word or letter within a range of positions (ie. 28 thru 74) on each line of a paragraph; though the range varies by a few characters.

Then I created a paragraph with no attributes at all. The ranging changed considerably, but it was still converting to italics when sent to CopyRichText, and doing so within ranges.
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

 

TinyPortal © 2005-2018