Advertisement

05.01.2008 at 06:01PM PDT, ID: 23370515
[x]
Attachment Details

Delphi append to (memo1) text file

Asked by a3dvm in Delphi Programming, Delphi Components, Delphi Database

Tags: Delphi, Text Files, Append

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.DeletedTextBtnClick(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(linebuffer);
  //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(linebuffer);
    ds.next;
    end;
    //New section
   if SysUtils.FileExists('C:\No25Data\Text\No25Deleted.txt')=true
   then
   // This is the problem line
   Memo1.lines.Append('C:\No25Data\Text\No25Deleted.txt')
   else
   Memo1.lines.SaveToFile('C:\No25data\Text\No25Deleted.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
[+][-]05.01.2008 at 06:22PM PDT, ID: 21483980

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 06:42PM PDT, ID: 21484034

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 07:43PM PDT, ID: 21484265

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 08:29PM PDT, ID: 21484390

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Delphi Programming, Delphi Components, Delphi Database
Tags: Delphi, Text Files, Append
Sign Up Now!
Solution Provided By: TheRealLoki
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.02.2008 at 03:41AM PDT, ID: 21485643

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906