如何将Delphi XE2外观应用于DLL中的表单? [英] How can I apply Delphi XE2 skins to forms in a DLL?

查看:80
本文介绍了如何将Delphi XE2外观应用于DLL中的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Delphi XE2,您可以选择将自定义样式(皮肤)嵌入到VCL项目中.
一切正常.现在,我将某些表格放入动态显示的单独的dll中.
当然,这些不是皮肤.我该如何纠正?

Using Delphi XE2, you have the option to embed custom styles (skins) to a VCL project.
Everything works fine. Now I have some forms into a separated dll that I show dynamically.
Of course those are not skinned. How can I rectify that?

我想我必须以某种方式打电话给TVisualStyle,但是没有运气.

I guess I must do some call to TVisualStyle somehow, but no luck.

主持人:

procedure TForm1.Button1Click(Sender: TObject); 
var   
  l: THandle;   
  p: procedure (const h: THandle); stdcall; 
begin   
 l:= LoadLibrary('project1.dll');   
 if l > 0 then   
 begin
        @p:= GetProcAddress(l,'ShowIt');
        p(Application.Handle);
        FreeLibrary(l);   
  end; 
end;

dll:

procedure ShowIt(const h: THandle);stdcall;
var
  form: TForm;
  b: TButton;
  han: THandle;
begin
  han:= Application.Handle;
  Application.Handle:= h;
  form :=Tform.Create(Application);
  b:= TButton.Create(form);
  b.Parent:= form;
  b.Caption:= 'ytes';
  b.Left:= 2;
  b.Top:= 2;
  form.ShowModal;
  form.Release;
  Application.Handle:= han;
end;

exports ShowIt ;
begin
end.

相当标准的东西.现在,要使dll表单使用主机的样式主题,究竟需要做什么?

Pretty standard stuff. Now, what exactly must be done to make the dll form use the host's style theme?

推荐答案

您有两个不同的VCL实例.您已经在可执行文件拥有的 StyleServices 实例中设置了样式,但是您的DLL具有对此一无所知.您可以通过以下任一方法解决此问题:

You have two distinct instances of the VCL. You have set the style in the StyleServices instance owned by the executable, but your DLL has no knowledge of that. You could solve this by either:

  1. 将样式设置传递给DLL中的功能,该功能将这些设置应用于其他StyleServices实例.
  2. 使用软件包,以便您只有一个VCL实例.
  1. Passing the style settings to a function in your DLL that applies those settings to the other StyleServices instance.
  2. Use packages so that you only have a single VCL instance.

这篇关于如何将Delphi XE2外观应用于DLL中的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆