使用Delphi通过代码添加资源文件 [英] Add resource file by code with Delphi

查看:64
本文介绍了使用Delphi通过代码添加资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义res文件"myres.res".此时,在我的应用程序上使用它,我在DPR项目文件的{$ R * .res}行下添加了{$ R myres.res},并且效果很好.

I have a custom res file "myres.res". In this moment I use it on my application, I have add {$R myres.res} under {$R *.res} line inside my DPR project file and it work very well.

现在,我想创建具有布尔属性"UseCustomRes"的VCL组件.如果我将UseCustomRes = True设置为True,则我希望在编译项目时添加res文件,但如果我将UseCustomRes = False设置为我不想在编译项目时使用res文件.

Now I'd like creare a VCL component with a boolean property "UseCustomRes". If I set UseCustomRes=True I'd like add the res file when I compile my project but if I set UseCustomRes=False I don't want use res file when I compile my project.

这可能吗?我不知道是否可能,以及如何可能.

Is this possible? I don't know if it possible and how it is possible.

推荐答案

链接器根据特殊的$ RESOURCE指令的存在来包含资源.不能根据对象实例的属性值来切换这些指令.

Resources are included by the linker based on the existence of special $RESOURCE directives. These directives cannot be switched based on the value of an object instance's property.

因此,借助内置的工具,现在可以实现您想要的目标.您需要做的是添加一个构建后步骤,如果需要,可以通过添加资源来修改输出文件.madExcept是一个很好的工具,可以很好地做到这一点.

So, with the built in tooling there is now way to achieve what you desire. What you will need to do is to add a post-build step that modifies the output file by adding the resource if needed. A good example of a tool which does exactly this is madExcept.

这篇关于使用Delphi通过代码添加资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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