Is there a way to temporarily suspend VCL styles when redrawing a form?

245 Views Asked by At

I am working with this legacy Delphi app that is a candidate for being made more modern-looking with VCL styles. One form is causing a show-stopping performance issue.

This problem form dynamically creates controls from a specification. Not only that, but it doesn't create all the controls at once. It has a hierarchical organization, with controls drawn on groupboxes, and clicking a checkbox or radio button can cause the creation of a new nested groupbox with new controls in it. At least part of the time, all of the controls on the form get their states saved, get deleted, and then get re-created and their states restored. This works acceptably with old-school (think Windows NT 3.51) controls, but when VCL Styles are added this form can take over a minute to redraw itself.

I think what's happening is that styling is causing windows events that the legacy form-drawing code is responding to, causing it to repeat things it's already done. I'm wondering if there is a way to temporarily turn styling off to allow this form to draw itself completely before applying any changes that would be made by the style.

Am I doomed to disappointment?

Edit: This is with Delphi XE3.

1

There are 1 best solutions below

0
On

Use Vcl.Themes.TStyleManager to toggle the style to use, either Windows (meaning normal style) or the Vcl style you have chosen as in following testcode:

uses ..., Vcl.Themes;

TForm11 = class(TForm)
// ... 
private
  StylesDisabled: boolean;
// ...
end;

procedure TForm11.Button1Click(Sender: TObject);
begin
  StylesDisabled := not StylesDisabled;

  if StylesDisabled then
    TStyleManager.SetStyle('Windows')
  else
    TStyleManager.SetStyle('Amethyst Kamri');
end;