Ok to use VirtualProtect to change resource in Delphi?

Posted by user257188 on Stack Overflow See other posts from Stack Overflow or by user257188
Published on 2010-02-09T14:22:17Z Indexed on 2010/03/16 16:31 UTC
Read the original article Hit count: 334

Filed under:

I'm working on a simple localization effort in D2010. I'm handling all strings on forms because ETM seems like overkill for my needs, as did other 3rd party tools... (although I'm not so sure at this point!)

Is the code below for changing the Const.pas strings considered safe to change the button labels on standard message boxes?

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;

const
  NewOK: PChar = 'New Ok';
  NewCancel: PChar = 'New Cancel';

Procedure TForm.FormCreate;
begin
  HookResourceString(@SMsgDlgOK, NewOK);
  HookResourceString(@SMsgDlgCancel, NewCancel);     
end;

© Stack Overflow or respective owner

Related posts about delphi