Sign in Join
Wiki copytemporary

Get: what changed

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

Title: Get

OldNewLine
1+The [[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}]].
2+
3+## behavior
4+
5+### requirements
6+
7+Before `get` is executed, two requirements must be met:
8+
9+1. The file must be in *inspection* mode.
10+2. The file’s “cursor” may not be past [[EOLN and EOF|EOF]].
11+
12+A [[runtime error|run-time error]] occurs if either condition is not satisfied.
13+
14+### effect
15+
16+`Get`
17+
18+1. advances the cursor by one record
19+2. makes the new current record accessible via the file’s buffer variable.
20+
21+To put this into relation:
22+
23+- `read(f, x)` is equivalent to `x := f^; get(f)`.
24+- `readLn(f)` is equivalent to `while not EOLn(f) do get(f); get(f)`. The latter `get(f)` actually consumes the newline marker.
25+- `reset(f)` is semantically equivalent to `seekRead(f, pred(firstRecord)); get(f)` where `firstRecord` is the index of the first record.
26+
27+## application
28+
29+`Get` is especially used to
30+
31+- read the file buffer variable multiple times at various locations (e. g. subroutines),
32+- eliminate the need for an *extra* buffer variable.
33+
34+begin
35+
36+`   while not EOF(input) do`\
37+`   begin`\
38+`       output^ := input^;`\
39+`       get(input);`\
40+`       put(output);`\
41+`   end;`
42+
43+end.
44+
45+</syntaxhighlight>
46+
47+- bypass [[Read|read/readLn]]’s interpretation/conversion capabilities and make nasty [[Typecast|type casts]].
48+
49+## see also
50+
51+- [[Put|put]]
52+
53+---
54+*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).*
55+Category: File Handling
56+Category: Pascal

Back to history