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 E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...