Delphi 2010:无法找到资源 - EResNotFound [英] Delphi 2010: unable to find resource - EResNotFound
问题描述
根据此处的示例,这里和< a href =http://stackoverflow.com/questions/2087402/delphi-pre-build-event-not-executing-before-compile>这里,我试图将SVN修订信息包含在项目。 svn信息调用的结果存储在 rev.txt
(这是一个简单的ansi文件)。我的 revinfo.rc
如下所示:
Based on examples at for instance here, here, and here, I'm trying to include SVN revision info in a project. The result of a svn info call is stored in rev.txt
(it's a plain ansi file). My revinfo.rc
looks like this:
REV_TEXT TEXT rev.txt
我的项目如下所示:
unit rev;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{$R revinfo.res}
procedure TForm2.Button1Click(Sender: TObject);
var
RS : TResourceStream;
MyStr : AnsiString;
begin
RS := TResourceStream.Create(hInstance, 'REV_TEXT', RT_RCDATA);
SetLength(MyStr, RS.Size);
RS.Read(MyStr[1], RS.Size);
RS.Free;
Memo1.Text := MyStr;
end;
end.
项目编译,换句话说,资源文件本身由编译器(或perphaps它)是链接器?)。无论如何;当执行语句 TResourceStream.Create(hInstance,'REV_TEXT',RT_RCDATA);
时,我得到一个EResNotFound异常,抱怨它找不到资源REV_TEXT。我可以确认资源文件编译满意,包含 rev.txt
文本文件的内容。有没有人能够重现我的麻烦?
The project compiles, in other words, the resource file itself is located by the compiler (or perphaps it is the linker?). Anyway; when the statement TResourceStream.Create(hInstance, 'REV_TEXT', RT_RCDATA);
is executed, I get an EResNotFound exception, complaining it can't find resource REV_TEXT. I can confirm that the resource file is compiled satisfactory, containing the content of the rev.txt
text file. Are there anyone out there who're able to reproduce my troubles?
BTW:我也试图使用索引版本的TResourceStream构造函数,但我不知道使用哪个索引(尝试0,1和2无效)。
BTW: I've also tried to use the indexed version of the TResourceStream-constructor, but I don't know which index to use (tried 0, 1, and 2 to no avail).
我非常感谢您的帮助! :
I really appreciate your help! :)
推荐答案
代码中的问题是这样的:
The problem in your code is the line:
TResourceStream.Create(hInstance, 'REV_TEXT', RT_RCDATA);
您必须调用 TResourceStream.Create
相同类型的资源 TEXT
。
You must call the TResourceStream.Create
with the same type of the resource TEXT
.
以下代码应该可以工作:
The following code should work:
var
RS : TResourceStream;
MyStr : AnsiString;
begin
RS := TResourceStream.Create(hInstance, 'REV_TEXT', 'TEXT');
try
SetLength(MyStr, RS.Size);
RS.Read(MyStr[1], RS.Size);
finally
RS.Free;
end;
end;
这篇关于Delphi 2010:无法找到资源 - EResNotFound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!