Delphi Error – E2033 Types of actual and formal var parameters must be identical

Delphi Compiler Error

E2033 Types of actual and formal var parameters must be identical

Reason for the Error & Solution

For a variable parameter, the actual argument must be of the exact type of the formal parameter.

program Produce;

procedure SwapBytes(var B1, B2 Byte);
var
  Temp: Byte;
begin
  Temp := B1; B1 := B2; B2 := Temp;
end;

var
  C1, C2 0..255;     (*Similar to a byte, but NOT identical*)
begin
  SwapBytes(C1,C2);   (*<-- Error message here*)
end.

Arguments C1 and C2 are not acceptable to SwapBytes, although they have the exact memory representation and range that a Byte has.

program Solve;

procedure SwapBytes(var B1, B2 Byte);
var
  Temp: Byte;
begin
  Temp := B1; B1 := B2; B2 := Temp;
end;

var
  C1, C2 Byte;
begin
  SwapBytes(C1,C2);   (*<-- No error message here*)
end.

So you actually have to declare C1 and C2 as Bytes to make this example compile.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...