[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Extended Pascal treats files quite differently from Borland Pascal. GPC supports both forms, even in mixed ways, and provides many extensions.
@@ A lot missing here
function FileSize (FileName : String) : LongInt; var f: bindable file [0 .. MaxInt] of Char; b: BindingType; begin Unbind (f); b := Binding (f); b.Name := FileName; Bind(f, b); b := Binding(f); SeekRead (f, 0); if Empty (f) then FileSize := 0 else FileSize := LastPosition (f) + 1; Unbind(f); end; |
Prospero's Extended Pascal has a bug in this case. Replace the MaxInt in the type definition of f by a sufficiently large integer. GNU Pascal works correct in this case.
Put
as
soon as possible and a Get
as late as possible. This should
avoid most of the problems sometimes considered to be the most
stupid feature of Pascal. When passing a file buffer as parameter
the buffer is validated when the parameter is passed.
program DirectAccessFileDemo; type DFile = file [1 .. 100] of Integer; var F: DFile; P, N: 1 .. 100; begin Rewrite (F); P := 42; N := 17; SeekWrite (F, P); Write (F, N) end. |
The following direct access routines may be applied to a direct access file:
SeekRead (F, N); { Open file in inspection mode, seek to record N }
SeekWrite (F, N); { Open file in generation mode, seek to record N }
SeekUpdate (F, N); { Open file in update mode, seek to record N }
Update (F); { Writes F^, position not changed. F^ kept. }
p := Position (F); { Return current record number }
p := LastPosition (F); { Return the last record number in file }
If the file is open for inspection or update, Get
may be applied.
If the file is open for generation or update, Put
may be applied.
program AssignTextDemo; var t: Text; Line: String (4096); begin Assign (t, 'mytext.txt'); Reset (t); while not EOF (t) do begin ReadLn (t, Line); WriteLn (Line) end end. |
GPC supports these routines when applied to files. The compiler will reject binding of other object types.
Only the fields `Bound' and `Name' of the predefined record type `BindingType' are required by Extended Pascal. Additionally, GPC implements some extensions. For the full definition of `BindingType', see section 9.25 BindingType.
The following is an example of binding:
program BindingDemo (Input, Output, f); |
b.Existing
to True
to work-around this. GPC does not
behave like this.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |