Difference between revisions of "Autosize / Layout"

From Lazarus wiki
Jump to navigationJump to search
Line 20: Line 20:
 
==Do I need to call Application.ProcessMessages when creating lots of controls?==
 
==Do I need to call Application.ProcessMessages when creating lots of controls?==
  
Application.ProcessMessages is called be the LCL automatically after every message (e.g. after every event like OnClick). Calling it yourself is only needed if the any changes should become visible to the user immediately. For example:
+
Application.ProcessMessages is called by the LCL automatically after every message (e.g. after every event like OnClick). Calling it yourself is only needed if the changes should become visible to the user immediately. For example:
  
 
<DELPHI>
 
<DELPHI>

Revision as of 12:42, 7 January 2008

Anchor Sides

See Anchor Sides.

FAQ

Why does AutoSize not work in the designer properly?

In the designer controls can be dragged around and properties can be set in almost any order. To allow this and avoid possible conflicts, the AutoSizing is not updated on every change at design time.

Why does TForm.AutoSize not work when something changes?

TForm.AutoSize only works once at creation time. After that the size is up to user and the windowmanager. The application can force a resize with the following:

 AutoSize:=false; // first reset the counter
 AutoSize:=true;  // then do one AutoSize

The reason for this is, that the size of the window is controlled by the window manager. Some window managers do not allow free resizes. This would result in an endless loop between the LCL and the window manager. That's why AutoSize works only once on controls with Parent=nil.

Do I need to call Application.ProcessMessages when creating lots of controls?

Application.ProcessMessages is called by the LCL automatically after every message (e.g. after every event like OnClick). Calling it yourself is only needed if the changes should become visible to the user immediately. For example:

<DELPHI> procedure TFrom.Button1Click(Sender: TObject); begin

 // change width of a control
 Button1.Width := Button1.Width + 10;
 // apply any needed changes and repaint the button
 Application.ProcessMessages;
 // do a lot of things that takes a long time
 ...
 // after leaving the OnClick the LCL automatically processes messages

end; </DELPHI>