Re: No errors for AssignFile ?
From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 11/12/04
- Next message: Bruce Roberts: "Re: very large numbers delphi overflow .."
- Previous message: Bruce Roberts: "Re: Answer to why low and high are bad !"
- Maybe in reply to: Skybuck Flying: "Re: No errors for AssignFile ?"
- Next in thread: Skybuck Flying: "Re: No errors for AssignFile ?"
- Reply: Skybuck Flying: "Re: No errors for AssignFile ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 12 Nov 2004 11:45:13 -0500
"Skybuck Flying" <nospam@hotmail.com> wrote in message
news:cn0ft1$c7a$1@news5.zwoll1.ov.home.nl...
> If I run this code it simply returns and no errors happen ??
>
> AssignFile( F, '///\\$#^$#%^$#b23412ull***' );
> Let me guess the error probably happens when I call
>
> writeln( F, 'blablabla' );
You guessed wrong. The error happens on the Reset, Rewrite, or Append. The
help is a little misleading on this issue. AssignFile does nothing more than
initialize the internal data space used by the VCL/Library. Reset, Rewrite,
and Append are the routines that actually communicate with the o/s to open
the file.
> Ok I just tried it:
>
> AssignFile( F, '///\\$#^$#%^$#b23412ull***' );
> try
> WriteLn( F, 'blabla' ); // i/o 103
> except
>
> end;
>
> That's not so cool....
>
> What if I want to make sure that the file will exist ?
Well most people would take the time to read the help. In it they will find
out that one must open a file before attempting i/o on it. They will also
learn about $I-/+ and IOResult. And, if they spend just a little more time
in the help they will probably find the FileExists function.
If you spent as much time reading and understanding the Delphi help files as
you do litering this ng with junk posts, you just might learn something.
> I can't use FileExists... because the file doesn't exist yet...
>
> I want to create it...
>
> Maybe do a reset ?
Oh wow. Of course you want to use Reset. After all the help entry on the
procedure starts with "Reset opens the existing external file . . ."
obviously just what you want. I guess you've never tried to follow any see
also links.
> Write stuff/text to a textfile.
>
> But make sure the path/file is valid.
>
> If it is not valid given an error message ONCE
var errorIssued : boolean = false;
procedure WriteStuffToTextFile (theFilename : string; const stuff : string);
var f : textFile;
begin
if FileExists (theFilename)
then begin
AssignFile (f, theFilename);
Append (f);
Writeln (f, theStuff);
CloseFile (f);
end
else begin
if not errorIssued
then begin
MessageBox ('Skybuck flunks again.');
errorIssued := True;
end
else raise exception.Create ('Enough already. I already told you its
wrong.');
end;
end;
- Next message: Bruce Roberts: "Re: very large numbers delphi overflow .."
- Previous message: Bruce Roberts: "Re: Answer to why low and high are bad !"
- Maybe in reply to: Skybuck Flying: "Re: No errors for AssignFile ?"
- Next in thread: Skybuck Flying: "Re: No errors for AssignFile ?"
- Reply: Skybuck Flying: "Re: No errors for AssignFile ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]