Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
Delphi 10.4 Sydney
|
AW: Move und FillChar bei strings.
8. Jun 2014, 23:27
Zuletzt hatte ich es so. Geht aber nicht. Bringt sogar gelegentlich EInavlidPointer AV.
Delphi-Quellcode:
function TMyStringList.Add( const Value: string): integer;
begin
Result := FCount;
Insert(Result, Value);
end;
function TMyStringList.MoveBytes( const Index: integer): integer;
var
I: integer;
begin
Result := 0;
for I := Index to FCount - 1 do
Result := Result + Length(FItems[I]) * SizeOf(Char);
end;
procedure TMyStringList.Insert( const Index: integer; const Value: string);
begin
if FCount = FCapacity then
Capacity := FCapacity + DeltaCapacity;
if Index < FCount then
begin
Move(FItems[ Index], FItems[ Index + 1], MoveBytes( Index));
// FillChar(FItems[Index], Length(FItems[Index]) * SizeOf(Char), 0);
Finalize(FItems[ Index]);
end;
FItems[ Index] := Value;
Inc(FCount);
end;
procedure TMyStringList.Delete( const Index: integer);
begin
if Index < FCount - 1 then
begin
Move(FItems[ Index + 1], FItems[ Index], MoveBytes( Index));
// FillChar(FItems[FCount - 1], Length(FItems[FCount - 1]) * SizeOf(Char), 0);
Finalize(FItems[FCount - 1]);
end;
FItems[FCount - 1] := ' ';
Dec(FCount);
end;
|
|
Zitat
|