I am trying to make "self-modifying" code, like the following example:
procedure TForm1.Button1Click(Sender: TObject);
P := Addr(TForm1.Button1Click);
ShowMessage('The address is: ' + IntToHex(Integer(P), 8));
P^ := 0; // <---- Access Violation occurs here
but the system reports:
Access violation at address 0042BBCA in module 'Project1.exe'
Write of address 0042BB6c
which is understandable, since this is not .DATA segment, but .CODE
What is API(s) for "unlocking" the CODE segment?