Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.060 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: TDictionary speichern

  Alt 25. Feb 2019, 12:30
Delphi-Quellcode:
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}


uses
  System.SysUtils,
  System.Classes,
  System.Generics.Collections;

procedure Main;
var
  KoschkesStrings: TDictionary<string, string>;
  I: Integer;
  Stream: TStream;
  Pair: TPair<string, string>;
  KoschkesData: string;
begin
  KoschkesStrings := TDictionary<string, string>.Create;
  try
    for I := 1 to 100 do
    begin
      KoschkesStrings.Add(I.ToString, (I * I).ToString);
    end;

    KoschkesData := '';
    for Pair in KoschkesStrings do
    begin
      KoschkesData := KoschkesData + Pair.Key + ':' + Pair.Value + sLineBreak;
    end;

    Stream := TStringStream.Create(KoschkesData);
    try
      Writeln((Stream as TStringStream).Datastring);
    finally
      Stream.Free;
    end;
  finally
    KoschkesStrings.Free;
  end;
end;

begin
  try
    Main;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
  Mit Zitat antworten Zitat