I am making a simple multi device application for my android phone to help me log my hours at work. I have never programmed a MDA before and still a novice in programming. I cant seam to find out where to save the text file since regardless of how I refer to the file location, it cant find it.
I have also tried hardcoding the file creation prior to checking its existence.
here's my initial attempt at this problem.
// writes the days log to log.txt
procedure TForm1.btnlogClick(Sender: TObject);
var
tlog: textfile;
ihours: integer;
sact, sdate, slog: string;
begin
// gets data from user
ihours := strtoint(sbhours.text);
if rbCoach.ischecked then
begin
sact := 'Coaching';
end
else
sact := 'Umpiring';
sdate := datetostr(Calendar.date);
// assigns teh file and writes to it
if fileexists('logs.txt') = false then
begin
showmessage('Log File Does Not Exist!');
filecreate('logs.txt');
exit;
end;
assignfile(tlog, 'logs.txt');
reset(tlog);
slog := sdate + '#' + sact + '#' + inttostr(ihours);
writeln(tlog, slog);
closefile(tlog);
end;
// on startup it outputs current log to the memo
procedure TForm1.FormActivate(Sender: TObject);
var
tlog: textfile;
slog: string;
ihash: integer;
ihours: integer;
sact, sdate: string;
begin
// assigns file
if fileexists('logs.txt') = false then
begin
showmessage('Log File Does Not Exist!');
filecreate('logs.txt');
exit;
end;
assignfile(tlog, 'logs.txt');
reset(tlog);
// adds logs to memo
Memlog.lines.add('Date: Activity: Hours: ');
while NOT EOF(tlog) do
begin
readln(tlog, slog);
ihash := pos('#', slog);
sdate := copy(slog, 1, ihash);
delete(slog, 1, ihash);
ihash := pos('#', slog);
sact := copy(slog, 1, ihash);
delete(slog, 1, ihash);
ihash := pos('#', slog);
ihours := strtoint(copy(slog, 1, ihash));
delete(slog, 1, ihash);
// ('Date: Activity: Hours: ');
Memlog.lines.add(sdate + ' ' + sact + ' ' + inttostr(ihours));
end;
closefile(tlog);
end;