Hi
I'm trying to have a thread that will search in
WhereToSearch for specific files and copy them in drive
TargetDriveSo i create a susspended thread, pass my two parameters (thread properies) to it and start it.
Well, that's the idea...
The problem is that as soon as
tCopy.pathToSearch := WhereToSearch;is executed, the thread crushes...
What am i doing wrong? Can you help?
type
TCopyFilesThread = class(TThread)
private
FpathToSearch: string;
FdriveToCopy: string;
procedure ShowStatus;
procedure showFilesFound;
procedure setPathToSearch(const Value: String) ;
procedure setDriveToCopy(const Value: String) ;
protected
procedure Execute; override;
public
constructor Create(CreateSuspended : boolean);
property pathToSearch: String read FpathToSearch write setPathToSearch;
property driveToCopy: String read FdriveToCopy write setDriveToCopy;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.doit();
begin
tCopy.Create(True);
tCopy.pathToSearch := WhereToSearch;
tCopy.driveToCopy := TargetDrive;
tCopy.Start;
end;
{ TCopyFilesThread }
constructor TCopyFilesThread.Create(CreateSuspended : boolean);
begin
inherited Create(CreateSuspended);
// because this is black box in OOP and can reset inherited to the opposite again...
FreeOnTerminate := True; // better code...
end;
procedure TCopyFilesThread.setPathToSearch(const Value: String);
begin
FpathToSearch := Value;
end;
procedure TCopyFilesThread.setDriveToCopy(const Value: String);
begin
FdriveToCopy := Value;
end;