0

When I start a program in the IDE, I use the following code to generate a log file. All of the paths are correct, checked with F8, but the log file is not output.

When I run the executable outside of the IDE, the log file is output properly.

Is there a setting somewhere in XE7 that prohibits this?

procedure LogProgram(const aEvent: String);
var
  TheLogFileName, TheLogLine: String;
  TheLogFile: TextFile;
  TheDay, TheMonth, TheYear, TheHour, TheMinute, TheSecond,
    TheMilliSecond: Word;
begin
  TheLogFileName := Format('%s%d.log', [usPATH_LOGS, Trunc(Now)]);
  AssignFile(TheLogFile, TheLogFileName);
  if not FileExists(TheLogFileName) then
    Rewrite(TheLogFile);
  Append(TheLogFile);
  DecodeDateTime(Now, TheYear, TheMonth, TheDay, TheHour, TheMinute, TheSecond,
    TheMilliSecond);
  TheLogLine := Format('%d-%d-%d: %d:%d:%d:%d%s%s', [TheYear, TheMonth, TheDay,
    TheHour, TheMinute, TheSecond, TheMilliSecond, #9, aEvent]);
  Writeln(TheLogFile, TheLogLine);
  CloseFile(TheLogFile);
end;

I tried to output a file, using the above code, while a program was running in the Delphi XE7 IDE, expected a log (text) file and got no output. Running the same program outside of the IDE generates the log (text) file properly.

@fpiette I checked Windows Security and folder protection is not active.

@Andreas-Rejbrand I'm using relative paths. Paths are being calculated relative to the path of the executable

@SilverWarior I did not change anything in Delphi through menu Run->Parameters. There are no paths listed there.

6
  • Check in Windows Security if folder protection is active (If it is you received a notification when the application or IDE attempted to write to the location). Commented Nov 26, 2022 at 12:57
  • 1
    Are you using absolute paths? Commented Nov 26, 2022 at 13:10
  • There should be no difference unless you changed startup parameters for your application in Delphi through menu Run->Parameters. Commented Nov 26, 2022 at 15:36
  • @SilverWarior that setting only applies if the code is using a relative file path. Commented Nov 26, 2022 at 20:25
  • "Paths are being calculated relative to the path of the executable" not true. It's relative to the working directory. Commented Nov 27, 2022 at 7:16

1 Answer 1

0

I did a global search (on my computer) for the name of the file, I was trying to create and discovered it in a containment folder (c:\VTRoot) managed by Comodo antivirus.

It turned out that if Comodo thought the file being created was a security risk, it moved it to the containment area on C:\

I went to the Comodo dashboard and disabled Auto-Containment and now Delphi XE7 works as it should.

Sign up to request clarification or add additional context in comments.

7 Comments

That doesn't answer where the file was supposed to be created. Yet nobody knows if usPATH_LOGS is an absolute or relative path.
@AmigoJack - I answered that already above to Andreas-Rejbrand I'm using relative paths. Paths are being calculated relative to the path of the executable
But the actual destination is important, with actual examples. Have you seen the comment to your edit? You're mixing up relative and absolute, because if it's relative to your EXE then it's effectively absolute, because it can only be relative to the working directory, which is not bound to where your EXE resides.
You should have done that search long before you asked your question here, to determine if the file was being created in a location different than you expected. It's part of basic debugging in situations like you've described.
Thanks for all your help. I'm glad that everything for you is basic. Unfortunately some of us, like me, are not as proficient as you are and thus what may seem basic to you, is insurmountable to those of us with a LOT LESS EXPERIENCE than you have. I searched for an answer for 3 days before I approached this forum, probably because something basic to you was not basic to me. I'll leave this for you to read and I'll close my account, since I don't know anything basic I can't expect to get any help here. Thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.