Do not use on any
shared computer
August 29, 2008 02:59pm pdt
 
[x]
Attachment Details

Delphi append to (memo1) text file

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 your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: a3dvm
Solution Provided By: TheRealLoki
Participating Experts: 2
Solution Grade: A
Views: 122
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by TheRealLoki

Rank: Wizard

Expert Comment by TheRealLoki:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by reynaldio
Expert Comment by reynaldio:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by a3dvm
Author Comment by a3dvm:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by TheRealLoki

Rank: Wizard

Accepted Solution by TheRealLoki:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by a3dvm
Author Comment by a3dvm:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_EXPERT_20070906