About reset(aFile, FileNameString)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

About reset(aFile, FileNameString)

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: About reset(aFile, FileNameString)

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;


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

re: About reset(aFile, FileNameString)

David Emerson
In reply to this post by Lance Boyle
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.



 -------- Original Message --------

> From: "Lance Boyle" <[hidden email]>
> Sent: Tuesday, September 13, 2005 2:39 AM
> To: "FPC-Pascal users discussions" <[hidden email]>
> 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  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal 





_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: About reset(aFile, FileNameString)

Adriaan van Os-2
In reply to this post by Lance Boyle
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.

> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: About reset(aFile, FileNameString)

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

Lance


On Sep 13, 2005, at 8:02 PM, Adriaan van Os wrote:

> 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.

>
>
>> 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^)

>
> Regards,
>
> Adriaan van Os
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal