如何将TXT文件作为资源添加到EXE文件? [英] How do I add a TXT file as resource to my EXE file?

查看:328
本文介绍了如何将TXT文件作为资源添加到EXE文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

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