glacialfury
Programmer
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
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