unit ThreadDummy;
interface
uses
SysUtils, Classes;
type
TThreadDummy =
class(TThread)
private
{ Private-Deklarationen }
FFileCount: Integer;
FFileIndex: Integer;
FFileName:
string;
FLine:
string;
procedure GetFileCount;
procedure GetFileName;
procedure Listbox2Add;
procedure Listbox3Add;
procedure Split(
const aParam1:
string;
const aParam2:
string;
const aParam3: TStrings);
protected
procedure Execute;
override;
end;
implementation
{ Wichtig: Methoden und Eigenschaften von Objekten in visuellen Komponenten dürfen
nur in einer Methode namens Synchronize aufgerufen werden, z.B.
Synchronize(UpdateCaption);
und UpdateCaption könnte folgendermaßen aussehen:
procedure TThreadDummy.UpdateCaption;
begin
Form1.Caption := 'Aktualisiert in einem Thread';
end; }
uses
FormStart;
{ TThreadDummy }
procedure TThreadDummy.Execute;
var
files, lines: Integer;
data, datanormsatz: TStringList;
begin
{ Thread-Code hier einfügen }
data :=
nil;
datanormsatz :=
nil;
try
data := TStringList.Create;
datanormsatz := TStringList.Create;
Synchronize(GetFileCount);
for files := 0
to FFileCount
do begin
Synchronize(Form1.ListBox1.Clear);
Synchronize(Form1.ListBox2.Clear);
FFileIndex := files;
Synchronize(GetFileName);
data.LoadFromFile('
Path' + FFileName);
for lines := 0
to data.Count - 1
do begin
datanormsatz.Clear;
FLine := data[lines];
Split('
;', FLine, datanormsatz);
if datanormsatz[0] = '
A'
then
Synchronize(Listbox3Add);
if datanormsatz[0] = '
T'
then
Synchronize(Listbox2Add);
end;
end;
finally
FreeAndNil(data);
FreeAndNil(datanormsatz);
end;
end;
procedure TThreadDummy.GetFileCount;
begin
FFileCount := Form1.ListBox4.Count;
end;
procedure TThreadDummy.GetFileName;
begin
FFileName := Form1.ListBox1.Items[FFileIndex];
end;
procedure TThreadDummy.Listbox2Add;
begin
Form1.ListBox2.Items.Add(FLine);
end;
procedure TThreadDummy.Listbox3Add;
begin
Form1.ListBox3.Items.Add(FLine);
end;
procedure TThreadDummy.Split(
const aParam1:
string;
const aParam2:
string;
const aParam3: TStrings);
begin
// Do split
end;