Forum > Editor

Unable to paste into Lazarus editor from another application

<< < (2/5) > >>

Maybe not relevant, but you mention Ctrl+V: if you selected classic keyboard scheme in the IDE options / Keyboard mapping (like I do) then this will never work, you must use Shift+Ins instead.

To further investigate the clipboard you could also try my program "Clipboard Explorer" ( After pressing the "Refresh" button it lists all formats contained in the clipboard and displays the clipboard content for each format as a hex dump or, when possible, in a memo, RichMemo, or image.

The minimum requirement for pasting text into the IDE is a text/plain format (CF_TEXT).

Note that for compilation you need the packages KControls and RichMemo which you can install easily via Online-Package-Manager.

Of course this program was written with Lazarus, and when Lazarus has a bug in clipboard handling this program will have this bug, too.

A similar program is Jesus Reyes' "clipanalizer" found on CCR:

I couldn't try "Clipboard Explorer" (clipbex) program very much: After I compiled and ran it, it displayed its main window. However, when I do a "Refresh" it starts displaying something on its main window and immediately crashes. Here is its console output:

--- Code: ---./clipbex
Gtk-Message: 15:58:49.041: Failed to load module "canberra-gtk-module"
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!
Peek !!!

(clipbex:30502): Gdk-CRITICAL **: 15:58:51.253: IA__gdk_x11_atom_to_xatom_for_display: assertion 'ATOM_TO_INDEX (atom) < virtual_atom_array->len' failed
The program 'clipbex' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadAtom (invalid Atom parameter)'.
  (Details: serial 9826 error_code 5 request_code 24 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
--- End code ---

Sometimes, it does not crash, but in this case it displays nothing. I think, it is a similar case like the following (see next paragraph and also the attached screenshot).

I ran the "Clipboard Analizer" (clipanalizer) program. Although it is buggy (crashes from time to time), when this problem occurs (that is, when Lazarus cannot read the clipboard contents, while other applications can) this program displays 0 length data for everything as can be seen in the attachment.


As a simpler test case, I added 3 memos, 1 button and 1 label to an empty form with the following code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  fc, i : Integer;  outstr : String;begin  if Clipboard.HasFormat(CF_TEXT) then  begin    Memo1.Text := ClipBoard.AsText;    Label1.Caption := IntToStr(Length(ClipBoard.AsText));  end  else    Label1.Caption := 'There is no text on the Clipboard';  Memo2.Text :=  PrimarySelection.AsText;  fc := ClipBoard.FormatCount;  outstr := 'FormatCount : ' + IntToStr(fc) + lineending;  for i:=1 to fc do  begin    outstr := outstr + inttostr(i) + '/' +      inttostr(ClipBoard.Formats[i].Size) + ' : ' +      ClipBoard.Formats[i].ToString + lineending;  end;  Memo3.text := outstr;end;
When this problematic case occurs; after I launch my program:

* After the first click to button; Label1 displays 0; Memo1 and Memo2 become empty, while Memo3 displays FormatCount : 0
* After the second click to the button (without doing anything else on the system): Label1 displays There is no text on the Clipboard; Memo1 is untouched, Memo2 becomes empty, while Memo3 displays FormatCount : 0

Martin, probably unrelated but this bug reminds me the fix for the null trailing character. When it's applied there is issues with copy paste from a synedit to another.

fedkad, can you try to compile Lazarus with this additional defines : GTK_REMOVE_CLIPBOARD_NULL, then test, come back an tell us if the things work better ?


--- Quote from: Basile-B on May 01, 2019, 07:39:20 pm ---Martin, probably unrelated but this bug reminds me the fix for the null trailing character. When it's applied there is issues with copy paste from a synedit to another.

--- End quote ---
Am I missing something? I thought that had been fixed?

IIRC (but its a bit ago), the initial fix failed, because it removed #0 from binary too. But then the fix was moved so it applies to text only. (Or rather does not add it to start with)

Revision: 58530 Author: martin Date: 15 July 2018 12:23:43
Message: Clipboard: fix trailing null issue for gtk2. Issue 0021453

Yes indeed, it's fixed. I don't know how I've managed to miss that. Nice to see the BT upgraded BTW.

fedkad: ignore my previous suggestion, it can solve nothing.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version