Jump to content

Daniele

Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. Daniele

    Call procedure for write to file in TTASK

    I don't know either. AddLog is specifically used to log information when the application throws exceptions. I created a demo that calls cascade procedures and each of these creates its own task and inside I generate an exception to check if it is captured and written to the log. Everything worked both by declaring the procedures involved as public and private. Evidently there is something in my application that disturbs this mechanism. In my application I use iTask to be able to read information from the internet using Indy. The fact that my application now writes logs by simply declaring procedures as private instead of public sounds strange to me too. Unfortunately I can't investigate further at the moment but thanks for your interest.
  2. Daniele

    Call procedure for write to file in TTASK

    First of all, thank you again for the quick replies. For some reason in my code I had to move the addlog procedure declaration from public to private and now it works. Good work!
  3. Daniele

    Call procedure for write to file in TTASK

    Yes in debug I see going into the procedure and executing everything written without exceptions but it doesn't write anything to the file. I'll definitely follow your suggestion and write a clean, separate program to see what happens. Thanks very much anyway.
  4. Daniele

    Call procedure for write to file in TTASK

    Sorry but does my code work for you? Ok for ErrorData it is indeed redundant. But I'm very surprised that it works for you. I've tried and tried but I just have no way to make it work. Did you rewrite it? but oh well... Thanks anyway and best regards for the moment.
  5. Daniele

    Call procedure for write to file in TTASK

    Yes, I debugged it but no exceptions are triggered. If I call outside of TTask the procedure works correctly.
  6. 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?
×