[Lazarus] Visual "uglyness" when creating TSynEdit @ runtime in my app

Martin lazarus at mfriebe.de
Sat Jan 5 12:08:02 CET 2013

On 05/01/2013 10:54, luiz americo pereira camara wrote:
> 2013/1/5 luiz americo pereira camara <luizmed at oi.com.br>:
>> 2013/1/5 luiz americo pereira camara <luizmed at oi.com.br>:
>>> 2013/1/5 Mattias Gaertner <nc-gaertnma at netcologne.de>:
>>>> On Sat, 05 Jan 2013 08:32:54 +0000
>>>> Martin <lazarus at mfriebe.de> wrote:
>>>>> and therefore finally
>>>>>     s:=PageControl1.AddTabSheet;
>>>>>     PageControl1.ActivePage := s;  // paint tabsheet
>>>>>     l := TSynEdit.Create(self);
>>>>>     l.Parent := s;                               // paint scrollbars, not
>>>>> yet aligned
>>>>>     l.Align := alClient;                      // paint scrollbars
>>>>> (again), this time aligned. Since synedit itself does not yet paint, the
>>>>> previous painted scrollbars remain a visible image
>>>> It seems the Win32 intf triggers immediate paints.
>>>> Maybe some win32 developer can explain why.
>> I've found a suspect.
>> SetParent triggers the handle creation
>> TSynEdt.CreateWnd calls SizeOrFontChanged that calls UpdateScrollBars
>> Here, since PaintLock <> 0 the scrollbar change is postponed
>> Martin/Bart, can you check if you pass the check for PaintLock in
>> UpdateScrollBars?
>> Alternatively comment the call to SizeOrFontChanged in CreateWnd and
>> see what happens
> More info:
> SynEdit.CreateHandle -> DoDecPaintLock -> UpdateScrollBars ->
> ShowScrollBar (LCL) -> ShowScrollBar (Win32) -> Windows.RedrawWindow
I don't think it can be avoided.

I can detect the situation of course, but preventing that call, might 
lead to wrong display results.

s := TSynEdit.Create
// Set ALign, size, text, all options.
s.Parent := form;

The last line makes the synedit visible. SynEdit must at some time tell 
the WidgetSet that scrollbars should  be visible (assuming they should).

SynEdit can not trust that there will be a resize. The final size may be 
equal to the initial size. So it can not wait for the resize. (Assuming 
that after the first resize it would have the right/final size, and that 
therefore doing the "ShowScrollBar" in Resize would not cause as much as 
a disturbance. (It would still paint the scrollbars early, leading to a 
period of time showing only the scrollbars, but not yet the Edit).

More information about the Lazarus mailing list