@TRon, thank you, I got it working.
You're welcome. Thank you for reporting back.
Coming from C, I find that there's quite a lot of overhead here... :'(
Actually using the old school object is the least overhead

Usually you use a class for that, and in case you are developing a gui application (Lazarus) then this is not a real problem because you already have a f.i. a form (to which you can add your ReplaceEsc method.
But... this is all related to how the/a object ( TRegExpr in this particular case ) implemented the callback. In this particular case it is a method but it could just as well have been a regular procedure or function (which would then not require the overhead of instantiating a class). To make matters even more complicated you could also use a static method of a class (which does not have to instantiated).
I hope I did not add more to the confusion (in case there was any to begin with ofc.)

edit: add example:
This is how confusion could look like:
program confucius;
{$mode objfpc}{$H+}
// class TMyClass
type
TCallbackMethod = procedure(x: integer) of object;
TCallbackProc = procedure(x: integer);
TMyClass = class
class procedure Callback(x: integer); static;
procedure AnotherCallBack(x: integer);
end;
class procedure TMyClass.Callback(x: integer);
begin
writeln(x);
end;
procedure TMyClass.AnotherCallback(x: integer);
begin
writeln(x);
end;
// old style object TMethods
type
TMethods = object
procedure callback(x: integer);
end;
procedure TMethods.Callback(x: integer);
begin
writeln(x);
end;
// regular procedure
procedure Callback(x: integer);
begin
writeln(x);
end;
procedure SomethingWithACallback(cbMethod: TCallBackMethod; cbProc: TCallbackProc);
begin
if assigned(cbMethod) then cbMethod(10);
if assigned(cbProc) then cbProc(11);
end;
var
Methods : TMethods;
MyClass : TMyClass;
begin
writeln(1);
SomethingWithACallback(@Methods.Callback ,@Callback);
writeln(2);
SomethingWithACallback(nil ,@TMyClass.Callback);
writeln(3);
MyClass := TMyClass.Create;
SomethingWithACallback(@MyClass.AnotherCallback ,nil);
MyClass.Free;
end.
And to make it even more fun, anonymous functions are in the makings
