如何初始化组件中活动主题的状态?

问题描述 投票:0回答:1

我正在研究主题感知组件,创建组件时,必须使用IsThemeActive(来自UxTheme单元)设置初始状态。但是,如果我在组件constructor中使用此功能,则会出现访问冲突。在其他任何地方使用它都可以正常工作。发生了什么?如果在OnCreate中无法设置初始状态,该如何设置?

我的组件单位:

unit TestUnit;

interface

uses Classes, Windows, Controls, ComCtrls, StdCtrls, CommCtrl, Messages, Forms,
     SysUtils, Graphics, UxTheme;

type
  TSuperList = class(TListView)
  private
    FThemeEnabled: Boolean;
  public
    constructor Create(AOwner: TComponent); override;
  end;

implementation

constructor TSuperList.Create(AOwner: TComponent);
begin
 inherited;
 FThemeEnabled:= IsThemeActive;
end;

end.

在应用程序中使用:

procedure TForm1.FormCreate(Sender: TObject);
begin
 List1:= TSuperList.Create(Form1);
 List1.Parent:= Form1;
end;
delphi themes delphi-2009
1个回答
1
投票
unit TestUnit; interface uses Classes, Windows, Controls, ComCtrls, StdCtrls, CommCtrl, Messages, Forms, SysUtils, Graphics, UxTheme; type TSuperList = class(TListView) private FThemeEnabled: Boolean; public constructor Create(AOwner: TComponent); override; end; implementation constructor TSuperList.Create(AOwner: TComponent); begin inherited; FThemeEnabled:= IsThemeEnabled; end; initialization InitThemeLibrary; IsThemeEnabled:= IsThemeActive; end.
© www.soinside.com 2019 - 2024. All rights reserved.