Reading a string list from a resource file

I am using Delphi XE Starter. I created the CCs.RC file and added this file to the project. A typical line in my CCs.RC file is as follows:

Danish1cc Text Danish1.cc

Immediately after the implementation line, I added

{$R CCs}

When I try to read this file in an existing string list, I get an error [EResNotFound][1]. Here is the code I 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 insert the file into the EXE and, of course, read it :) Thanks for any help.

+5
source share
2 answers

Resource type does not match. In the * .RC file you use TEXT, while in your code you use RCDATA. You must either change the * .RC file to

Danish1cc RCDATA Danish1.cc

Or you have to change

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

to

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

, - {$R CCs}

, CCs.res?

, {$R CCs.res}

0

All Articles