Clipboard open during execution of OnChange event

General TRichView support forum. Please post your questions here
Post Reply
markussamuelsson
Posts: 3
Joined: Mon Aug 23, 2010 7:18 am

Clipboard open during execution of OnChange event

Post by markussamuelsson »

Sergey,

We have found a subtle bug in TCustomRichViewEdit.PasteRVF.

The problem is caused by Clipboard.Close being called after InsertRVFFromStreamEd(Stream) in combination with showing a MessageBox (or doing any time consuming operation) in the OnChange event.

InsertRVFFromStreamEd triggers the OnChange event where we pop up the MessageBox. While the MessageBox is still open the Clipboard hasn’t been closed, so if the user switches to another application, e.g. a text editor, he can’t do any copy/paste. The call to OnChange can take an arbitrary amount of time, depending on what is implemented here.

The bug is resolved by calling Clipboard.Close before InsertRVFFromStreamEd(Stream).

Current code causing the undesired behavior:

Code: Select all

procedure TCustomRichViewEdit.PasteRVF;
begin
  if not Clipboard.HasFormat(CFRV_RVF) then exit;
  Clipboard.Open;
  Stream := TRVMemoryStream.Create;
  try
    ...
    Stream.Position := SizeOf(Size);    
    InsertRVFFromStreamEd(Stream);  		<-- Here OnChange is called, while Clipboard is still open
  finally
    Stream.Free;
    Clipboard.Close;
  end;
end;
Suggested changes:

Code: Select all

procedure TCustomRichViewEdit.PasteRVF;
begin
  if not Clipboard.HasFormat(CFRV_RVF) then exit;
  Stream := TRVMemoryStream.Create;
  try
    Clipboard.Open;
    try
      ...
      Stream.Position := SizeOf(Size);
    finally
      Clipboard.Close;
    end;
    InsertRVFFromStreamEd(Stream);	<-- OnChange is called. Clipboard is closed and can be used by other applications
  finally
    Stream.Free;
  end;
end;
The same problem and solution applies to TCustomRichViewEdit.PasteGraphicFiles and TCustomRichViewEdit.PasteRTF.

Regards,
Markus Samuelsson
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Ok, this change will be included in the next update.
Post Reply