read() and write() question lazarus / 62-General ---------------------------------------------------------------------- 440bx · 2020-02-09 10:38 Hello, Do the standard procedures "read" and "write" do anything if they are called without parameters ? i.e, "read();" and "write();" Some code is generated but it doesn't seem to have any effect.  The reason I'm asking the question is because I want to make sure I didn't miss some "hidden" effect they may have when called without parameters. Thank you for your help. ---------------------------------------------------------------------- ASerge · 2020-02-09 13:26 Quote from: 440bx on February 09, 2020, 11:38:02 amDo the standard procedures "read" and "write" do anything if they are called without parameters ? i.e, "read();" and "write();" Logically, they should not do anything - there are no arguments, nothing to read/write. Actual implementation: they call the Flush function. For Input, it is not present, but for Output, it is called at the end of any Write operation. So the only possible hidden effect is that if the previous call to Write(ln) failed, Write will flush the buffer. By the way, in Delphi, for {$IOCHECKS OFF} the code is not generated at all for Read and Write. ---------------------------------------------------------------------- marcov · 2020-02-09 14:12 Afaik write_end is only for textfile, not for typed file . OTOH typed file is buffered less, so that might not matter much . ---------------------------------------------------------------------- 440bx · 2020-02-09 17:27 Quote from: ASerge on February 09, 2020, 02:26:56 pmLogically, they should not do anything - there are no arguments, nothing to read/write. Actual implementation: they call the Flush function. For Input, it is not present, but for Output, it is called at the end of any Write operation. So the only possible hidden effect is that if the previous call to Write(ln) failed, Write will flush the buffer. By the way, in Delphi, for {$IOCHECKS OFF} the code is not generated at all for Read and Write. That makes sense.  Thank you Serge. Quote from: marcov on February 09, 2020, 03:12:51 pmAfaik write_end is only for textfile, not for typed file . OTOH typed file is buffered less, so that might not matter much . Thank you Marco. ---------------------------------------------------------------------- EganSolo · 2020-02-21 04:24 That's interesting. I guess I never thought about the difference between read() and readln(). Consider the silly little program: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Program Project1;Begin  Write('Hello ... when ready hit a key on the keyboard for the rest...');  readln();  Write(' World!');  readln();End.  Readln requires no param to work but if you replace the readln() with read(), the code will pass over it as if it wasn't there. ---------------------------------------------------------------------- lucamar · 2020-02-21 11:52 Quote from: EganSolo on February 21, 2020, 05:24:25 amReadln requires no param to work but if you replace the readln() with read(), the code will pass over it as if it wasn't there. That's quite logical: after all, ReadLn has to wait for an end-of-line before returning even if it's returning an empty line and putting it nowhere. And it was the only way to implement a "Press to continue" in the good old days.