I want to create and start a thread, all with one command line TClientCopyThread.Create(...)
. For this, I must create the thread with Suspended = False
, so that it can run immediately. I know that when I write a constructor
of a new object, first of all I must call the inherited Create
so that the instance of the object is created, and then do my initializations. But here, if I call inherited
the thread will start without initialized parameters. I try to call inherited
last and it seems it's working (I don't receive any access violation), but I don't know for sure if this is a coincidence or not.
TClientCopyThread = class(TThread)
private
OwnGUID: String;
SrcPath, DestPath: String;
Files: TFileNames;
RemoveIt: Boolean;
protected
procedure Execute; override;
public
constructor Create(const GUID, ASrcPath, ADestPath: String;
const FileNames: TFileNames; RemoveSrc: Boolean);
end;
constructor TClientCopyThread.Create(const GUID, ASrcPath, ADestPath: String;
const FileNames: TFileNames; RemoveSrc: Boolean);
var I: Integer;
begin
SrcPath:= Copy(ASrcPath, 1, Length(ASrcPath));
DestPath:= Copy(ADestPath, 1, Length(ADestPath));
SetLength(Files, Length(FileNames));
for I:= 0 to High(Files) do
Files[I]:= Copy(FileNames[I], 1, Length(FileNames[I]));
RemoveIt:= RemoveSrc;
FreeOnTerminate:= True;
inherited Create;
end;