Master BAW
2012-07-03 08:31:59
Hey, I made this, to put in my script for if something goes wrong.
If something goes wrong, I call this function, and enter the error into it, and then it will make a screenshot from it, and write the error into a file.
It fully works, except for the first time you run it, then it can't append the file after creating it… the second time , when the file is already created, it works though… Can somebody test it and explain me why it doesn't work the first time, and maybe help me to solve that?
This is my first time working with files, so please give me some hints :D
If you like this little Procedure, you may use it yourself :) It's also quite handy for a lot of other things that you want to log I think. It is a screenshot, plus the description of the screenshot, and it's saved in your script path .
example:
Cheers!
Edit: changed one line :)
If something goes wrong, I call this function, and enter the error into it, and then it will make a screenshot from it, and write the error into a file.
It fully works, except for the first time you run it, then it can't append the file after creating it… the second time , when the file is already created, it works though… Can somebody test it and explain me why it doesn't work the first time, and maybe help me to solve that?
This is my first time working with files, so please give me some hints :D
If you like this little Procedure, you may use it yourself :) It's also quite handy for a lot of other things that you want to log I think. It is a screenshot, plus the description of the screenshot, and it's saved in your script path .
Procedure BugLogScreen(Error: String);
var
i: integer;
theFile: Integer;
thePath: string;
DirectoryToSave : string;
begin
DirectoryToSave := 'BugsLogScreens\';
i := Length(GetFiles(ScriptPath+DirectoryToSave,'jpg'));
SaveScreenshot(ScriptPath + DirectoryToSave + 'SCR' + ToStr(i) + '.jpg');
if not DirectoryExists(ScriptPath + DirectoryToSave) then
begin
try
CreateDirectory(ScriptPath + DirectoryToSave);
writeln('Created Directory');
Wait(1000);
except
writeln('Failed to create directory!');
end;
end;
if not FileExists(ScriptPath + DirectoryToSave + 'BUGS.txt') then
begin
try
CreateFile(ScriptPath + DirectoryToSave + 'BUGS.txt');
Writeln('Created File');
Wait(1000);
except
writeln('Failed to create file!');
end;
end;
thePath := ScriptPath + DirectoryToSave + 'BUGS.txt';
try
theFile := AppendFile(thePath);
except
Writeln('Error opening file!');
end;
try
WriteFileString(theFile, IntToStr(i)+': (' + TheDate(Date_Day) + ' at ' + TheTime + ') ' + Error + #13 + #10);
except
Writeln('Error writing file');
end;
try
CloseFile(theFile); // Again, don't forget this!
except
Writeln('Error closing file');
end;
end;
example:
if Something() = GoneWrong then
BugLogScreen('SomeThing has gone wrong');Cheers!
Edit: changed one line :)