答案已更新!再一次。
VCL
但我会尽力解释如何避免你的问题。在你进一步阅读之前,我应该告诉你:
无法注销任何样式
.
风格还是不风格
氯乙烯
的样式使用内部
FRegisteredStyles
要存储的词典
全部的
注册样式。样式在之后注册
TStyleManager.LoadFromFile(YourStyleName)
不要使用
UnregisterStyle
风格。因此,在你打电话之后
UnregisterStyle(YourStyle)
你就把他干掉
YourStyle
来自内部列表,而不是来自前面提到的字典,并且无法设置此样式。
成功呼叫后
UnregisterStyle()
你可以打电话
LoadFromFile()
方法和疑问为什么应用程序说:
LoadFromFile()
方法加载指定的样式并检查其在已注册样式的内部字典中的存在。这张支票总是回来的
true
注销样式()
过程不会从字典中删除指定的样式。
同样的事情也与财产有关
StyleNames
. 此属性返回使用内部样式的名称
FRegisteredStyles公司
字典以获取具有指定索引的样式名称。
样式化结果
procedure TForm1.Button1Click(Sender: TObject);
begin
if Assigned(TStyleManager.Style['Emerald']) and TStyleManager.Style['Emerald'].Available then
// Do your code
else
ShowMessage('Specified style is not available!');
end;
如果你有
VCL.Themes
你可以很容易地检查我在这里写的东西的真实性。
我创造了
class-helper
对于
TStyleManager
它允许检查样式文件是否已注册,并在需要时注销它。为了填补
TStyleInfo
用样式文件中的实际值记录,我们需要将指定的样式保存到
TMemoryStream
IsValidStyle
功能。我们也可以用
风格(f.e。
C:\Embarcadero\Delphi\Styles\Emerald.vsf
)而不是变种与流,但后者看起来更优雅。
不幸的是,根据
雷米的评论
(我不知道如何链接到它),
C++ Builder
(由OP使用)不支持
功能。唯一的解决方案是创建一个简单的单元,其中包含
类助手
uses
子句并调用适当的公共程序\函数。
该装置具有以下结构:
unit StyleManager_CH;
interface
uses
VCL.Themes;
function IsStyleRegistered_CH(var AStyle: TCustomStyleServices): Boolean;
procedure UnregisterStyleEx_CH(var AStyle: TCustomStyleServices);
implementation
uses
System.SysUtils, System.Classes, System.Generics.Collections;
type
TStyleManagerHelper = class helper for TStyleManager
public
class function IsStyleRegistered(var AStyle: TCustomStyleServices): Boolean;
class procedure UnregisterStyleEx(var AStyle: TCustomStyleServices);
end;
class function TStyleManagerHelper.IsStyleRegistered(var
AStyle: TCustomStyleServices): Boolean;
begin
Result := Assigned(AStyle) and
TStyleManager.FRegisteredStyles.ContainsKey(AStyle.Name);
end;
class procedure TStyleManagerHelper.UnregisterStyleEx(var
AStyle: TCustomStyleServices);
var
MS: TMemoryStream;
StyleInfo: TStyleInfo;
SourceInfo: VCL.Themes.TStyleManager.TSourceInfo;
begin
if Assigned(AStyle) then
begin
MS := TMemoryStream.Create;
try
AStyle.SaveToStream(MS);
MS.Position := 0;
if AStyle.IsValidStyle(MS, StyleInfo) then
begin
if TStyleManager.FRegisteredStyles.ContainsKey(StyleInfo.Name) then
begin
SourceInfo := TStyleManager.FRegisteredStyles.Items[StyleInfo.Name];
if Assigned(SourceInfo.Data) then
FreeAndNil(SourceInfo.Data);
TStyleManager.FStyles.Remove(AStyle);
TStyleManager.FRegisteredStyles.Remove(StyleInfo.Name);
FreeAndNil(AStyle);
end;
end;
finally
MS.Free;
end;
end;
end;
function IsStyleRegistered_CH(var AStyle: TCustomStyleServices): Boolean;
begin
Result := TStyleManager.IsStyleRegistered(AStyle);
end;
procedure UnregisterStyleEx_CH(var AStyle: TCustomStyleServices);
begin
TStyleManager.UnregisterStyleEx(AStyle);
end;
end.
附录
_CH
代表
缩写。还修复了一些内存泄漏。
重新加载