D2 Question - Set edit area in Rich Edit window


I have defined a small routine to set the text display area of a
TRichEdit  as follows:

procedure TMainForm.SetEditRect;
  R: TRect;
  R := RichEdit.ClientRect;
  InflateRect(R, -20, -18);
  SendMessage(RichEdit.Handle, EM_SETRECT, 0, Longint(@R));

I then call this routine in the program's OnResize event handler, and
wherever else the code could force the Rich Edit window to resize. In
my application, this can happen in a number of ways.

In D1 and using a TMemo, but basically the identical application, this
works just fine. Whenever the window resizes, the text paints just
once. But in D2 with the Rich Edit, the text repaints twice, and maybe
even three times. The result is a very ugly flashing effect. When
tracing the code execution in the de{*word*81}, it seems that the resize
event gets called again, and the program executes back through the
SetEditRect routine. It is clear that a D2 program executes
differently from a D1 program somehow, behind the scenes.

This creates a very unprofessional looking effect in my application,
and I would like to eliminate it. However, I've not yet come up with
the solution.

I have tried:
1) call the SetEditRect routine between RichEdit.Lines.BeginUpdate and
RichEdit.Lines.EndUpdate, but the routine has no effect there.
2) call the SetEditRect routine while the WM_SETREDRAW flag is set to
false, but again the routine has no effect (nothing is changed when
the REDRAW flag is set back to true.)

What can I do to solve this problem? Any ideas would certainly be
Michael Purcell