我正在研究主题感知组件,创建组件时,必须使用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;
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.