仅使用内置工具在 Delphi XE 中制作组件图标的最佳方法
在Delphi 7中,包含一个图像编辑器程序,它可以读写.dcr
文件,这些文件只是具有不同扩展名的二进制资源文件(.res
文件),按照约定,.dcr 文件包含一个已编译的资源,其中包含已命名的位图资源,这些资源的名称与您的组件名称相对应(对于名为 TMyComponent 的组件,名为 TMYCOMPONENT 的位图资源)。这些位图是用于在 Delphi 组件面板上放置图标的“图标”的来源,以及当您将非可视组件放在其上时在表单或数据模块上放置图标的位置。
快进到 Delphi XE 10 年了,我正在尝试使用位图文件和 RC 文件制作组件图标,并将其构建为 .DCR 文件,作为 Delphi IDE 的一部分。
应该简单地在 .dpk(包源)文件中添加一个 .Rc 文件和这样的声明,如下所示:
{$R mypackageicons.rc mypackageicons.dcr}
包含组件图标的示例 .rc 文件:
// COMPONENT ICON RESOURCES
TMYCOMPONENT BMP "TMYCOMPONENT.BMP"
但是我无法让它工作。当我尝试时,似乎出现了一些奇怪的 RLINK32 错误,并且 IDE 在 borlandmm.dll 中崩溃:
[DCC Error] E2161 Error: RLINK32: Unsupported 16bit resource in file "C:\temp\compicon\COMPONENTICONS.rc"
[DCC Fatal Error] F2084 Internal Error: AV21515155-W06000D07-1
有问题的位图文件是一个简单的 256 色 bmp 文件,大小为 24x24 像素,我也尝试过 16 色位图,没有运气。在我看来,ImageEdit 程序是我所知道的唯一可以用来创建 Delphi 组件图标的方法。
我错过了什么?
更新: 对于无法访问 Delphi 7 图像编辑器的人来说,外部工具是一个很好的解决方案,并且实际上可能更优越,但我更愿意仅使用附带的工具来完成此操作Delphi,因为似乎只使用一个 {$R} 声明、一个文本文件和一个用画笔制作的 bmp 文件就可以了。当然,他们没有忽略使用这个伟大的 1.5 GB 开发工具来制作组件图标! .. 更新2:有一种方法;鲁迪五世找到了它。
In Delphi 7, an image editor program is included, which can read and write .dcr
files, which are merely binary resource files (.res
files) with a different extension, which by convention indicates that the .dcr file contains a compiled resource with named bitmap resources that have names corresponding to your component names (a bitmap resource named TMYCOMPONENT for a component named TMyComponent). These bitmaps are where the "icons" used to put an icon on the delphi component palette, and on your form or data-module when you drop a non-visual component on it, come from.
Fast forward 10 years to Delphi XE, and I am trying to make component icons using a bitmap file, and an RC file, and have that build to a .DCR file, as part of the Delphi IDE.
It should be simply a matter of adding an .Rc file and a declaration like this in the .dpk (package source) file, like this:
{$R mypackageicons.rc mypackageicons.dcr}
A sample .rc file containing a component icon:
// COMPONENT ICON RESOURCES
TMYCOMPONENT BMP "TMYCOMPONENT.BMP"
However I can not get this to work. It seems that you get some bizarre RLINK32 errors, and IDE crashes in borlandmm.dll, when I try it:
[DCC Error] E2161 Error: RLINK32: Unsupported 16bit resource in file "C:\temp\compicon\COMPONENTICONS.rc"
[DCC Fatal Error] F2084 Internal Error: AV21515155-W06000D07-1
The bitmap file in question is a simple 256 color bmp file size 24x24 pixels, and I have also tried 16 color bitmaps, with no luck. It seems to me that the ImageEdit program is the only way that I know of that I can use to create Delphi component icons.
What am I missing out on?
Update: The external tools are a nice solution for people who don't have access to the Delphi 7 image editor, and may in fact be superior, but I would prefer to do this using only what ships with Delphi, because it seems that it should be possible using just one {$R} declaration, a text file, and a bmp file made with paintbrush. Surely they didn't omit to make a way to make component icons, with this great big 1.5 gigabyte developer tool! .. update2: And there is a way; Rudy V. found it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用过并取得了巨大成功:
更新
我刚刚在 XE 中尝试了以下操作,并且成功了。
dclusr.pdk 的源文件有一个新条目
{$R *.dres}
(注意扩展名)。我可以在 Samples 调色板中看到 TNewAnimate 以及 TMRUComboBox.bmp 中的字形。我将 dclusr.dres 与 dclusr.dpk 位于同一目录中(通常位于 C:\Program Files 下,但不在我的设置中)。我尝试使用 XN 资源编辑器打开它,但拒绝打开它,并显示一条神秘的错误消息。看起来这不是一个正常的 .res 文件。
I have used and had great success with:
Update
I just tried the following, in XE, and was successful.
The source file for dclusr.pdk got a new entry
{$R *.dres}
(note the extension). I could see the TNewAnimate in the Samples palette with the glyph in TMRUComboBox.bmp.I located dclusr.dres in the same directory as dclusr.dpk (which is normally under C:\Program Files, but not in my setup). I tried to open it with XN Resource Editor, but that refused to open it with a cryptic error message. It is not a normal .res file, it seems.
尝试资源编辑器。旧图像编辑器的一个很好的替代品。
Try Resource Editor. A nice replacement for old Image Editor.
首先将 'mypackageicons.rc' 文件添加到项目中,这会在编译时生成 'mypackageicons.res' (请参阅相关 SO 回答问题“在项目中包含资源文件.RC 文件而不是 .RES 文件”)。
还要将
{$R mypackageicons.res mypackageicons.dcr}
添加到组件单元(或 .dpk)。这不会生成“.dcr 文件”,但会设置组件的图标。请注意,我对“BMP”资源的测试失败了。我使用“BITMAP”作为资源类型。
First add 'mypackageicons.rc' file to the project, this produces 'mypackageicons.res' at compile time (see related SO answer to the question "Including resource file in a project by .RC file rather than .RES file").
Also include
{$R mypackageicons.res mypackageicons.dcr}
to the component unit (or to the .dpk). This does not produce a '.dcr file', but sets the icon for the component.Note that my test with a 'BMP' resource failed. I used 'BITMAP' as resource type.
我已经使用 Delphi XE5 upd2 调查了以前的响应。没有多大成功。因此,我尝试构建一个新的解决方案,并找到了一个源自以前答案的解决方案。
简而言之:
1. 使用 Windows Paint 程序创建位图。
2. 使用位图创建资源脚本文件。
3.使用BRCC32编译脚本生成dcr文件
4. 将dcr文件包含到包源中
5. 重新编译/安装包
要自动执行此操作,只需将 BRCC32 命令行添加到包项目“预构建事件”中即可。这样,您的 dcr 文件将在每次构建之前重新创建。
有关详细说明,请参阅我的博客 http://francois-piette.blogspot.be/2014/02/howto-create-dcr-file-for-your-delphi.html
I have investigated the previous responses using Delphi XE5 upd2. Not much success. So I tried to build a new solution and found one derived from previous answers.
In short:
1. Create your bitmap using Windows Paint program.
2. Create a resource script file with the bitmap.
3. Compile the script with BRCC32 to produce the dcr file
4. Include the dcr file into the package source
5. Recompile/Install the package
To automate this, it is enough to add the BRCC32 command line into the package project "pre-build events". This way, you dcr file will be recreated before each build.
For a detailed description, see my blog at http://francois-piette.blogspot.be/2014/02/howto-create-dcr-file-for-your-delphi.html