KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Find Global Coordinates of an Object
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: July 23, 2015

Below is a method to find the global coordinates in the context of the 4D application as opposed to the local coordinates in the context of the form it is on with the OBJECT GET COORDINATES command.

//----------------------------------------------------------------
// Method: ObjectGetGlobalCoordinates
//
// Description: Returns the Global Coordinates of an object within
// the scope of 4D
//
// Parameters:
// $1 - String containing name of the object
//
// The following four parameters are Pointer to the Longint that will
// contain the resulting coordinate values:
// $2 - Left
// $3 - Top
// $4 - Right
// $5 - Bottom
//
//----------------------------------------------------------------

C_TEXT($1;$objName_t)
C_POINTER($2;$3;$4;$5)
C_LONGINT($objLeft_l;$objTop_l;$objRight_l;$objBot_l)
C_LONGINT($winLeft_l;$winTop_l;$winRight_l;$winBot_l)
C_BOOLEAN($0)

If (Count parameters=5)
   $objName_t:=$1

   OBJECT GET COORDINATES(*;$objName_t;$objLeft_l;$objTop_l;$objRight_l;$objBot_l)
   GET WINDOW RECT($winLeft_l;$winTop_l;$winRight_l;$winBot_l)

   $2->:=$winLeft_l+$objLeft_l
   $3->:=$winTop_l+$objTop_l
   $4->:=$winLeft_l+$objRight_l
   $5->:=$winTop_l+$objBot_l

End if


Example of using the method:
//There is a button object named "Button"
ObjectGetGlobalCoordinates ("Button";->$left_l;->$top_l;->$right_l;->$bottom_l)

This will return the global coordinates of the "Button" object in the four longint variables.