KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Detecting which form objects are directly under the mouse
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: June 30, 2017

Here is a project method that can be used to detect which form objects are currently under the mouse:

// ----------------------------------------------------
// Method: getMouseOverObjects
// Description
// Populate a text array with the object names that the mouse
// is currently hovering over.
//
// Parameters
// $ 1 - Pointer to a Text array
// ----------------------------------------------------
C_POINTER($1;$objectName_atp)
If (Count parameters>=1)
   $objectName_atp:=$1
   CLEAR VARIABLE($objectName_atp->)
   C_LONGINT($x;$y;$mouse_l)
   GET MOUSE($x;$y;$mouse_l)
   ARRAY TEXT($objectName_at;0)
   FORM GET OBJECTS($objectName_at)
   C_LONGINT($i;$l;$t;$r;$b)
   For ($i;1;Size of array($objectName_at))
    OBJECT GET COORDINATES(*;$objectName_at{$i};$l;$t;$r;$b)
    If ($l<=$x) & ($x<=$r) & ($t<=$y) & ($y<=$b)
     APPEND TO ARRAY($objectName_atp->;$objectName_at{$i})
    End if
   End for
End if


If this method is saved as a project method named getMouseOverObjects then it could be used like this:
C_LONGINT($formEvent_l)
$formEvent_l:=Form event
Case of
  :($formEvent_l=On Mouse Move)
     ARRAY TEXT(atFormObjects;0)
     getMouseOverObjects (->atFormObjects)
End case


Then, as the mouse moves around the form the atFormObjects array will be populated with the names of each form object directly under the mouse.