如何将TXT文件作为资源添加到EXE文件? [英] How do I add a TXT file as resource to my EXE file?
问题描述
我有一个TXT文件,其中包含大约10,000行文本。我想在TMemo中显示这些行。
但是我不想将TXT文件分发给我的程序。如何使用 stringtable {}
将它作为资源WITHIUT集成到我的EXE文件中,因为这需要每行一个标识符(因此我必须添加10000个标识符)。 / p>
_
我有Delphi XE
我通常为这种资源创建一个 RC
文件(基本上是文本文件),然后添加类似
MyText RCDATA ..\资源\filename.txt
将每个文件/资源放入RC文件。如果RC文件是项目的一部分,它将被编译(到 res
)并链接到exe。要使用资源,我通常使用 TResourceStream
,即
var ResStream: TResourceStream;
ResStream:= TResourceStream.Create(hInstance, MyText,RT_RCDATA);
BTW,如果在IDE中创建RC文件时未将其自动添加到项目中,则像这样添加行
{$ R'myExtraRes.res''myExtraRes.RC'}
进入项目文件,紧随 uses
列表之后。
I have a TXT file containing about 10,000 lines of text. I want to display these lines in a TMemo.
But I don't want to distribute that TXT file my program. How do I integrate it into my EXE file as a resource WITHIUT using stringtable {}
because this requires an identifier for each line (so I will have to add 10000 identifiers).
_
I have Delphi XE
I usually create an RC
file (which is basically an text file) for this kind of resources, then add line like
MyText RCDATA ..\resources\filename.txt
for each file / resource into the RC file. If the RC file is part of the project it will be compiled (to res
) and linked into exe. To use the resource I usually use TResourceStream
, ie
var ResStream: TResourceStream;
ResStream := TResourceStream.Create(hInstance, 'MyText', RT_RCDATA);
BTW if the RC file wasn't added to the project automatically when you created it in the IDE then add line like
{$R 'myExtraRes.res' 'myExtraRes.RC'}
into the project file, right after the uses
list.
这篇关于如何将TXT文件作为资源添加到EXE文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!