#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    29
    Rep Power
    0

    Inserting (updating) row into .txt


    Hello fellas.

    I have a .txt file including currentdate,student's number, student's name and student's surname.

    I want to insert new rows to the .txt file.

    How could I insert new rows to the .txt file?
    For example, I have a list.txt file including rows:

    27.08.2012;4566;john;smith
    27.08.2012;6656;margaret;wilson
    28.08.2012;6455;kevin;duncan
    28.08.2012;4536;joe;bell

    I want to add three rows then it become

    27.08.2012;4566;john;smith
    27.08.2012;6656;margaret;wilson
    28.08.2012;6455;kevin;duncan
    28.08.2012;4536;joe;bell
    29.08.2012;3255;katerine;smith
    29.08.2012;5455;zoe;mell
    29.08.2012;3566;marie;spacey

    I am waiting for help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Can you clarify what features you need?
    Do you only need to extend the file as per your example or do you also need to insert
    new rows at various points in the file and/or do you need to edit the content (update) an existing row?

    Also, how big can the file get?
    This would determine the best approach.

    Clive
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    29
    Rep Power
    0
    I only need to insert new rows to the .txt file.

    The new rows will not be bigger than 10 rows.

    The new rows will be added to the end of the .txt file.

    The original content of the .txt file will not be change, will stay the same. The process will be just adding new rows.

    what does row mean?

    A row includes; date, student number, student name, student surname like

    30.08.2012;2345;john;smith



    Can you clarify what features you need?

    Do you only need to extend the file as per your example - yes
    or do you also need to insert
    new rows at various points in the file and/or do you need to edit the content (update) an existing row? -no

    Also, how big can the file get? - just couple of rows.
    This would determine the best approach.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Then the simplest thing would be to read the file into a TstringList and then simply add the rows you want using something like this:

    Code:
    function MakeNewRow: String
    begin
    // Whatever code you need to create the new row
    end;
    
    procedure Execute(fileName: string);
    var
      strList: TStringList;
    begin 
       strList := TStringList.Create;
       try
         strList.LoadFromFile(fileName);
         while ???? do begin
            stringlist.Add(MakeNewRow);
         end;
         strList.SaveToFile(fileName);
       finally
          strList.Free;
       end;
    end;
    Clive
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    29
    Rep Power
    0
    works perfectly.

    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo