The syntax for your request does not exist.
However, you can use use-pointer arithmetic (if you are using a version that supports it), for example:
function RefCount(const s: string): Integer; begin if s <> '' then Result := (PInteger(s) - 2)^; else Result := 0; end;
A more robust approach is to use the StrRec record StrRec , which is what String really contains inside:
function RefCount(const s: string): Integer; begin if s <> '' then Result := (PStrRec(s) - 1)^.refCnt else Result := 0; end;
Or, an arithmetic version without a pointer:
function RefCount(const s: string): Integer; begin if s <> '' then Result := PStrRec(LongInt(s) - SizeOf(StrRec))^.refCnt else Result := 0; end;
BTW, starting with D2009 +, the System block has its own StringRefCount() function, which returns a row counter.
source share