Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 728
bobonwhidbey Avatar asked Sep 08 '12 17:09

bobonwhidbey


1 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');
like image 141
Andreas Hausladen Avatar answered Nov 17 '22 13:11

Andreas Hausladen