DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: shz0000
今日帖子: 38
在线用户: 9
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 dalas (dalas) ★☆☆☆☆ -
普通会员
2021/10/17 9:58:11
标题:
请教 TStyleManager 如何清除已经加载的皮肤 浏览:1339
加入我的收藏
楼主: TStyleManager 加载了很多皮肤,很占内存,想清除一些没有使用的,找半天没见类似 Clear 方法,请问如何清除呢?
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/10/17 12:47:22
1楼: hi @Dalas

try my code if works for you:



implementation

{$R *.dfm}

uses
  Vcl.Themes;

const
  StyleDir: string = 'C:\Users\Public\Documents\Embarcadero\Studio\22.0\Styles\';
  MyStyle: string  = 'RubyGraphite.vsf'; // 'GoldenGraphite.Style'; // 'RubyGraphite.vsf';

var
  MyStyleServicesHandle: Pointer;

procedure TForm1.BtnAddNewStyleByFileNameClick(Sender: TObject);
var
  StyleInfo: TStyleInfo;
begin
  if TStyleManager.IsValidStyle('C:\Users\Public\Documents\Embarcadero\Studio\22.0\Styles\RubyGraphite.vsf', StyleInfo) then
  begin
    if TStyleManager.Style[StyleInfo.Name] <> nil then
    begin
      // ShowMessage('Style already loaded...');
      exit;
    end;
    //
    MyStyleServicesHandle := TStyleManager.LoadFromFile('C:\Users\Public\Documents\Embarcadero\Studio\22.0\Styles\RubyGraphite.vsf');
    // ShowMessage('MyStyleServicesHandle := TStyleManager.LoadFromFile...');

    if not(MyStyleServicesHandle = nil) then
    begin
      TStyleManager.SetStyle(MyStyleServicesHandle);
      // ShowMessage('TStyleManager.SetStyle(MyStyleServicesHandle);');
    end;
    //
    ListBox1.Items.Clear;
    ListBox1.Items.AddStrings(TStyleManager.StyleNames);
  end
  else
    ShowMessage('Not OK');
end;

procedure TForm1.BntAddAllStyleOnListBoxClick(Sender: TObject);
begin
  ListBox1.Items.AddStrings(TStyleManager.StyleNames);
end;

procedure TForm1.BtnClick(Sender: TObject);
begin
  if not(MyStyleServicesHandle = nil) then
  begin
    ListBox1.Items.Clear;
    ListBox1.Items.AddStrings(TStyleManager.StyleNames);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.Items.AddStrings(TStyleManager.StyleNames);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
  StyleToRemove: string;
begin
  if (ListBox1.ItemIndex > -1) then
  begin
    StyleToRemove := ListBox1.Items[ListBox1.ItemIndex];
    //
    if not(StyleToRemove = TStyleManager.SystemStyleName) then
    begin
      if not(StyleToRemove = TStyleManager.ActiveStyle.Name) then
      begin
        TStyleManager.RemoveDesigningStyle(StyleToRemove);
        //
        ListBox1.DeleteSelected;
        //
        Memo1.Lines.Clear;
        Memo1.Lines.AddStrings(TStyleManager.StyleNames);
      end
      else
        ShowMessage('Style in use cannot be removed for while...');
    end
    else
      ShowMessage(Format('%s, is a SystemStyle - Cannot be removed', [StyleToRemove]));
    // TStyleManager.SetStyle(ListBox1.Items[ListBox1.ItemIndex]);
  end;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
var
  StyleToApply: string;
begin
  if (ListBox1.ItemIndex > -1) then
  begin
    StyleToApply := ListBox1.Items[ListBox1.ItemIndex];
    //
    TStyleManager.SetStyle(StyleToApply);
  end;
end;

end.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 dalas (dalas) ★☆☆☆☆ -
普通会员
2021/10/17 16:42:48
2楼: TStyleManager.RemoveDesigningStyle 没有这个方法
此帖子包含附件:
PNG 图像
大小:569.9K
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/10/18 0:43:45
3楼: You dont say what EDITION you use!!!!

im using RAD 11 Alexandria for while!
--- Native class "TStyleManager"

It's only important say the target = Edition!

On RAD 11:
class procedure TStyleManager.RemoveDesigningStyle(const Name: string);
var
  LInfo: TSourceInfo;
begin
  if FRegisteredStyles.TryGetValue(Name, LInfo) and LInfo.DesigningState then
  begin
    if SameText(FActiveDesigningStyle.Name, Name, loUserLocale) then
      FActiveDesigningStyle := SystemStyle;
    RemoveStyleData(Name, LInfo);
  end;
end;


class procedure TStyleManager.RemoveStyleData(const AStyleName: string; AInfo: TSourceInfo);
var
  LIndex: Integer;
  LStyle: TCustomStyleServices;
begin
  LStyle := FindStyle(AStyleName, LIndex);
  if LStyle <> nil then
  begin
    LStyle.Free;
    FStyles.Delete(LIndex);
  end;
  TMemoryStream(AInfo.Data).Free;
  FRegisteredStyles.Remove(AStyleName);
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/10/18 0:49:01
4楼: by Stephen Ball - MVP Embarcadero

https://delphiaball.co.uk/2014/10/22/adding-vcl-styles-runtime/
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 dalas (dalas) ★☆☆☆☆ -
普通会员
2021/10/18 11:59:54
5楼: 哦哦,我用的还是 10.4.2,晚上用 11 试试。
谢谢!!
----------------------------------------------
-
作者:
男 dalas (dalas) ★☆☆☆☆ -
普通会员
2021/10/18 19:52:24
6楼: delphi 11 有 RemoveStyle,10和11能共存吗?
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/10/19 4:45:55
7楼: RAD 11 can coexists with any other edition, as before editons!!!
--> the basic secret is the "PATH" installation!
-----> distinct FOLDERS on disk!!!
-----> distinct "PATH" environment on system!!!

my preferences:
--- I dont use "Program Files or (x86) folder as ROOT
---> c:\EMB  <---- my root folder for RAD/Delphi
-----> c:\Emb\DelphiX
---------> c:\Emb\DelphiX\ComponentsSuiteX
-----> c:\Emb\RAD11
---------> c:\Emb\RAD11\ComponentsSuiteY

do you understand?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行85.9375毫秒 RSS