I cannot replace ResourceStrings when my app uses GnuGetText

126 Views Asked by At

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?

0

There are 0 best solutions below