Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange File Problem

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
I have this code in one of my apps and it generates a 103 (file not open) on the seek line

Filename := Concat(Datadir,GSDef.StatSets.Name,'.s30');
If FileExists(Filename) then
begin
AssignFile(FileS30, Filename);
Reset(FileS30);
For k := 1 to FileSize(FileS30)-1 do
begin
Seek(FileS30, k);

Surely by the time it gets there, the file has to be open?
 
Do you close the file at the end? I think this can happen if the file is still open from the last time. Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Is the file read-only? If you have copied it from a CD it probably will be. The Reset command will try to open the file for read and write purpose. Steven van Els
SAvanEls@cq-link.sr
 
The file is closed after processing (if it would get past the seek). I've shutdown and restarted my computer since I posted and it still gave me a 103 at that line, so I don't think it's a problem with the file being open.
 
When you made your original post, did you copy and paste your code or did you re-type it? I can re-create an error 103 when I mis-type the file variable name in the Seek function. E.g., FileS3O (ess-three-oh) instead of FileS30 (ess-three-zero).
 
They are all zeros, I retyped them in my app to make sure and it still gave the error.

btw, here's the code without the italics, slightly easier to read (damn parser):

Filename := Concat(Datadir,GSDef.StatSets.Name,'.s30');
If FileExists(Filename) then
begin
AssignFile(FileS30, Filename);
Reset(FileS30);
For k := 1 to FileSize(FileS30)-1 do
begin
Seek(FileS30, k);
 
Can you open the file in windows explorer? We ran into a situation where virus software had quarantined some files, and would not let us in. We've also run into stuff on the network where the file exists, but we do not have rights to it. Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Yeah, the file opens in Explorer and I have rights to it. I've tried this on two computers and it gives the same on both. If I add a reset just after the

For k := 1 to FileSize(FileS30)-1 do
begin

it works perfectly. Before that line, it'll tell me the file size:

ShowMessage(IntToStr(FileSize(FileS30)));

But afterwards it seems to have closed it. I have tried changing the FileSize(FileS30)-1 to a straight number, but that doesn't work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top