Jump to content
Sign in to follow this  
Perpeto

TColorBox bad performance, if style differs from default

Recommended Posts

I have a test application, where i only have a TColorBox-Component. If I change the style in any way, it takes ~20ms to initialise. In Delphi11 it's faster than in Delphi12, because Delphi12 has more Colors in "System.UIConsts".

In our "real" application we do have some dialogs with 20 or more coloroboxes, which adds up to 700ms per Dialog only to initialize those colorboxes. 

 

We assume, that the issue is in TCustomColorBox.PopulateList or more preciseley "TCustomColorBox.ColorCallBack".

Does anyone have tips how to speed things up or what i do wrong here?

 

Thanks!

unit colorbox_performance;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm22 = class(TForm)
    ColorBox1: TColorBox;
    procedure FormShow(Sender: TObject);
  end;

var
  Form22: TForm22;

implementation

uses
  diagnostics;

{$R *.dfm}

{ TForm22 }
procedure TForm22.FormShow(Sender: TObject);
begin
  var StopWatch := TStopwatch.StartNew;
  ColorBox1.Style := ColorBox1.Style - [cbStandardColors];
  ShowMessage(format('%dms', [round(StopWatch.Elapsed.TotalMilliseconds)]));
end;

.

Share this post


Link to post

If all or most of the comboboxes need to be populated with the same items, then cache the Items of one combobox to a TStringList.

Then use ColorBox1.Items := CachedColorItems instead of setting its Style. On my side it increases the performance from 20ms to 15ms

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×