Creating or Destroying of Multiple Controls at Runtime

<< Click to Display Table of Contents >>

Navigation:  Developer's Guide > Application Design Considerations > Dynamically Created Controls >

Creating or Destroying of Multiple Controls at Runtime

If your application requires creating (or destroying) a big number of controls dynamically it is good to call SuspenLayouts()method before proceeding to start creating them.

 

Each SuspendLayouts() call must be paired with a ResumeLayouts() method, preferably in a try..finally block.

 

  SuspendLayouts;
  try
    for I := 1 to 20 do
    begin
      B := TUniDBGrid.Create(Self); // create 20 grids dynamically
      B.DataSource := DataSource1;
      B.Parent := UniContainerPanel1;
      .
      .
      .

 
    end;
  finally
    ResumeLayouts;
  end;
 

Calling SuspendLayouts() is especially useful when you are inserting new controls into an already created and rendered Form or Frame.