it won’t work as expected - testcase error.
You are trying to store 64bit Pointer into 32bit value.
as a result, value will be broken.
sessval:integer;
...
function createsession(str:string) :TUserSession;
...
function MyOwnFunction(Data: string): string;
var
us: TUserSession;
begin
// Do something with Data
us := TUserSession(sessval);
...
sessval := integer(createsession(''));