This display looks all right as far as it goes, but in many cases you want your labels to appear right-justified rather than left-justified. In other words, you want the colons that end each label to be vertically aligned, so that all the field values can begin at the same column position to the right of that. How can you do this?

ABL provides a built-in system handle, called FONT-TABLE, which is an object representing the current font. There are four useful methods you can apply to this handle to calculate the actual size of a value when it is displayed: GET-TEXT-WIDTH-CHARS, GET-TEXT-HEIGHT-CHARS, GET-TEXT-WIDTH-PIXELS, and GET-TEXT-HEIGHT-PIXELS. In an alternative version of the trigger code for the selection list, you can use this function to align the labels on their colons.

To colon-align your labels:

  1. Change the column setting in the CREATE TEXT statement for the label to this:
            /* COLUMN = 85.0. -- modified to do colon-aligned labels */
            COLUMN = 100.0 - FONT-TABLE:GET-TEXT-WIDTH-CHARS(hBufField:LABEL + ":").

    Instead of starting at column 85 and positioning the label to the right, the statement starts where the labels should end (column position 100), and subtracts the label width as calculated by the method on the FONT-TABLE. This gives the right starting position for the label object.

  2. Change the column assignment for the fill-in to be fixed at column 102:
            /* COLUMN = 85.0 + LENGTH(hBufField:LABEL) + 4 -- changed for
              colon-aligned */
            COLUMN = 102

    This places each displayed value at the same position, two positions to the right of the label.

    There is a third change you have to make as well. As discussed in the “Object sizing” section in Create dynamic fields, the format calculation for the label is likely to provide a format somewhat larger than the actual display width. This is a deliberate adjustment the AVM makes to provide a format for a field that is large enough to display most values without truncation. In the case of your labels, however, you might find that if you just use the label format to determine the width, the display width is a bit too large and overwrites the beginning of some of the displayed values with blanks. To correct this, you need to specify an accurate WIDTH-CHARS attribute value for the label, so that it is just large enough to display itself without truncation but not so large that it overwrites the value that follows it.

  3. Use the same FONT-TABLE method to calculate the WIDTH-CHARS of the text label object, adding this assignment to the CREATE TEXT statement:
            WIDTH-CHARS = FONT-TABLE:GET-TEXT-WIDTH-CHARS(hBufField:LABEL + ":") 
  4. Run the window. With these changes, you see a different display where the labels of the dynamic fields are colon-aligned:
  5. Select another row in the browse, and the field values are set to blank by the VALUE-CHANGED trigger on the browse. What you see, however, is that because the displayed fields are not all CHARACTER fields, the AVM applies the field’s format to the blank value, which in the case of a numeric field is the value zero, and is displayed in various ways by the different field formats:

Clearly this procedure is an interesting example of using dynamic fields but not a terribly useful application window. You would probably want to be able to select a list of fields once and use them to display OrderLine values for any Order you select, rather than having the fields blanked out after one OrderLine is displayed. And there must be a way to navigate through the OrderLines of an Order rather than just seeing the first one. Feel free to extend the test procedure to provide these abilities.

Since there is room in the window to display all the OrderLine fields, the whole notion of making them dynamic fill-ins is also of limited use. A more realistic example of how you can use this technique in an application would be for a table with a great many fields, only a few of which each user needs to work with. After you learn about dynamic data management objects in the next section, you are able to allow the user to select a completely different table to display in place of the OrderLines.