[SOLVED] File types must be var parameters. Why? lazarus / 21-General ---------------------------------------------------------------------- zamronypj · 2021-07-05 05:23 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 procedure WriteHello(const atxtfile : Text);var txt : Text;begin    txt := atxtfile;    write(txt, 'hello');end; begin    WriteHello(StdOut);end.  Above code will not be compiled with error Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Error: File types must be var parameters Why const cannot be used for file types? ---------------------------------------------------------------------- skalogryz · 2021-07-05 05:34 Quote from: zamronypj on July 05, 2021, 07:23:49 amWhy const cannot be used for file types? when you're reading/writing the file you're changing the state of the file-variable that's responsible for tracking the state of the file. It doesn't matter if you modify the file itself or just trying to read it - you're always changing the contents of the (Text) variable. "const" declares that the variable value cannot be changed, and this is just not the case for files. So you've to use "var" at all times. For the advanced developers it might be easier to put into this perspective. "Text" is actually an implicit RECORD and not a pointer. (as one could be used to when dealing with unix FILE, windows's Handle, or TStream) 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 var t : Text;begin  writeln(sizeof(t));end. ---------------------------------------------------------------------- lucamar · 2021-07-05 05:44 And it's documented in the Language Guide: Quote from: Free Pascal Reference guideFile type variables must always be passed as variable parameters. ---------------------------------------------------------------------- zamronypj · 2021-07-05 06:27 @skalogryz Thank you. Make sense  now. @lucamar Documentation does not explain why. ---------------------------------------------------------------------- lucamar · 2021-07-05 06:32 Quote from: zamronypj on July 05, 2021, 08:27:45 am@lucamar Documentation does not explain why. Yeah, I know. I mention it just for completeness sake. I was going to explain why but skalogryz beat me to it