Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-05

ClipBoard.GetAsText bug?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

Can anyone confirm this?

On win9x I have a problem with ClipBoard.GetAsText.

Take a look at this example code:

  ClipText := ClipBoard.AsText;
  debugln;
  debugln('ClipText = "',ClipText,'"');
  debugln('Length = ',DbgS(Length(ClipText)));
  for i := 1 to length(ClipText) do DbgOut('#',DbgS(Ord(ClipText[i])));
  debugln;

Now when I copy (from Windows Notepad) 'ABC' to the clipboard and run the above code, the output is

ClipText = "ABC "
Length = 31
#65#66#67#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0

The first #0 after 'C' (#67) is consistent, the rest may be garbage.

I traced this down to (in /lcl/interfaces/win32/win32winapi.inc)

  function ReadClipboardToStream(DestStream: TStream): Boolean;
  begin
    Result := false;
    DataHandle := Windows.GetClipboardData(FormatID);
    if DataHandleHWND(0) then
    begin
      Size := Windows.GlobalSize(DataHandle);      // <<-------------------- **
    .....
  end;

** Size will always be n times 32 (on win32)

In ClipBoard.GetAsText there is code to remove the last trailing #0 (if there is one), but as the example shows, this is not enough. Moreover, the last char in the buffer might not even be a #0 and nothing gets removed.

Can anyone confirm this?
Is it Windows (win32) only?

Bart

Reply by email