Is there a workaround for “incompatible parameter list” message from Delphi IDE?
-
04-07-2021 - |
Question
Please consider this simplified example:
type
TForm43 = class(TForm)
drwgrd1: TDrawGrid;
procedure drwgrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: Windows.TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure TForm43.drwgrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: Windows.TRect; State: TGridDrawState);
begin
Rect.Left := 5;
end;
In method drwgrd1DrawCell
I've explicitly used Windows.TRect
to resolve ambiguity beetween TRect
defined in two different units. Everything works fine, code is compiling.
But everytime when I save the above unit I am getting a question from the Delphi IDE which asks: "The drwgrd1DrawCell method referenced by drwgrd1.OnDrawCell has an incompatible parameter list. Remove the reference?"
This is very annoying. Is there any way to turn off this message dialog or to write my code in a way that it would not be shown? Unfortunately I can not change my TRect
for TRect2
or something like that.
Solution
The reason you are getting the error when you save the form is because Delphi compares the declaration of all event handlers to ensure they are declare exactly the same as their inherited implementations. Adding Windows.
to the declaration makes the compare fail.
You can remove the Windows.
from drwgd1DrawCell()
if you move the Windows
unit after the other unit in the uses
clause that declares TRect
. This is because Delphi processes the units in the uses
clause from the last to the first. It will use the TRect
from the first instance that it finds...
OTHER TIPS
You could add the following type declaration above your form declaration:
type
TRect = Windows.TRect;