Results 1 to 15 of 23

Thread: TGridPanel.Free ?? Slow

Threaded View

  1. #1

    TGridPanel.Free ?? Slow

    Hoi,

    Is er een mogelijkheid om dat hele FREE te versnellen?
    Een matrix van 6x6 is wel te doen maar 26x26 kost veel tijd en dat zit in de FREE.

    Code:
    for I := 0 to Pred(MainGridPanel.ControlCount) do
        MainGridPanel.Controls[0].Free; // Always slow
    Hier is de complete INIT.

    Code:
    procedure TfrmControlPad.CreateGradientPanels(const rowCount, colCount: Integer);
    var
      I: Integer;
      AMainPanel: TPanel;
      AMainLabel: TLabel;
      AMainGradient: TGradient;
    begin
      MainGridPanel.RowCollection.BeginUpdate;
      MainGridPanel.ColumnCollection.BeginUpdate;
    
      for I := 0 to Pred(MainGridPanel.ControlCount) do
        MainGridPanel.Controls[0].Free; // Always slow
    
      // Cannot clear if there are controls, so first remove "old" controls above
      MainGridPanel.RowCollection.Clear;
      MainGridPanel.ColumnCollection.Clear;
    
      for I := 1 to rowCount do MainGridPanel.RowCollection.Add;
      for I := 1 to colCount do MainGridPanel.ColumnCollection.Add;
    
      for I := 0 to Pred(rowCount * colCount) do
      begin
        // Background Panel
        AMainPanel := TPanel.Create(Self);
        AMainPanel.Parent := MainGridPanel; //magic: place in the next empty cell
        AMainPanel.StyleElements := [];
        AMainPanel.Visible := True;
        AMainPanel.Tag := (I + 1);
        AMainPanel.Name := 'Panel' + Format('%.2d', [I + 1]);
        AMainPanel.BevelOuter := bvNone;
        AMainPanel.ParentBackground := False;
        AMainPanel.ParentColor := True;
        AMainPanel.ShowCaption := False;
        AMainPanel.Align := alClient;
        AMainPanel.AlignWithMargins := True;
        AMainPanel.Margins.SetBounds(0, 0, 2, 2);
        // Label on Panel
        AMainLabel := TLabel.Create(Self);
        AMainLabel.Parent := AMainPanel;
        AMainLabel.StyleElements := [];
        AMainLabel.ParentFont := False;
        AMainLabel.ParentColor := False;
        AMainLabel.WordWrap := True;
        AMainLabel.Top := ControlpadHintTop;
        AMainLabel.Left := ControlpadHintLeft;
        AMainLabel.Font.Size := ControlpadFontsize;
        AMainLabel.Font.Color := clBlack;
        AMainLabel.Visible := True;
        AMainLabel.Tag := (I + 1);
        AMainLabel.Name := 'Label' + Format('%.2d', [I + 1]);
        AMainLabel.Transparent := True;
        // Gradient on Panel
        AMainGradient := TGradient.Create(Self);
        AMainGradient.Parent := AMainPanel;
        AMainGradient.StyleElements := [];
        AMainGradient.Visible := True;
        AMainGradient.Tag := (I + 1);
        AMainGradient.Name := 'Gradient' + Format('%.2d', [I + 1]);
      end;
    
      MainGridPanel.RowCollection.EndUpdate;
      MainGridPanel.ColumnCollection.EndUpdate;
    end;
    En voor de liefhebbers met ssPercentage problemen. Dit werkt heel goed ik gebruik het al jaren...
    En zo ook voor de Colomns

    Code:
    procedure SetGridResizeRows;
      var
       I, ADiv, AMod: Integer;
       AValue: Double;
      begin 
        ADiv := (MainGridPanel.Height ) div rowCount;
        AMod := (MainGridPanel.Height) mod rowCount;
    
        MainGridPanel.RowCollection.BeginUpdate;
    
        { Kolommen berekenen }
        for I := 0 to Pred(MainGridPanel.RowCollection.Count) do
        begin
          MainGridPanel.RowCollection[I].SizeStyle := ssAbsolute;
          MainGridPanel.RowCollection[I].Value := ADiv;
        end;
    
        { Fix restant; AMod pixel verdelen over de eerste kolommen }
        for I := 0 to Pred(AMod) do
        begin
          if (I < MainGridPanel.RowCollection.Count) then // Controle voor AV!
          begin
            AValue := MainGridPanel.RowCollection[I].Value;
            MainGridPanel.RowCollection[I].SizeStyle := ssAbsolute;
            MainGridPanel.RowCollection[I].Value := (AValue + 1);
          end;
        end;
    
        MainGridPanel.RowCollection.EndUpdate;
      end;
    Last edited by DragonFly; 14-Jul-21 at 12:12.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •