Hello. I'm workin with Delphi 10.4.2 community in Windows 10/11.
I've this procedure
procedure TfrmMain.AddLog(NomeProc, PointProc, Datis: string; MarckEX: boolean);
var
ErrorLogFileName : string;
ErrorFile : TextFile;
markec : string;
begin
ErrorLogFileName := ExtractFilePath(ParamStr(0))+'error.log';
AssignFile(ErrorFile, ErrorLogFileName) ;
if FileExists(ErrorLogFileName) then
Append(ErrorFile)
else
Rewrite(ErrorFile) ;
try
if MarckEX then begin
markec := '***;';
end
else begin
markec := '---;'
end;
ErrorData := DateTimeToStr(Now) + ';' + NomeProc + ';' + PointProc + ';' + Datis + ';' + markec;
WriteLn(ErrorFile,ErrorData) ;
finally
CloseFile(ErrorFile)
end;
end;
And I've this Task (simple method to work in another thread) called in a button click
TASK := TTask.Create(
procedure
begin
//do some work and then.... call AddLog..
AddLog('Test','Test','Test',false);
end
);
TASK.Start();
If I call AddLog into TASK do not work. I tried to call AddLog in and out to
TASK := TTask.Create(
procedure
begin
//do some work and then.... call AddLog..
TThread.Synchronize(nil,
procedure
begin
AddLog('Test','Test','Test',false);
end
);
end
);
TASK.Start();
but without success, nothing is ever written to the file. What am I doing wrong?