Adding children to tscrollbox in runtime takes more time lazarus / 31-LCL ---------------------------------------------------------------------- gayathri · 2016-05-09 12:49 Hi All, I am having performance issues when adding many tshape components into my tscrollbox . Earlier when I added shape components directly to form, it was faster but now it is much slower. Tried using "doublebuffered = true" but it doesn't make any difference. Can anyone help me out with this problem? Thanks! ---------------------------------------------------------------------- howardpc · 2016-05-09 13:22 If you show the code that presently populates your form slowly, perhaps others can suggest improvements or optimisations. ---------------------------------------------------------------------- gayathri · 2016-05-09 13:57 My code structure is as follows: 1) I have a main framework which has the code for creation of components 2) It is registered with lua and I call the framework functions from lua. Here is the code for framework //Scrollboxes -> array of scrollboxes created //labels->array of created labels //shapes -> array of created shapes function Lua_NewScrollBox(L: Plua_State): integer; cdecl; var   x,y,w,h:integer;   s:string; begin    Result := 0;     x := lua_tointeger(L, 1);     y := lua_tointeger(L, 2);     w := lua_tointeger(L, 3);     h := lua_tointeger(L, 4);      s := lua_tostring(L, 5);   setlength(Scrollboxes, length(Scrollboxes) + 1);   Scrollboxes[length(Scrollboxes) - 1] := TScrollBox.Create(Form);  Scrollboxes[length(Scrollboxes) - 1].parent := LUA_Panel;     Scrollboxes[length(Scrollboxes) - 1].Caption := s;     Scrollboxes[length(Scrollboxes) - 1].Left := x;     Scrollboxes[length(Scrollboxes) - 1].Top := y;     Scrollboxes[length(Scrollboxes) - 1].Width := w;     Scrollboxes[length(Scrollboxes) - 1].Height := h;     Scrollboxes[length(Scrollboxes) - 1].DoubleBuffered:=true; Scrollboxes[iScrollBox].ChildSizing.ControlsPerLine := 17;       Scrollboxes[iScrollBox].ChildSizing.EnlargeHorizontal :=         TChildControlResizeStyle.crsHomogenousChildResize;       Scrollboxes[iScrollBox].ChildSizing.EnlargeVertical :=         TChildControlResizeStyle.crsHomogenousChildResize;       Scrollboxes[iScrollBox].ChildSizing.ShrinkHorizontal :=         TChildControlResizeStyle.crsHomogenousChildResize;       Scrollboxes[iScrollBox].ChildSizing.ShrinkVertical :=         TChildControlResizeStyle.crsHomogenousChildResize;      Result := 1; end;    function addtoscrollbox(L: Plua_State): integer; cdecl; var i:integer; begin //get ctrlhandle,iscrollbox , etc from lua          index :=0           labels[ctrlHandle].Parent := nil;           Scrollboxes[iScrollBox].InsertControl(labels[ctrlHandle],index);           index := index +1;           for i:= 0 to 150 do begin               shapes.Parent := nil;               Scrollboxes[iScrollBox].InsertControl( shapes,index);               index := index+1;           end;    end call from lua 1) Lua_NewScrollBox(10,10,100,100) 2)addtoscrollbox() Kindly help me out ---------------------------------------------------------------------- howardpc · 2016-05-09 15:27 In the Lua_NewScrollBox() function you could try making the assignment Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Scrollboxes[length(Scrollboxes) - 1].parent := LUA_Panel;the very last assignment of the function. How many LUA_Panels are there? Perhaps assigning the panel(s) as Parent could be delayed even further. ---------------------------------------------------------------------- gayathri · 2016-05-10 08:23 I have used omultipanel componenthttp://www.kluug.net/omultipanel.php to split the form and adding controls to it in order to achieve resize feature. I have set multipanel1 to the whole form. Inside multipanel1 there are 2 multipanels(mp2 and mp3)(mp->multipanel) Inside mp3 I have mp4,scrollbox (which we are talking about) and mp5. Inside this scrollbox I am adding many labels and shapes which is getting delayed. All these are done from my lua code which in turn calls the framework functions. One observation was initially when the shapes are added it is faster and when more shapes are appended it is getting slower. Kindly give me a possible solution for this problem. Note: I have used omultipanel inorder to obtain resize functionality for the form. LUA_Panel is the main form inside which all the components are added. Initially on creating the component, we set its parent as luapanel and then change accordingl to our design. Will calling the setparent() function take more time? ---------------------------------------------------------------------- gayathri · 2016-05-10 13:05 I have found the rootcause for the delay. I have set minimum and maximum size constraints for the shapes which was causing the delay. After removing it, it was much faster. But I need to have this constraint set for the children of scrollbox .  Is there any generic size constraints for the children of scrollbox? ---------------------------------------------------------------------- howardpc · 2016-05-11 00:30 I started a new project, dropped a scrollbox on the form and tried adding 2,500 shape controls to the scrollbox, and setting their constraints using the following code. I have a fairly fast machine, but it displayed instantaneously as far as I could tell. Could it be Lua slowing things down? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Forms, Controls, Graphics, ExtCtrls; type   TShapeArray = array of TShape;  TColorArray = array[0..19] of TColor;  TShapeTypeArray = array[0..13] of TShapeType; const    DefMaxWidth = 25;    DefMaxHeight = 25;    DefMinWidth = 12;    DefMinHeight = 12;     ColorArray: TColorArray = (                  TColor($000000), TColor($000080), TColor($008000), TColor($008080),                  TColor($800000), TColor($800080), TColor($808000), TColor($808080),                  TColor($C0C0C0), TColor($0000FF), TColor($00FF00), TColor($00FFFF),                  TColor($FF0000), TColor($FF00FF), TColor($FFFF00), TColor($FFFFFF),                TColor($C0DCC0), TColor($F0CAA6), TColor($F0FBFF), TColor($A4A0A0));     ShapeTypeArray: TShapeTypeArray = (                      stRectangle, stSquare, stRoundRect, stRoundSquare,                      stEllipse, stCircle, stSquaredDiamond, stDiamond,                      stTriangle, stTriangleLeft, stTriangleRight, stTriangleDown,                        stStar, stStarDown);type   { TForm1 }   TForm1 = class(TForm)    ScrollBox1: TScrollBox;    procedure FormCreate(Sender: TObject);  private    FShapeArray: TShapeArray;    procedure PopulateShapeArray(aShapeCount: integer);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  PopulateShapeArray(50*50); // 2500end; procedure TForm1.PopulateShapeArray(aShapeCount: integer);var  i, r, c: integer;begin  SetInitialBounds(0, 0, 860, 860);  with ScrollBox1 do begin    Left:=0;    Top:=0;    Width:=Self.Width;    Height:=Self.Height;  end;  Randomize;  SetLength(FShapeArray, aShapeCount);  for i:=0 to aShapeCount-1 do begin    FShapeArray[i]:=TShape.Create(Self);    FShapeArray[i].Brush.Color:=ColorArray[Random(20)];    FShapeArray[i].Shape:=ShapeTypeArray[Random(14)];    FShapeArray[i].Constraints.MaxHeight:=DefMaxHeight;    FShapeArray[i].Constraints.MinHeight:=DefMinHeight;    FShapeArray[i].Constraints.MaxWidth:=DefMaxWidth;    FShapeArray[i].Constraints.MaxWidth:=DefMinWidth;    r:=(i mod 50) * (DefMinHeight+5) + 5;    c:=(5 + DefMinWidth) * (i div 50) + 5;    FShapeArray[i].SetInitialBounds(c, r, DefMinWidth, DefMinHeight);    FShapeArray[i].Parent:=ScrollBox1;  end;end; end. ---------------------------------------------------------------------- gayathri · 2016-05-13 04:20 Thank you howardpc But I face the issue only when I am adding constraints. May be it is lua slowing it down. I am not sure