unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils, System.Variants, System.Classes, System.Generics.Collections, System.Generics.Defaults,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FDictionary: TDictionary<
string,
string>;
procedure ReadFile;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
FDictionary := TDictionary<
string,
string>.Create;
ReadFile;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FDictionary.Free;
end;
procedure TForm1.ReadFile;
var
I: Integer;
Content: TStringList;
TextStream: TResourceStream;
CurrentRowKey:
string;
CurrentRowValue:
string;
begin
FDictionary.Clear;
Content := TStringList.Create;
try
TextStream := TResourceStream.Create(HInstance, '
Content', PWideChar('
ContentFile'));
try
Content.LoadFromStream(TextStream);
for I := 0
to Content.Count - 1
do
begin
CurrentRowKey := Copy(Content[I], 1, 6);
if not FDictionary.TryGetValue(CurrentRowKey, CurrentRowValue)
then
begin // einfügen
CurrentRowValue := Copy(Content[I], 8, Length(Content[I]) + 8);
FDictionary.Add(CurrentRowKey, CurrentRowValue);
end
else
begin // Key zusammensetzen bei Duplikaten
CurrentRowValue := Copy(Content[I], 8, Length(Content[I]) + 8);
FDictionary.AddOrSetValue(CurrentRowKey, FDictionary.Items[CurrentRowKey] + '
; ' + CurrentRowValue);
end;
end;
finally
TextStream.Free;
end;
finally
Content.Free;
end;
end;
end.