In Delphi XE7 when running a program in the IDE cannot create a log file, but it works when I run the created exe

221 Views Asked by At

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.

1

There are 1 best solutions below

7
Emile Verkerk On

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.