I did it like this:
procedure SetREBackColor(RE: TRichEdit; Color: TColor);
var
CharFormat2: TCharFormat2;
begin
FillChar(CharFormat2, SizeOf(CharFormat2), 0);
CharFormat2.cbSize := SizeOf(TCharFormat2);
CharFormat2.dwMask := CFM_BACKCOLOR;
CharFormat2.crBackColor := Color;
SendMessage(RE.Handle, EM_SETCHARFORMAT,
SCF_SELECTION, LPARAM(@CharFormat2));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if ColorDialog1.Execute then
SetREBackColor(RichEdit1,ColorDialog1.Color);
end;
Make sure you have Richedit in your uses clausule!
It has something to do with Richedit2, some dll files that are standard in the newer windows versions.