Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#13

AW: Innere Struktur von TStrings / TMemo

  Alt 27. Mär 2015, 22:56
@ #10

Also ich erkenne auf dem Weg zum Speicher keine Änderung an dem String. Zu beachten ist auch, dass der String stets als Konstante übergeben wird.
Delphi-Quellcode:
function TStringList.Add(const S: string): Integer;
begin
  Result := AddObject(S, nil);
end;

function TStringList.AddObject(const S: string; AObject: TObject): Integer;
begin
  if not Sorted then
    Result := FCount
  else
    if Find(S, Result) then
      case Duplicates of
        dupIgnore: Exit;
        dupError: Error(@SDuplicateString, 0);
      end;
  InsertItem(Result, S, AObject);
end;

procedure TStringList.InsertItem(Index: Integer; const S: string; AObject: TObject);
begin
  Changing;
  if FCount = FCapacity then Grow;
  if Index < FCount then
    System.Move(FList^[Index], FList^[Index + 1],
      (FCount - Index) * SizeOf(TStringItem));
  with FList^[Index] do
  begin
    Pointer(FString) := nil;
    FObject := AObject;
    FString := S;
  end;
  Inc(FCount);
  Changed;
end;

function TStringList.Find(const S: string; var Index: Integer): Boolean;
...
  Mit Zitat antworten Zitat