Reputation: 2110
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:
Note: I use a memo to load the string from resource.
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?
Thank you in advanced, Peter
Upvotes: 1
Views: 4173
Reputation: 6477
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;
Upvotes: 2
Reputation: 5134
In which encoding is text file that you put to resource? If ANSI, try save it as Unicode (GetResourceAsString
from article use PChar
type).
Upvotes: 1