

It is not allowed to set the value to the const parameter inside of the function/procedure either pass it as a var/out parameter to other routines. The const parameters are almost the same as standard parameters, but have some differences. The out parameters are the same as var parameters except that the out prefix indicates that the input value is not respected (for managed types, for simple types that will be just assumption as the value is not set to default) and the parameter value is initialized with the default value for managed types (such as string, dynamic array or interface). When other developer looks at your code and sees the var prefix he will be confused – as var means that the value can be changed from inside of the routine! And also once you define the parameter as var you cannot pass the constants to the routine.

When you access and modify the fields of the object or interface you do not need to mark parameter as var. You should use the var parameters only when you actually modify the value of the variable you pass to the routine. So once the value is assigned to the parameter it changes the source instance/memory block. Var parameters are passed to the routine always by reference. When we define such a parameters we can pass the constants as well. And we still have an ability to assign a value to the parameter inside of the function/procedure, but that only affects the value in the stack which was pushed there before. When no prefix is defined for the parameter the compiler passes it by value (simple types) or by reference (string, fixed array, dynamic arrays and records) with copy on write technique. Everybody know that in Delphi there are four types of parameters:īut let me just refresh your memory a bit 🙂 Standard
