0

I'm replacing some Delphi default ResourceStrings to localize those error messages. It works fine on a new blank application, this code raises an exception correctly translated:

implementation

uses System.SysConst;

procedure HookResourceString(rs: PResStringRec; newStr: PChar);
var
  oldprotect: DWORD;
begin
  VirtualProtect(rs, SizeOf(rs^), PAGE_EXECUTE_READWRITE, @oldProtect);
  rs^.Identifier := Integer(newStr);
  VirtualProtect(rs, SizeOf(rs^), oldProtect, @oldProtect);
end;

procedure TForm1.FormCreate(Sender: TObject);
var test: integer;
begin
  HookResourceString(@SInvalidInteger, '''%s'' no es un valor entero valido');
  test := StrToInt('test');  // We force an InvalidInteger error 
end;

The problem is that the moment I add gnuGetText to the uses of that blank application then it raises an "ERROR" exception, at ConvertErrorFmt of System.SysUtils instead of my translated exception. It fails exactly here:

procedure ConvertErrorFmt(ResString: PResStringRec; const Args: array of const); {$IFDEF ELF} local; {$ENDIF}
begin
  raise EConvertError.CreateResFmt(ResString, Args);
end;

I need gnuGetText to also localize the rest of my application, so what's the right way of translating Delphi's ResourceStrings when using gnuGetText?

3
  • Integer(newStr) is obviously wrong in a 64-bit application. Commented Mar 8, 2023 at 10:47
  • @AndreasRejbrand 32bits applications don't work correctly either. In a blank 32-bits application it works fine until I add gnuGetText to the uses. Same as in a blank 64-bits app, it translates the exceptions until you add gnuGetText. Replacing Integer(newStr) with Int64(newStr) doesn't make any difference. GnuGetText must do some changes in the way you access to the language resources. Commented Mar 8, 2023 at 11:06
  • 1
    gnugettext also hooks resource string handling. Just in case you didn't know. But I am not familiar enough with that code to give any advice. Commented Mar 8, 2023 at 12:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.