KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Swapping the position of form objects dynamically with MOVE OBJECT
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: August 24, 2001

The following method will allow you to swap the positions of any two objects on a form by passing in their object names (not their associated variable names). It is useful especially when you want to have several display options within the same form.

For example:

You want to give your form the ability to display one of several objects at a specific position when conditions are met. The first thing that you need to do is create all of the objects you will need, outside of the form's display area.



In this example, a specific button will be displayed depending on which radio button the user has selected.








The following method will swap the objects' positions.

` Project Method: SwapFormObjectPositions

` Description: This method will switch the position between 2 objects

`

` $1 - The name of the object that you want to move out.

` $2 - The name of the object that you want to move in.

`

` Author: Add Komoncharoensiri - 4D, Inc.



C_TEXT($1;$2)

GET OBJECT RECT(*;$1;Left1;Top1;Right1;Bottom1)
GET OBJECT RECT(*;$2;Left2;Top2;Right2;Bottom2)

If (Left1>=Left2)
 Case of

   : (Top1>=Top2)
     MOVE OBJECT(*;$1;-(Left1-Left2);-(Top1-Top2);0;0)
      MOVE OBJECT(*;$2;(Left1-Left2);(Top1-Top2);0;0)
   Else
     MOVE OBJECT(*;$1;-(Left1-Left2);(Top2-Top1);0;0)
     MOVE OBJECT(*;$2;(Left1-Left2);-(Top2-Top1);0;0)
  End case
Else
 Case of
   : (Top1>=Top2)
     MOVE OBJECT(*;$2;-(Left2-Left1);(Top1-Top2);0;0)
    Else
     MOVE OBJECT(*;$2;-(Left2-Left1);-(Top2-Top1);0;0)
    End case
End if

` This part is optional. You will only need it if you want to hide
` the object from the visible area
SET VISIBLE(*;$1;False)
SET VISIBLE(*;$2;True)