Text resource won't compile into my Delphi exe

∥☆過路亽.° 提交于 2019-12-11 14:44:06

问题


I use a list of words in my Delphi program, and until now I would place the list in the Lines property of a TMemo. I don't need the visual component, though, rather a TStringList, so now I want to do things the proper way by using a resource file for this, and load my TStringList from the resource. I tried applying the information from this answer, but I get an error:

[dcc32 Error] E2161 Error: RLINK32: Unsupported 16bit resource in file "D:\etc\Unit1.rc"

For good measure, I have this Unit1.rc file:

RC_keywords RCDATA "keywords.txt"

I created this in Project → Resources and images..., but it looks like this is the same as writing the .rc file yourself.

In my program I have this resource include:

{$R *.rc}

and in my procedure

procedure TForm1.FormCreate(Sender: TObject);
var
  SL: TStringList;
  ResStream: TResourceStream;
begin
  SL := TStringList.Create;
  try
    ResStream := TResourceStream.Create(hInstance, 'RC_keywords', RT_RCDATA);
    SL.LoadFromStream(ResStream);
    //
    // do a lot of useful stuff here
    //
  finally
    SL.Free;
  end;

What's wrong here?


回答1:


As David says, the compiler can not use the .rc script directly, it must be compiled into a .res file.

I just created a simple text file, keywords.txt. Then I created another text file, with the same content as yours, called keywords.rc, all in the Delphi IDE.

After saving both, I clicked menu Project -> Add to Project... and added keywords.rc to the project. In the .dpr, the line

{$R 'keywords.res' 'keywords.rc'}

was added and the .res file created as soon as I compiled the project.




回答2:


You are not compiling the resource script into a compiled resource. You have to compile the script, the .rc file, to a compiled resource, a .res file. Do that using the resource compiler brcc32. Then link the resource like this

{$R keywords.res}

Or get the compiler to invoke the resource compiler for you

{$R keywords.res keywords.rc}

I'm assuming a resource script name of keywords.rc which makes more sense to me that Unit1.rc.



来源:https://stackoverflow.com/questions/24803059/text-resource-wont-compile-into-my-delphi-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!