Click here to Skip to main content
15,851,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I have a question for delphi, Its annoying me because I keep getting I/0 errors, "File not found" its annoying and It wont stop

procedure TForm1.BtnSaveClick(Sender: TObject);
var
  F, E, Level: TextFile;
  sName, sSur, sEmail, sTelKid, sMom, sDad, sTelMom, sTelDad, sLs, sSchool, sSchoolTel, sSchoolEmail: String;
begin
  sName:=EdtName.text;
  sSur:=EdtSur.text;
  sEmail:=EdtEmail.text;
  sTelKid:=EdtTelKid.text;
  sTelMom:=EdtTelMom.text;
  sTelDad:=EdtTelDad.text;
  sSchool:=EdtSchool.Text;
  sSchoolTel:=EdtSchoolTel.Text;
  sSchoolEmail:=EdtSchoolEmail.Text;
  sMom:=EdtMum.Text;
  sDad:=EdtDad.Text;
  sLs:=ClevelS.Text;
  AssignFile(E, 'Config\list.txt');
  append(E);
  Writeln(E,sName + ' ' + sSur);
  CloseFile(E);
  CBSearch.Items.LoadFromFile('Config\list.txt');
  CBSearch.Items.SaveToFile('Config\list.txt');
  AssignFile(F, 'Students\' +sName+ ' ' +sSur+ '.txt');
  Rewrite(F);
  WriteLn(F, '  ' +sSchool);
  WriteLn(F);
  WriteLn(F, '  Correo Electronico: ' +sSchoolEmail);
  WriteLn(F);
  WriteLn(F, '  Numero de telefono: ' +sSchoolTel);
  WriteLn(F);
  WriteLn(F, '_____________________________________________________________');
  WriteLn(F, '_____________________________________________________________');
  WriteLn(F);
  WriteLn(F, '  NOMBRE: ' +sName);
  WriteLn(F);
  WriteLn(F, '  APPELIDOS: ' +sSur);
  WriteLn(F);
  WriteLn(F, '  EMAIL: ' +sEmail);
  WriteLn(F);
  WriteLn(F, '  TELEFONO DE ESTUDIANTE: ' +sTelKid);
  WriteLn(F);
  WriteLn(F, '  TELEFONO DE '+sMom+' : ' +sTelMom);
  WriteLn(F);
  WriteLn(F, '  TELEFONO DE '+sDad+' : ' +sTelDad);
  WriteLn(F);
  Closefile(F);
  Assignfile(Level, 'Levels\' +sName+ ' ' +sSur+ '.txt');
  rewrite(Level);
______________________________________________________________________________________
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
crashes at this point
______________________________________________________________________________________

  WriteLn(Level,'NIVEL DE LENGUAJE: ' +sLs);
  CloseFile(Level);
  imgStudent.Picture.SaveToFile('Data\'+sName+' '+sSur+'.jpg');
end;


What I have tried:

I have tried appending it, rewriting it, resetting it, I have even tried indepent "Start/end;"'s , I am at my wits end right now... PLEASE HELP ME

If you are interested, This is the error message from the event log:

First chance exception at $777540F8. Exception class EInOutError with message 'Invalid filename'. Process Project1.exe (1060)
Posted
Updated 8-Sep-16 15:02pm
v2
Comments
[no name] 7-Sep-16 15:07pm    
Never mind. Nothing to see here.
Maciej Los 7-Sep-16 15:11pm    
rewrite is Delphi's built-in function ;)
[no name] 7-Sep-16 15:15pm    
I see, thanks.
Maciej Los 7-Sep-16 15:22pm    
You're welcome, friend ;)
Seems MattTelles's answer is the best solutioin for OP.
P.S.
I haven't seen you a lot of time on QA forum. I hope that you are fine.

Look at:

AssignFile(E, 'Config\list.txt');

Is there a "Config" subdirectory in the current directory in which the executable is running? I bet not.
 
Share this answer
 
Comments
Maciej Los 7-Sep-16 15:38pm    
5ed!
Crytach Daiguren 8-Sep-16 15:36pm    
Sorry mattTelles, I do infact have a folder called config, Its what stores the search library for my combobox.
Quote:
I keep getting I/0 errors, "File not found"
2 possibilities, either the file do not exists or you are not in the expected directory.
- You should display current directory path, just to make sure.
- Make sure Levels directory exist in current directory.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900