Get
The procedure get retrieves a datum from a file of … and advances the reading cursor. Although get is a standardized Pascal routine, in the FPC get is only available in an ISO-compliant mode, such as {$mode ISO}.
behavior
requirements
Before get is executed, two requirements must be met:
- The file must be in inspection mode.
- The file’s “cursor” may not be past EOF.
A run-time error occurs if either condition is not satisfied.
effect
Get
- advances the cursor by one record
- makes the new current record accessible via the file’s buffer variable.
To put this into relation:
read(f, x)is equivalent tox := f^; get(f).readLn(f)is equivalent towhile not EOLn(f) do get(f); get(f). The latterget(f)actually consumes the newline marker.reset(f)is semantically equivalent toseekRead(f, pred(firstRecord)); get(f)wherefirstRecordis the index of the first record.
application
Get is especially used to
- read the file buffer variable multiple times at various locations (e. g. subroutines),
- eliminate the need for an extra buffer variable.
begin
while not EOF(input) do
begin
output^ := input^;
get(input);
put(output);
end;
end.
- bypass read/readLn’s interpretation/conversion capabilities and make nasty type casts.
see also
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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
