String ExePath; // path
ExePath = ExtractFilePath (Application-> ExeName); // the current directory
ExePath = ExtractFilePath (ExcludeTrailingPathDelimiter (GetCurrentDir (); // The Directory address of the upper-level EXE program
WriteLog (); // use
. H
Void _ fastcall WriteLog (String AMsg );
. Cpp
// ----------------- Write the log file under the executable program directory -------------------------------
Void _ fastcall WriteLog (String AMsg ){
Static String LogFileName = ExePath + "log \ WebUpdata. log ";
Static String LogFile = ExePath + "log ";
If (! DirectoryExists (LogFile ))
{
CreateDir (LogFile); // create if the folder does not exist
}
TFileStream * Log;
Try {
If (! FileExists (LogFileName )){
Log = new TFileStream (LogFileName, fmCreate );
}
Else {
Log = new TFileStream (LogFileName, fmOpenWrite );
}
}
Catch (...){
Return;
}
Log-> Seek (0, soFromEnd );
AMsg = AMsg + "---->" + Now () + "\ r \ n ";
Log-> Write (AMsg. c_str (), AMsg. Length ());
Delete Log;
}
From an empty column