If you want have your result as a PChar, you need to allocate the correct amount of heap memory for result.
The error you make is having it only point to another value, not copy, inside the function. Every variable that is local will disappear.
That value is stack memory and will disappear on function exit: BOOOOM.
Guaranteed SIGSEV. A PChar is a pointer type, not a value type, hence the P.