从资源(.res)文件加载文本 [英] Loading text from resource (.res) file

查看:56
本文介绍了从资源(.res)文件加载文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我找到了本教程,并按照它进行了学习.看到我只对从资源文件中加载文本感兴趣,因此我只使用了与所需内容相关的.可以从教程中找到代码,也可以找到

I found this tutorial a few days ago and I followed it. Seeing as I am only interested in loading text from the resource file, I only used the that was relevant to what I needed. The code can be found from the tutorial can be found here. Note: I am using code from the functions GetResourceAsPointer and GetResourceAsString. I have:

  • 创建了包含一个文本文件的资源文件.文本文件包含测试"
  • 包含了{$ R resource.res}

注意:我使用备忘录从资源中加载字符串.

Note: I use a memo to load the string from resource.

该程序能够编译,没有任何错误,但是当我单击按钮将字符串加载到备忘录中时,将加载字符串,但不会加载"test".取而代之的是,我得到了随机字符,例如正方形和汉字.

The program is able to compile without any errors but when I click the button to load the string into the memo, a string is loaded but not "test". Instead I get random characters such a squares and Chinese characters.

有人知道这个问题可能是什么吗?有人有过经历吗?

Does anyone know what the problem could be? Has anyone experience this before?

谢谢彼得

推荐答案

我使用以下两个例程,以便从添加到EXE的资源中获取文本:一个例程用于ANSI字符串,一个用于Unicode字符串.您的随机字符可能是由于读取的字符超过了所需的字符.

I use the following two routines in order to obtain text from resources added to the EXE: one routine is for ANSI strings and one for Unicode strings. Your random characters may be due to reading more characters than needed.

Function GetResString (i, lang: integer): string;
var
 buffer: array [0..400] of char;
 ls: integer;

begin
 result:= '';
 ls:= loadstring (hinstance, i + lang * 1000, buffer, sizeof (buffer));
 if ls <> 0 then result:= buffer
end;

function LoadResW (id, lang: integer): WideString;
const
 maxlength = 1024;

var
 ls: integer;

begin;
 setlength (result, maxlength);
 ls:= loadstringw (hinstance, lang * 1000 + id,
 pwidechar (result), length (result));
 if ls > 0
  then setlength (result, ls)
  else result:= ''
end;

这篇关于从资源(.res)文件加载文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆