×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

File I/O error 6 while reading an empty File of Record

File I/O error 6 while reading an empty File of Record

File I/O error 6 while reading an empty File of Record

(OP)
For the record, I'm not very experienced in programming in general and with Delphi in particular; hence the poor practice of using goto's, so please be gentle .

I have a program that, upon loading, checks to see whether a certain file exists.  If it does not exist, an empty one is created; if it does exist, it should be loaded into the program.

The creation of the empty file seems to work; however, when the program loads and tries to read that empty file, I get an I/O Error 106.  

If it is important, the file is a typed file for records; the records will contain three strings each.

Here is the code for the offending procedure; I have marked off the area that is causing the area.  I have tested it thoroughly to ensure that this is indeed the spot that is causing trouble.

The error-producing section is toward the bottom of the procedure.

*********************************************************
procedure Tform_main.FormCreate(Sender: TObject);
var   tmpServer : ServerInfo;

label assignPaths;
label noPaths;
label createEmptyServerList;
label reloadServerList;
label dealwithServerList;

begin
  if (FileExists('paths.txt'))
  then goto assignPaths
  else goto noPaths;

  assignPaths:
  begin
    //loads paths.txt into variables for use
    AssignFile(pathsFile,'paths.txt');
    Reset(pathsFile);
    ReadLn(pathsFile,Unit4.clientPath);
    ReadLn(pathsFile,Unit4.sclientinfoPath);
    CloseFile(pathsFile);
    goto dealwithServerList;
  end;
  Exit;

  noPaths:
  begin
    self.btn_AddServer.Enabled := false;
    self.btn_RemoveServer.Enabled := false;
    self.btn_Go.Enabled := false;
    goto dealwithServerList;
  end;
  Exit;

  dealwithServerList:
    if (FileExists('servers.dat') = false)
    then goto createEmptyServerList
    else goto reloadServerList;

    createEmptyServerList:
      begin
        AssignFile(ServerList,'servers.dat');
        ReWrite(ServerList);
        CloseFile(ServerList);
      end;
      Exit;

//*****************************************
// THIS SECTION HAS PROBLEMS - ERROR 106  *
// ERROR 106 Invalid numeric format       *
//*****************************************

    reloadServerList:
      begin
        ShowMessage('Reloading old Server List');
        AssignFile(ServerList,'servers.dat');

        while not EOF do
        begin
          Reset(ServerList);
          Read(ServerList,tmpServer);
        end;
        CloseFile(ServerList);
      end;
      Exit;


end; //end of procedure

RE: File I/O error 6 while reading an empty File of Record

try this :

CODE

 reloadServerList:
      begin
        ShowMessage('Reloading old Server List');
        AssignFile(ServerList,'servers.dat');
        Reset(ServerList);
        while not ServerList.EOF do
        begin
          Read(ServerList,tmpServer);
        end;
        CloseFile(ServerList);
      end;

--------------------------------------
 What You See Is What You Get

RE: File I/O error 6 while reading an empty File of Record

(OP)
Thank you for the quick response; however, that gives me a compile error:

[Error] Unit1.pas(241): Record, object or class type required

To clarify:
ServerInfo is the name of the record type.
ServerList is a File of ServerInfo.


For the record, I am using Delphi 7.

RE: File I/O error 6 while reading an empty File of Record

Try

While Not EOF(ServerList) Do

Hope this helps

RE: File I/O error 6 while reading an empty File of Record

jups correct earthandfire, sorry for that.

glacialfury, if you're using D7, look into the use of Tfilestream or even TstringList (and use the LoadFromFile method)

cheers

--------------------------------------
 What You See Is What You Get

RE: File I/O error 6 while reading an empty File of Record

(OP)
Thank you very much, earthandfire and whosrdaddy.  It does not give me the error any more.  Now I have a couple of access violations from some other code to figure out, but you got my big puzzler out of the way.    

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close