这个函数的目的是是字符串的引用计数减1,如果引用计数为0了,就释放字符串。
procedure _LStrClr(var S);
{$IFDEF PUREPASCAL}
var
P: PStrRec;
begin
if Pointer(S) <> nil then
begin
P := Pointer(Integer(S) - Sizeof(StrRec));
Pointer(S) := nil;
if P.refCnt > 0 then
if InterlockedDecrement(P.refCnt) = 0 then
FreeMem(P);
end;
end;
//赋值函数
procedure _LStrLAsg(var dest; const source);
{$IFDEF PUREPASCAL}
var
P: Pointer;
begin
P := Pointer(source);
_LStrAddRef(P);//source的引用计数加1
P := Pointer(dest);
Pointer(dest) := Pointer(source);
_LStrClr(P);//dest的引用计数减1
end;