Use PChar(sString) in Scripter

Why can't I use PChar(sString) within Scripter?

sString = 'MyText f‰ƒ€ÿ H¸Äÿÿÿÿÿÿÿ‰'
sString = 'MyText ш„Œÿ ‹EüƒÀ‰Eüë'
(After "MyText" there is a Asciicode #0, but the String is not terminated.)
Usually sString := PChar(sString) would fix this problem. In Delphi I can use this function, but not in TMS Scripter :frowning:

Even this did not work:

  Helper: PChar;
  Helper := sString;

Helper has the same problem, String is not terminated at the first occurence of #0

My temporary solution looks like this:

function PChar(sString: string);
  x: integer;
  for x := 1 to Length(sString) do begin
    if sString[x] = #0 then break;
  Result := Copy(sString, 1, x-1);

This basically solves my problem but needs CPU time because I have to iterate through every string.

Scripter is not type safe, so there is no type cast. Casting to PChar does nothing.
One workaround is that you register a Delphi function in script, named PChar (or `ToPChar to avoid any confusion) and then do it from Delphi, casting it to PChar and returning the correct string to scripter.