What is a good way to compare 2 interfaces (IControl)? Is this a bug in Delphi?


In the source code of Delphi, I see this in the FMX.Forms unit:
procedure TCommonCustomForm.SetHovered(const Value: IControl);
if (Value <> FHovered) then

I think doing Value <> FHovered is fundamentally wrong because Value <> FHovered can return true and at the same time both Value and FHovered can point to the same TControl object. Am I wrong? (note this is what I saw in debugging).
Now a subsidiary question: why can 2 IControl interfaces be different (from the view of pointers) but point to the same TControl?
Note: below a sample that show how 2 IControl can be different (from the pointer view) and still pointing to the same object:
procedure TForm.Button1Click(Sender: TObject);
var LFrame: Tframe;
Lcontrol: Tcontrol;
LIcontrol1: Icontrol;
LIcontrol2: Icontrol;
Lframe := Tframe.Create(nil);
Lcontrol := Lframe;
LIcontrol1 := Lframe;
LIcontrol2 := Lcontrol;
if LIcontrol1 <> LIcontrol2 then
raise Exception.Create(‘Boom’);

Now also what could be the good way to fix this bug ?

Comments are closed.