Ad Space — Top Banner

E2033

Delphi Programming Language

Severity: Moderate

What Does This Error Mean?

Error E2033 means you passed a variable to a var parameter in a procedure or function, but the variable's type does not exactly match the declared type of that parameter. Var parameters in Delphi are passed by reference — the function works directly on your original variable. Because of this, the types must be absolutely identical, not just compatible.

Affected Models

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

Common Causes

  • Passing a variable of a subtype or compatible-but-not-identical type to a var parameter
  • Passing a TMyType variable to a var parameter declared as its base type (or vice versa), even if they look the same
  • Passing a typed pointer where an untyped pointer (Pointer) was declared, or vice versa
  • Passing a Byte or Word where an Integer var parameter is expected — even though they are all integers
  • A type alias declared with 'type' keyword is treated as a new distinct type, not the same as the original

How to Fix It

  1. Change your variable's type to exactly match the type declared for the var parameter. Check both the declaration and the call site.

    Even if two types are compatible for assignment, they must be identical for a var parameter.

  2. If you control the function and the parameter does not need to be modified, change var to const or remove the parameter modifier entirely. Then compatible types are accepted.

    Use var only when the function needs to write back to the caller's variable. If it only reads, use const.

  3. If you declared a type alias with the 'type' keyword, it creates a new distinct type. Either use the original type for the variable, or change the parameter to accept the alias type.

    Example: type TMyInt = Integer; — TMyInt and Integer are incompatible for var parameters even though they are identical in memory.

  4. For integer types like Byte, Word, Integer, and Int64, var parameters require the exact same integer type. Convert to the exact type the function expects before passing it.

    You can use a temporary variable of the correct type, modify it via the function, then copy back.

  5. If you need to pass any pointer type without knowing the exact type, use an untyped var parameter (declared simply as 'var X' without a type). This accepts any type.

    This technique is used in standard Delphi routines like Move() and FillChar().

When to Call a Professional

E2033 is always something you can fix yourself. The strictness of var parameters is intentional and prevents dangerous memory errors. Change the type of your variable to match the parameter exactly, or change the parameter to use a value parameter instead of var.

Frequently Asked Questions

Why are var parameters stricter than regular value parameters?

A value parameter receives a copy — Delphi can safely convert a compatible type for the copy. A var parameter is a direct reference to the original variable — if the types do not match in size or layout, writing through the reference could corrupt memory. The strict type check prevents these memory corruption bugs.

What is the difference between var, const, and out parameters?

Var: the function can both read and write the caller's variable. Const: the function can only read — the original cannot be changed. Compatible types are accepted. Out: the function only writes — the original value is discarded. Same strictness as var. If in doubt, use const — it is the safest and most flexible.

Can I pass a literal value (like the number 42) to a var parameter?

No — you can only pass a variable to a var parameter. A literal value has no address in memory, so there is nothing for the reference to point to. Create a variable, assign your value to it, then pass the variable.