本文介绍了Delphi 2010:无法找到资源 - EResNotFound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 根据此处的示例,这里和这里,我试图将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;interfaceuses 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-27 11:48