Sign in Join
Wiki copytemporary

Get: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11The [[Procedure|procedure]] **`get`** retrieves a datum from a [[typed files|file of …]] and advances the reading cursor. Although `get` is a standardized [[Standard Pascal|Pascal]] routine, in the [[FPC]] `get` is only available in an ISO-compliant mode, such as [[Mode iso|{$mode ISO}]].
22
33## behavior
44
55### requirements
66
77Before `get` is executed, two requirements must be met:
88
991. The file must be in *inspection* mode.
10102. The file’s “cursor” may not be past [[EOLN and EOF|EOF]].
1111
1212A [[runtime error|run-time error]] occurs if either condition is not satisfied.
1313
1414### effect
1515
1616`Get`
1717
18181. advances the cursor by one record
19192. makes the new current record accessible via the file’s buffer variable.
2020
2121To put this into relation:
2222
2323- `read(f, x)` is equivalent to `x := f^; get(f)`.
2424- `readLn(f)` is equivalent to `while not EOLn(f) do get(f); get(f)`. The latter `get(f)` actually consumes the newline marker.
2525- `reset(f)` is semantically equivalent to `seekRead(f, pred(firstRecord)); get(f)` where `firstRecord` is the index of the first record.
2626
2727## application
2828
2929`Get` is especially used to
3030
3131- read the file buffer variable multiple times at various locations (e. g. subroutines),
3232- eliminate the need for an *extra* buffer variable.
3333
3434begin
3535
3636`   while not EOF(input) do`\
3737`   begin`\
3838`       output^ := input^;`\
3939`       get(input);`\
4040`       put(output);`\
4141`   end;`
4242
4343end.
4444
45-</syntaxhighlight>
46-
4745- bypass [[Read|read/readLn]]’s interpretation/conversion capabilities and make nasty [[Typecast|type casts]].
4846
4947## see also
5048
5149- [[Put|put]]
5250
5351---
5452*From the Free Pascal wiki, page "Get", as it stood on 2021-07-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
5553Category: File Handling
5654Category: Pascal

Back to history