Hallo,
ich habe folgendes Problem: In meinder Synchronisations-Software nutze ich einen Thread zum Erstellen von Dateilisten mehrmals.
Wie kann ich es am besten bewerkstelligen, das meine Software solange wartet, bis alle Instanzen des Threads beendet sind?
Mein Thread ist wie folgt deklariert:
Delphi-Quellcode:
TFileListTh = class(TThread)
private
FSource: TStringList;
FDest: TStringList;
FSourceDir: string;
FDestDir: string;
FMode: Word;
procedure CreateSourceFileList;
procedure CreateDestFileList;
public
property Source: TStringList read FSource write FSource;
property Dest: TStringList read FDest write FDest;
property sSourceDir: string read FSourceDir write FSourceDir;
property sDestDir: string read FDestDir write FDestDir;
property nMode: Word read FMode write FMode;
destructor Destroy; override;
protected
procedure Execute; override;
constructor Create(CreateSuspended: Boolean);
end;
...
constructor TFileListTh.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FSource := TStringList.Create;
FDest := TStringList.Create;
end;
procedure TFileListTh.Execute;
begin
case FMode of
0: CreateSourceFileList;
1: CreateDestFileList;
end;
end;
procedure TFileListTh.CreateSourceFileList;
var
nCount: Integer;
begin
if (FSourceDir <> '') then
if AdvBuildFileList(IncludeTrailingPathDelimiter(FSourceDir) + '*.*',
faAnyFile or faDirectory, FSource, amAny, [flFullNames, flRecursive]) then
begin
for nCount := FSource.Count - 1 downto 0 do
if (Pos('\.', FSource.Strings[nCount]) > 0) then
FSource.Delete(nCount);
end;
FSource.Sort;
end;
procedure TFileListTh.CreateDestFileList;
var
nCount: Integer;
begin
if (FDestDir <> '') then
if AdvBuildFileList(IncludeTrailingPathDelimiter(FDestDir) + '*.*',
faAnyFile or faDirectory, FDest, amAny, [flFullNames, flRecursive]) then
begin
for nCount := FDest.Count - 1 downto 0 do
if (Pos('\.', FDest.Strings[nCount]) > 0) then
FDest.Delete(nCount);
end;
FDest.Sort;
end;
destructor TFileListTh.Destroy;
begin
FSource.Free;
FDest.Free;
inherited;
end;