【发布时间】:2022-01-19 14:44:54
【问题描述】:
在Delphi的源码中,我在FMX.Forms单元中看到了这个:
procedure TCommonCustomForm.SetHovered(const Value: IControl);
begin
if (Value <> FHovered) then
begin
....
end;
end;
我认为Value <> FHovered 根本上是错误的,因为Value <> FHovered 可以返回true,同时Value 和FHovered 都可以指向同一个TControl 对象。我错了吗? (注意这是我在调试时看到的)。
现在是一个附属问题:为什么 2 个IControl 接口可以不同(从指针的角度来看)但指向相同的TControl?
注意:下面的示例显示了 2 IControl 如何不同(从指针视图)并且仍然指向同一个对象:
procedure TForm.Button1Click(Sender: TObject);
var LFrame: Tframe;
Lcontrol: Tcontrol;
LIcontrol1: Icontrol;
LIcontrol2: Icontrol;
begin
Lframe := Tframe.Create(nil);
Lcontrol := Lframe;
LIcontrol1 := Lframe;
LIcontrol2 := Lcontrol;
if LIcontrol1 <> LIcontrol2 then
raise Exception.Create('Boom');
end;
现在还有什么好的方法可以修复这个错误?
【问题讨论】:
-
我怀疑调试器中的错误,但除了声称我们没有任何证据。
-
@RemyLebeau 实际上,这种情况是可能的。
TControl = class(TFmxObject, IControl,和TFrame = class(TControl, IControl) -
@RemyLebeau 喜欢 Dalija 说是的,这是可能的,我看到了(顺便说一下 Tframe)。如果在 Tframe 内,在 Tcontrol 实现中(Tframe 从 Tcontrol 下降)我做 MyIcontrol1 := self 和 Tframe 外我做 MyIcontrol2 := MyTframe 然后 MyIcontrol1 MyIcontrol2 :(
-
@UweRaabe 我用一个样本编辑了这个问题,表明它是可能的
-
我打开了一个质量错误请求:quality.embarcadero.com/browse/RSP-36612
标签: delphi firemonkey