Hello! Is there a way to change a resource string in run-time?

Hello! Is there a way to change a resource string in run-time?
My case, I need to change the Dialog messages to another language.
Example: SMsgDlgYes = 'Oui';

Comments

  1. dxgettext and probably all other translation tools can do that.

    ReplyDelete
  2. I'm not vouching for it's quality, but we've been using the code below with no problems for many years. I can't recall where I found it online originally:

    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; { HookResourceString }

    HookResourceString(@SMsgDlgOK, PChar(OurNewString); {first arg is from CONSTS.PAS }

    ReplyDelete
  3. Tom Field I hope it works with FMX too

    ReplyDelete
  4. Magno Lima It should with FMX on Windows; it won't work on other platforms

    ReplyDelete

Post a Comment