Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Types of actual and formal var parameters must be identical" error in Procedure

I am trying to write a procedure in delphi. This procedure gets the name of TControl descendent element and then try to change some properties. But when i try to do it, Delphi gives an error like:

E2033 Types of actual and formal var parameters must be identical

Procedure:

procedure Change_prop(var Control: TControl;height:integer;width:integer);
begin
//......
end;

Usage Example : Change_prop(Label1, 50,200); What can be the solution of that error..Thanks.

like image 237
Alper Avatar asked Dec 10 '10 17:12

Alper


People also ask

What are actual and formal parameters of a procedure?

The Actual parameters are the variables that are transferred to the function when it is requested. The Formal Parameters are the values determined by the function that accepts values when the function is declared.

What are formal and actual parameters with example?

formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller. actual parameter — the actual value that is passed into the method by a caller. For example, the 200 used when processDeposit is called is an actual parameter.

What is meant by a formal parameter?

formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller. For example, amount is a formal parameter of processDeposit.


2 Answers

You just need to remove the var in the Control parameter and make it a value parameter. Because Delphi objects are actually implemented as reference types, you can call methods on them, change member fields etc. even if you pass them to a procedure as a value or const parameter.

like image 98
David Heffernan Avatar answered Sep 22 '22 10:09

David Heffernan


Just remove var - you don't need it to change Control's properties:

procedure Change_prop(Control: TControl;height:integer;width:integer);
begin
......
end;
like image 28
kludg Avatar answered Sep 21 '22 10:09

kludg