Board index » delphi » Open text file

Open text file

delphi 4 send me an E/S 102 error on the reset instruction

if fileexists('param.00')=false then begin
           filecreate('param.00');
           assignfile(f_param,'param.00');
            reset(f_param);
end;

but when the file exists there is no error
#102 says that the reset has been done without assignfile ???

 

Re:Open text file


"vh" <t...@wanadoo.fr> skrev i en meddelelse news:8lpucb$1d9$1@wanadoo.fr...

Quote
> delphi 4 send me an E/S 102 error on the reset instruction
> if fileexists('param.00')=false then begin
>            filecreate('param.00');
>            assignfile(f_param,'param.00');
>             reset(f_param);
> end;

Why not read the help?

Quote:
"file management routines
function FileCreate(const FileName: string): Integer;
Note: Use of the non-native Pascal file handlers such as *FileCreate* is not
encouraged.
For normal file operations use AssignFile, *Rewrite*, and Reset instead."

Finn Tolderlund

Re:Open text file


instead of filecreate, do something like
assignfile(f,'whatever');
rewrite(f); closefile(f);
reset(f);

rewrite will always create a new empty file.

Quote
vh wrote:
> delphi 4 send me an E/S 102 error on the reset instruction

> if fileexists('param.00')=false then begin
>            filecreate('param.00');
>            assignfile(f_param,'param.00');
>             reset(f_param);
> end;

Re:Open text file


Quote
"vh" <t...@wanadoo.fr> wrote in message news:8lpucb$1d9$1@wanadoo.fr...
> delphi 4 send me an E/S 102 error on the reset instruction

> if fileexists('param.00')=false then begin
>            filecreate('param.00');

The above statement creates the file and opens a file handle to it. Since
you don't store the handle the file is going to be open for the rest of the
program's life.

Quote
>            assignfile(f_param,'param.00');
>             reset(f_param);
> end;

> but when the file exists there is no error
> #102 says that the reset has been done without assignfile ???

I suspect that what you probably want to do is something like

AssignFile (f_param, 'param.00');
if not FileExists ('param.00')
then Rewrite (f_param);
Reset (f_param);

Re:Open text file


You mean:

AssignFile (f_param, 'param.00');
if not FileExists('param.00') then
  Rewrite(f_param)
else
  Reset(f_param);

"Bruce Roberts" <no.junk.please....@attcanada.net> schreef in bericht
news:k_7g5.38016$qS3.77602@tor-nn1.netcom.ca...

Quote

> "vh" <t...@wanadoo.fr> wrote in message news:8lpucb$1d9$1@wanadoo.fr...
> > delphi 4 send me an E/S 102 error on the reset instruction

> > if fileexists('param.00')=false then begin
> >            filecreate('param.00');

> The above statement creates the file and opens a file handle to it. Since
> you don't store the handle the file is going to be open for the rest of
the
> program's life.

> >            assignfile(f_param,'param.00');
> >             reset(f_param);
> > end;

> > but when the file exists there is no error
> > #102 says that the reset has been done without assignfile ???

> I suspect that what you probably want to do is something like

> AssignFile (f_param, 'param.00');
> if not FileExists ('param.00')
> then Rewrite (f_param);
> Reset (f_param);

Re:Open text file


Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

news:8lrd1c$1it$1@porthos.nl.uu.net...

Quote
> You mean:

> AssignFile (f_param, 'param.00');
> if not FileExists('param.00') then
>   Rewrite(f_param)
> else
>   Reset(f_param);

No actually, I meant what I posted. By way of explanation: I have no idea if
Delphi is different but when I learned Pascal Rewrite openned a file for
writing only and any attempt to use it for input (e.g. EOF ()) would cause a
r/t error.

Quote

> "Bruce Roberts" <no.junk.please....@attcanada.net> schreef in bericht
> news:k_7g5.38016$qS3.77602@tor-nn1.netcom.ca...

> > "vh" <t...@wanadoo.fr> wrote in message news:8lpucb$1d9$1@wanadoo.fr...
> > > delphi 4 send me an E/S 102 error on the reset instruction

> > > if fileexists('param.00')=false then begin
> > >            filecreate('param.00');

> > The above statement creates the file and opens a file handle to it.
Since
> > you don't store the handle the file is going to be open for the rest of
> the
> > program's life.

> > >            assignfile(f_param,'param.00');
> > >             reset(f_param);
> > > end;

> > > but when the file exists there is no error
> > > #102 says that the reset has been done without assignfile ???

> > I suspect that what you probably want to do is something like

> > AssignFile (f_param, 'param.00');
> > if not FileExists ('param.00')
> > then Rewrite (f_param);
> > Reset (f_param);

Other Threads