Excursion: Controls

 

We have already created some controls in our knowledge base. If you're interested in how controls are managed in TCE and how they can be further programmed, you should read more here.

If you look at the properties of a control, you'll find a split into specific control properties and container properties.

Controls are not placed directly on the surface of a form, but within a so-called Control Container.

The container determines with its properties

-     The position (Left, Top), Width, and Height of a rectangle surrounding the control.

The values are given in twips, a resolution-dependent unit

When you change the resolution of the screen on windows you control the conversion factor from twips to pixels:

Setting of the scaling of Windows 10 (German version)

 

Thus, the conversion factor at 100% is usually determined by a factor of 15, i.e. 1 pixel = 15 Twips

If the resolution is set to 125%, the factor is smaller: 1Pixel = 12 Twips

(information depending on the physical resolution of the output medium)

 

If you want to determine the current conversion factor, use the functions

Client.Screen.TwipsPerPixelX or Client.Screen.TwipsPerPixelY

 

-     The alignment of the control container rectangle (see: Alignment Settings).

 

-     The visibility of the container and thus the visibility of the control.

Visible

-     An alternate name that can be used to find the control.

Alias

-     Determine whether the control can be selected in special design mode

Designable

-     The context menu that appears when the control is selected in design mode

DesignContextMenu

 

In addition, the container has events:

 

      ControlAvailable

The client-server architecture of TCE and the asynchronous transfer of the data may delay the availability of a control to the client. If the control is real-life with the client, the Controls container triggers this event.

      DesignerSelected

When an application is launched from the client in Designer mode and a control is enabled, the Controls container triggers this event.

      GotFocus

If a control receives the focus, this event is triggered.

      LostFocus

If a control loses focus, this event is triggered.

      Validate

Immediately before the focus loss, the Validate event is triggered by the container. This can prevent the focus loss if necessary.

      ResponsiveChanged

if the control is displayed in a different responsive context this event is generated

 

Let's say you have placed a button on a form. If you look at the parameters of the event, you will always find an object of type Ambient as the first parameter. The Ambient object provides you with information about the context of the control.

For example, you can close the window where the control is located:

Ambient.Formular.Hide

 

Or you might want to affect a property of the control container:

Ambient.Control.Visible := False

 

Or, you might want to affect a property of the control. To do this, use the typeless COM object reference with the name Object. In the following code, the typeless COM object reference is typed and the Text property is modified.

Dim Ctrl As TCEButtons.Button

 

Ctrl := Ambient.Control.Object

Ctrl.Text := "Cancel"

 

Alternatively, you can write the expression with a typecast:

Ambient.Control.Object:"TCEButtons.Button".Text := "Cancel"

 

If you want to influence another control, you can reach it from the window's form:

Ambient.Formular.Controls.Item("Material table").Controls.Item("ID").Object:"TCETables.TableColumn".Caption := "XXX"

 

You can see that this results in very long expressions. Remedy is the use of an alias on the control container whose control you want to influence.

Here, the table column ID is marked with an Alias with the value IDColumn. This makes the expression shorter because it can be referenced directly to the control:

Ambient.Formular.ControlByAlias("IDColumn").Object:"TCETables.TableColumn".Caption := "XXX"

 

You can also do without the explicit typecast. However, higher effort must be made at run time to find the property (binding at run time):

Ambient.Formular.ControlByAlias("IDColumn").Object.Caption := "XXX"

 

Alternatively, you can find a control container from its path (divided by slashes) from the window form:

Ambient.Formular.ControlByPath("Materialtabelle/ID").Object.Caption := "XXX"

 

Also, relative information is possible, here about an existing father-control:

Dim CtrlID As Control

 

CtrlID := Ambient.Formular.ControlByAlias("IDColumn")

CtrlID.ParentControl.Controls.Item("Bezeichnung").Object.Caption := "Material text"