Board index » delphi » Sequential file problem

Sequential file problem

Hello,
I am trying to add to a sequential file or to create a new file (if one
doesn't exist).What is wrong with the following code?
 {open the file}
  AssignFile (OutputFile, 'C:\My Documents\student4.txt');
  try
    Append (OutputFile);
  except on EInOutError do{file not found}
    Rewrite(OutputFile);
  end;
  Writeln(OutputFile,edtStudent.Text);
  Writeln(OutputFile,lstCourse.Items[lstCourse.ItemIndex]);
  Writeln(OutputFile,edtMark.Text);
  CloseFile (OutputFile);
Your help would be appreciated.
Mark
 

Re:Sequential file problem


Might try:

  AssignFile (OutputFile, 'C:\My Documents\student4.txt');
  If fileexists( 'C:\My Documents\student4.txt') then
    Append (OutputFile)
  else
    Rewrite(OutputFile);

Quote
Mark wrote:
> Hello,
> I am trying to add to a sequential file or to create a new file (if one
> doesn't exist).What is wrong with the following code?
>  {open the file}
>   AssignFile (OutputFile, 'C:\My Documents\student4.txt');
>   try
>     Append (OutputFile);
>   except on EInOutError do{file not found}
>     Rewrite(OutputFile);
>   end;
>   Writeln(OutputFile,edtStudent.Text);
>   Writeln(OutputFile,lstCourse.Items[lstCourse.ItemIndex]);
>   Writeln(OutputFile,edtMark.Text);
>   CloseFile (OutputFile);
> Your help would be appreciated.
> Mark

Other Threads