Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-09

About reset(aFile, FileNameString)

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lance Boyle

"Official" Pascal for opening a file and associating a name with it (e.g., a disk file) goes like this:

assign(aFile, FileNameString);
reset(aFile); {or rewrite, etc.}

All of the Pascals that I have used allowed the following shorthand, an extension:

reset(aFile, FileNameString); {or rewrite, etc.}

At least one of these Pascals was not a Macintosh Pascal, so I never considered it a "Mac" extension. Yet, I can find no possibility of this in FPC, in spite of its various compatibility modes.

I tried overloading reset() (newbie alert on the overloading thing) but it didn't work.

What say ye?

Lance

Jeff Pohlmeyer
All of the Pascals that I have used allowed the following shorthand, an extension: reset(aFile, FileNameString); {or rewrite, etc.} I tried overloading reset() ... but it didn't work.
procedure reset(var f:text; const fn:string);
begin
assign(f, fn);
system.reset(f);
end;
procedure reset(var f:file; const fn:string);
begin
assign(f, fn);
system.reset(f);
end;
David Emerson

I usually just make a wrapper function, and keep it in a utility unit with some other similarly useful stuff. Here's my code:

type reset_or_rewrite_enum_type = (resetit, rewriteit);
function open_file (var f : file; file_name : ansistring; whattodo : reset_or_rewrite_enum_type) : boolean;
	var
		io_result : integer;
	begin
		assign (f, file_name);
		if whattodo = resetit
			then {$I-} reset (f) {$I+}
			else {$I-} rewrite (f); {$I+}
		io_result := ioresult;
		if io_result = 0 then open_file := true
		else begin
			open_file := false;
			write ('Error: ');
			if whattodo = resetit
				then write ('Reset ')
				else write ('Rewrite ');
			writeln (file_name, ' returned ', io_result, ': ', error_description(io_result));
			end;
	end;
function reset_file (var f : file; file_name : ansistring) : boolean;
	begin
		reset_file := open_file (f, file_name, resetit);
	end;
function rewrite_file (var f : file; file_name : ansistring) : boolean;
	begin
		rewrite_file := open_file (f, file_name, rewriteit);
	end;

~David.

Earlier message 31 lines
-------- Original Message -------- > From: "Lance Boyle" > Sent: Tuesday, September 13, 2005 2:39 AM > To: "FPC-Pascal users discussions" > Subject: [fpc-pascal] About reset(aFile, FileNameString) > > "Official" Pascal for opening a file and associating a name with it > (e.g., a disk file) goes like this: > > assign(aFile, FileNameString); > reset(aFile); {or rewrite, etc.} > > All of the Pascals that I have used allowed the following shorthand, > an extension: > > reset(aFile, FileNameString); {or rewrite, etc.} > > At least one of these Pascals was not a Macintosh Pascal, so I never > considered it a "Mac" extension. Yet, I can find no possibility of > this in FPC, in spite of its various compatibility modes. > > I tried overloading reset() (newbie alert on the overloading thing) > but it didn't work. > > What say ye? > > Lance > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Adriaan van Os
to Lance Boyle: "Official" Pascal for opening a file and associating a name with it (e.g., a disk file)…
Lance Boyle wrote 5 lines
"Official" Pascal for opening a file and associating a name with it (e.g., a disk file) goes like this: assign(aFile, FileNameString); reset(aFile); {or rewrite, etc.}

Assign is not "official" Pascal but a non-standard Turbo/Borland/Delphi Pascal extension.

All of the Pascals that I have used allowed the following shorthand, an extension: reset(aFile, FileNameString); {or rewrite, etc.}

"FileNameString" also is a non-standard (non-ISO) Pascal extension ....

At least one of these Pascals was not a Macintosh Pascal, so I never considered it a "Mac" extension. Yet, I can find no possibility of this in FPC, in spite of its various compatibility modes.

... but indeed many Pascal compilers support it.

Regards,

Adriaan van Os

Lance Boyle
to Adriaan van Os

Thanks for the pointers 8^), y'all.

Lance

Adriaan van Os wrote 12 lines
Lance Boyle wrote: > "Official" Pascal for opening a file and associating a name with > it (e.g., a disk file) goes like this: > > assign(aFile, FileNameString); > reset(aFile); {or rewrite, etc.} > Assign is not "official" Pascal but a non-standard Turbo/Borland/ Delphi Pascal extension.

Thanks for the correction. I guess I never have used actual "Wirth" Pascal and had forgotten that even assign() is an extension.

Show quoted text 19 lines
> All of the Pascals that I have used allowed the following > shorthand, an extension: > > reset(aFile, FileNameString); {or rewrite, etc.} > "FileNameString" also is a non-standard (non-ISO) Pascal extension .... > At least one of these Pascals was not a Macintosh Pascal, so I > never considered it a "Mac" extension. Yet, I can find no > possibility of this in FPC, in spite of its various compatibility > modes. > ... but indeed many Pascal compilers support it.

Nice. 8^)

Show quoted text 9 lines
Regards, Adriaan van Os _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal