Reading a stringlist from a resource file

I'm using Delphi XE Starter. I've created a CCs.RC file and added that file to the project. A typical line in my CCs.RC file looks like this:

Danish1cc Text Danish1.cc

Directly after an Implementation line I've added

{$R CCs}

When I try to read this file into an existing stringlist, I get an [EResNotFound][1] error message. Here's the code I've used to try and read the file:

procedure LoadStringListFromResource(const ResName: string;SL : TStringList);
var
  RS: TResourceStream;
begin
  RS := TResourceStream.Create(HInstance, ResName, RT_RCDATA);
  try
    SL.LoadFromStream(RS);
  finally
    RS.Free;
  end;
end;
///
LoadStringListFromResource('Danish1cc',MySL)

My goal is to embed the file in my EXE and of course be able to read it :) Thank you for any help.

Answers


Your resource's type doesn't match. In your *.RC file you use TEXT whereas in your code you use RCDATA. You must either change your *.RC file to

Danish1cc RCDATA Danish1.cc

Or you must change

RS := TResourceStream.Create(HInstance, ResName, RT_RCDATA);

to

RS := TResourceStream.Create(HInstance, ResName, 'Text');

Need Your Help

Fixing merge conflicts?

git merge git-merge

I have two remote branches, "grape" and "master". I'm currently on "grape".

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.