title: Modifying or deleting a line from a text file the low-level way?
body: <p>I'm working with a Text File in Delphi, and I don't wish to use the method of loading/saving with a string list. I intend to maintain an open filestream where I read and write my data there, keeping massive amounts of data on the hard disk instead of in the memory. I have the simple concept of writing new lines to a text file and reading them, but when it comes to modifying and deleting them, I cannot find any good resources.</p>
  
  <p>Each line in this file contains a name, and equals sign, and the rest is data. For example, <code>SOMEUNIQUENAME=SomeStringValue</code>. I intend to keep a file open for a period of time inside of a thread. This thread performs incoming requests to either get, set, or delete certain fields of data. I use <code>WriteLn</code> and <code>ReadLn</code> in a loop, evaluating <code>EOF</code>. Below is an example of how I read the data:</p>
  
  <pre><code>FFile = TextFile;
  
  ...
  
  function TFileWrapper.ReadData(const Name: String): String;
  var
    S: String; //Temporary line to be parsed
    N: String; //Temporary name of field
  begin
    Result:= '';
    Reset(FFile);
    while not EOF(FFile) do begin
      ReadLn(FFile, S);
      N:= UpperCase(Copy(S, 1, Pos('=', S)-1));
      if N = UpperCase(Name) then begin
        Delete(S, 1, Pos('=', S));
        Result:= S;
        Break;
      end;
    end;
  end;
  </code></pre>
  
  <p>...and then I trigger an event which informs sender of result. The requests are inside of a queue, which is sort of a message pump for these requests. The thread simply processes the next request in the queue repeatedly, similar to how typical applications work.</p>
  
  <p>I have procedures ready to be able to write and delete these fields, but I don't know what I have to do to actually perform the action on the file.</p>
  
  <pre><code>procedure TFileWrapper.WriteData(const Name, Value: String);
  var
    S: String; //Temporary line to be parsed
    N: String; //Temporary name of field
  begin
    Result:= '';
    Reset(FFile);
    while not EOF(FFile) do begin
      ReadLn(FFile, S);
      N:= UpperCase(Copy(S, 1, Pos('=', S)-1));
      if N = UpperCase(Name) then begin
        //How to re-write this line?
        Break;
      end;
    end;
  end;
  
  procedure TFileWrapper.DeleteData(const Name: String);
  var
    S: String; //Temporary line to be parsed
    N: String; //Temporary name of field
  begin
    Result:= '';
    Reset(FFile);
    while not EOF(FFile) do begin
      ReadLn(FFile, S);
      N:= UpperCase(Copy(S, 1, Pos('=', S)-1));
      if N = UpperCase(Name) then begin
        //How to delete this line?
        Break;
      end;
    end;
  end;
  </code></pre>
  
  <p>In the end, I need to avoid loading the entire file into the memory to be able to accomplish this.</p>