Access violation with FindDragTarget

0

I need to detect what kind of component the user has clicked on. For this I am using the following check, every time the left mouse button is clicked:

if FindDragTarget(Mouse.CursorPos, True).ClassType = TEdit then
//Código

However, when the user clicks on the windows virtual keyboard and its keys, I get the message from Access Violation ; I guess it's because it's calling the function but it does not recognize the type of component. I am in Windows 10 and my Delphi is XE7 ; it may not recognize the virtual keyboard component and thus can not perform the verification. Anyway, are there other alternatives to check what kind of component the user clicked on?

    
asked by anonymous 07.08.2017 / 21:49

1 answer

0

You're assuming that the FindDragTarget (Mouse.CursorPos, True) function ALWAYS returns a value, which may not be happening.

You should check first, something like

ct:=FindDragTarget(Mouse.CursorPos, True);
if (ct<>nil) and (ct.classtype=TEdit) then
    ...
    
08.08.2017 / 12:05