How can I apply Delphi XE2 skins to forms in a DLL?

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

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?

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

The host:

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; 

The 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. 

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

回答1:

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. 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.


回答2:

I had a lot of trouble with this and it was because I was using themes rather than VCL.THEMES and VCL.STYLES.

Delphi was throwing up a customeStyleException saying "style not found" or EcustomStyleException "Feature not supported by this style"



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!