Hello,
I am faced with a problem that I can not solve:
when I use this source code (without SetLength), I get the message:
StrUtils.pas(130,8) Fatal: Unknown compilerproc "fpc_ansistr_unique". Check if you use the correct run time library.
Fatal: Compilation aborted
procedure fpc_ansistr_unique(var s: AnsiString); compilerproc;
var
pSrc, pDst: PChar;
len: LongInt;
refCountPtr: PLongInt;
newMem: Pointer;
begin
if Pointer(s) = nil then
Exit;
// RefCount-Adresse berechnen
refCountPtr := PLongInt(Pointer(s) - 8);
len := PLongInt(Pointer(s) - 4)^;
// Nur bei mehrfacher Referenz kopieren
if refCountPtr^ > 1 then
begin
// Neuen Speicherblock mit Header (8 Byte) + Inhalt + Nullterminierung
GetMem(newMem, 8 + len + 1);
// RefCount = 1
PLongInt(newMem)^ := 1;
// Länge übernehmen
PLongInt(Pointer(newMem) + 4)^ := len;
// Daten kopieren
pSrc := PChar(s);
pDst := PChar(Pointer(newMem) + 8);
Move(pSrc^, pDst^, len);
pDst[len] := #0;
// Alten RefCount dekrementieren
Dec(refCountPtr^);
// neuen Zeiger setzen
Pointer(s) := PChar(Pointer(newMem) + 8);
end;
end;
procedure fpc_ansistr_setlength(var s: AnsiString; newlen: SizeInt); compilerproc;
var
tmp: AnsiString;
i: Integer;
begin
tmp := StrPas('');
if Length(s) < newlen then
begin
for i := 1 to newlen do
tmp[i] := s[i]; // <-- in this line, the compiler need fpc_ansistr_unique
end else
begin
for i := Length(s) to newlen do
tmp[i] := s[i];
end;
s := tmp;
end;