Hi Experts,
Delphi app using an Access db.
Trying to archive deleted records to a text file before deletion.
(I'm testing this from a form button currently, but would integrate it in to the delete records procedure when working, so that it saves text file before deleting.)
Writing a new file (SaveToFile) is no problem - but trying to append to it is!
rtwoolf gave me this code some weeks ago for another area where only new (overwritten) files are required.
I added in the code under '//new section' at the bottom to try and write if not existing, or append if existing.
The 'SaveToFile' line works fine - but the 'Append' line seems to do nothing - text file remains as before! (even if I comment out the other code leaving it as the only option)
Ideally, I would like to add a date/time stamp at the append point too if that's possible.
***********
procedure TFrameDeleteConts.DeletedT
extBtnClic
k(Sender: TObject);
var
ds : TDataSet;
i : integer;
linebuffer : string;
begin
// Produce text file ...........
ds := DBGrid1.DataSource.DataSet
;
//insert fields header into memo
linebuffer := '';
for i := 0 to ds.fieldcount - 1 do
begin
linebuffer := linebuffer + '"' + ds.FieldList[i].FieldName + '"';
if i < ds.fieldcount - 1 then linebuffer := linebuffer + ',';
end;
// Clear Test*******
memo1.clear;
memo1.Lines.append(linebuf
fer);
//insert all records
ds.first;
while ds.Eof = false do
begin
//insert all records into memo
linebuffer := '';
for i := 0 to ds.fieldcount - 1 do
begin
linebuffer := linebuffer + '"' + ds.fieldlist[i].AsString + '"';
if i < ds.fieldcount - 1 then linebuffer := linebuffer + ',';
end;
memo1.Lines.append(linebuf
fer);
ds.next;
end;
//New section
if SysUtils.FileExists('C:\No
25Data\Tex
t\No25Dele
ted.txt')=
true
then
// This is the problem line
Memo1.lines.Append('C:\No2
5Data\Text
\No25Delet
ed.txt')
else
Memo1.lines.SaveToFile('C:
\No25data\
Text\No25D
eleted.txt
');
end;
I'm a beginner with Delphi.
Have tried TextFile routines with AssignFile (then Rewrite and Append) but they didn't work either.
Thanks.
Start Free Trial