Home
What's New
Delphi 3.0 Tips
Questions
Development Tools
Links

How to ensure the text pasted into a RichEdit is the same font as all the other text

In windows text can readily be copied from one program to another. Because a RichEdit supports non-homogeneous fonts, there can be a problem when someone copies black text and pastes it into your program which uses yellow text because the pasted text will still be black. This problem can be averted if Application.OnActivate and Application.OnDeactivate call FixColor (below).
uses clipbrd;
.
.
.
{makes text in the clipboard lose formating
 info. such as coloring, font type and size
 because Clipboard.AsText does not
 return such info.}
procedure FixColor;
begin
  Clipboard.AsText := Clipboard.AsText;
end;