Ad Space — Top Banner

E2036

Delphi Programming Language

Severity: Moderate

What Does This Error Mean?

Error E2036 means Delphi expected a variable at a specific point in your code, but found an expression or literal value instead. The most common trigger is passing a constant, a literal value, or a read-only expression to a var or out parameter. Var parameters require an actual variable because the function writes back to it — a constant or expression has no place to write back to.

Affected Models

  • Delphi 2005 and later
  • RAD Studio
  • Lazarus/Free Pascal (similar error)

Common Causes

  • Passing a literal value (like 42 or 'hello') to a var parameter
  • Passing a constant (declared with const) to a var or out parameter
  • Passing a function call result or an expression to a var parameter
  • Trying to use the address-of operator (@) on something that has no memory address
  • Using a property where a var parameter requires a direct variable field

How to Fix It

  1. Create a local variable of the correct type, assign your value to it, pass the variable to the function, then read back the result.

    Example: instead of MyProc(42), write: var Temp: Integer; Temp := 42; MyProc(Temp);

  2. If you are passing a constant to a var parameter and the function does not actually modify it, ask yourself whether the parameter should be const instead of var.

    Change the parameter declaration from 'var X: T' to 'const X: T' and then constants and expressions are accepted.

  3. If you are trying to pass a property to a var parameter, you cannot do this directly because properties go through getter/setter methods, not direct memory access. Use a temporary variable.

    Example: Temp := MyObject.MyProperty; MyProc(Temp); MyObject.MyProperty := Temp;

  4. If you are using the @ operator to get an address and getting E2036, the expression you are applying it to must be a named variable. You cannot take the address of a temporary value.

    Assign the value to a variable first, then take its address: Temp := SomeValue; Ptr := @Temp;

  5. Review whether the function actually needs var. If it does not write back a value to the caller, change var to const or remove the modifier. This makes the call site much more flexible.

    Always prefer const over var for input-only parameters — it is more efficient and more flexible.

When to Call a Professional

E2036 is always something you can fix yourself. Create a temporary variable of the correct type, pass it to the function, then use its value after the call. Alternatively, change the parameter to a value parameter if write-back is not needed.

Frequently Asked Questions

Why cannot I pass a constant to a var parameter?

A var parameter is a reference to a memory location — the function expects to be able to write to that location. A constant has no writable memory location; it is baked into the program. Allowing it would mean the function is trying to overwrite a constant, which is unsafe and undefined.

Can I pass an array element to a var parameter?

Yes — array elements are variables with addresses. You can pass MyArray[i] to a var parameter and the function will modify that element directly. This works for both static and dynamic arrays.

What is the difference between var and out parameters?

Both require a variable and work by reference. The difference is in intent: var means the function both reads and writes the variable. out means the function only writes it — the original value is ignored. Use out when a function returns a value through a parameter without reading the existing value.