文本资源无法编译到我的Delphi exe中 [英] Text resource won't compile into my Delphi exe
问题描述
我在Delphi程序中使用了一个单词列表,直到现在我仍将列表放在TMemo的Lines属性中.不过,我不需要视觉组件,而是TStringList,所以现在我想通过使用资源文件来以正确的方式执行操作,然后从资源中加载我的TStringList.我尝试应用来自此答案的信息,但出现错误:
I use a list of words in my Delphi program, and until now I would place the list in the Lines property of a TMemo. I don't need the visual component, though, rather a TStringList, so now I want to do things the proper way by using a resource file for this, and load my TStringList from the resource. I tried applying the information from this answer, but I get an error:
[dcc32错误] E2161错误:RLINK32:文件"D:\ etc \ Unit1.rc"中不受支持的16位资源
[dcc32 Error] E2161 Error: RLINK32: Unsupported 16bit resource in file "D:\etc\Unit1.rc"
为了很好,我有这个Unit1.rc文件:
For good measure, I have this Unit1.rc file:
RC_keywords RCDATA "keywords.txt"
我是在Project→中创建的资源和图片...,但是看起来就像自己编写.rc文件一样.
I created this in Project → Resources and images..., but it looks like this is the same as writing the .rc file yourself.
在我的程序中,我具有以下资源:
In my program I have this resource include:
{$R *.rc}
在我的程序中
procedure TForm1.FormCreate(Sender: TObject);
var
SL: TStringList;
ResStream: TResourceStream;
begin
SL := TStringList.Create;
try
ResStream := TResourceStream.Create(hInstance, 'RC_keywords', RT_RCDATA);
SL.LoadFromStream(ResStream);
//
// do a lot of useful stuff here
//
finally
SL.Free;
end;
这是怎么了?
推荐答案
正如David所说,编译器不能直接使用 .rc
脚本,必须将其编译为 .res.
文件.
As David says, the compiler can not use the .rc
script directly, it must be compiled into a .res
file.
我刚刚创建了一个简单的文本文件 keywords.txt
.然后,我在Delphi IDE中创建了另一个文本文件,其内容与您的文本相同,称为 keywords.rc
.
I just created a simple text file, keywords.txt
. Then I created another text file, with the same content as yours, called keywords.rc
, all in the Delphi IDE.
保存完两个文件后,我单击菜单 Project
-> Add to Project ...
,然后将 keywords.rc
添加到项目中.在 .dpr
中,该行
After saving both, I clicked menu Project
-> Add to Project...
and added keywords.rc
to the project. In the .dpr
, the line
{$R 'keywords.res' 'keywords.rc'}
编译项目后,便会添加
并创建 .res
文件.
was added and the .res
file created as soon as I compiled the project.
这篇关于文本资源无法编译到我的Delphi exe中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!