2.14 :exchange()

There are two different forms of the :exchange() method:

2.14.1 :exchange() (List Objects)

This method exchanges two rows or columns in the contents of an object whose contents consist of multiple entries indexed with integer or index. Along with the contents, the associated attributes are exchanged as well.

Definition

boolean :exchange
(
      integer Position1 input,
      integer Position2 input
  { , boolean Direction := false input }
)

Parameters

integer Position1 input
integer Position2 input
These parameters define the two rows or columns that should be exchanged with each other.
boolean Direction := false input

This optional parameter controls whether rows or columns are exchanged in the tablefield. This depends on the value of the tablefield attribute .direction.

The parameter may only be passed for the tablefield. For other objects than the tablefield, passing the parameter will result in an error.

Value range

false
Exchanges against the direction given in the .direction attribute
true
Exchanges in the same direction as given in the .direction attribute

Thus these contents are exchanged in the tablefield:

Parameter Direction

.direction 1 (vertical)

.direction 2 (horizontal)

false

row(s)

column(s)

true

column(s)

row(s)

Return value

The method returns true if the rows or columns could be exchanged.

If an error has occurred when exchanging, the method will return a fail.

Objects with this method

Example

dialog D

window Wn
{
  .title "Example for the method :exchange()";

  child treeview Tv
  {
    .content[1] "Company A";
    .content[2] "Miller";
    .content[3] "Mayer";
    .content[4] "Company B";
    .content[5] "Jones";
    .content[6] "Smith";
    .content[7] "Fisher";
    .style[style_lines]   true;
    .style[style_buttons] true;
    .style[style_root]    true;
    .level[2] 2;
    .level[3] 2;
    .level[5] 2;
    .level[6] 2;
    .level[7] 2;
  }

  child statictext St
  {
    .text "Select an employee";
  }

  child pushbutton Pb
  {
    .text "Exchange two employees";

    on select
    {
      if (Tv.activeitem > 1) then
        if (Tv.level[Tv.activeitem] = Tv.level[(Tv.activeitem - 1)]) then
          Tv:exchange(Tv.activeitem, (Tv.activeitem - 1));
          St.text := "Exchange ok";
        else
          St.text := "Upper partner is a company";
        endif
      else
        St.text := "There is no upper partner";
      endif
    }
  }
}

2.14.2 :exchange() (Arrays)

This method exchanges two items of an array (indexed, non-associative, user-defined attribute).

Definition

boolean :exchange
(
  attribute Attr input,
  integer Position1 input,
  integer Position2 input
)

Parameters

attribute Attr input
This parameter defines the user-defined attribute on which the method should be applied.
integer Position1 input
integer Position2 input

In these parameters the indices of the two items to be exchanged with each other are passed.

The value range for both parameters is 0 … .count[Attr], i.e. the default value can also be exchanged with the value of another item.

Return value

The method returns true if the items could be exchanged.

If an error has occurred when exchanging, the method will return a fail.

Objects with this method

All objects that may have user-defined attributes.

See also

Chapter “Methods for Arrays of User-defined Attributes” in manual “User-defined Attributes and Methods”