Clipboard open during execution of OnChange event
Posted: Tue Aug 24, 2010 10:02 am
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:
Suggested changes:
The same problem and solution applies to TCustomRichViewEdit.PasteGraphicFiles and TCustomRichViewEdit.PasteRTF.
Regards,
Markus Samuelsson
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;
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;
Regards,
Markus Samuelsson