Skip to content

On_name_item Command

Obsolete

This command is obsolete. It is valid only in character-mode DataFlex. There is no Windows equivalent for this option.

See Also

Purpose

To replace the on_item command.

Syntax

on_name_item
item_name [value]
... (standard on_item syntax)

What It Does

on_name_item is a version of the on_item command that permits the assignment of names to object items for easier recognition in source code. item_name is the name by which you choose to refer to the item, and the remainder of the syntax (starting with value) is the syntax of the original on_item command.

Referring to items in objects by their item numbers straightforwardly can result in code that is very difficult to read, as the following example demonstrates.

Object My_Form is a Form
    item_list
        on_item '' Send None
        on_item '' Send None
        on_item '' Send None
    end_item_list

    Procedure Run_report
        String IODevice FileName
        Integer Index_Order
        Get value item 1 to FileName
        Get value item 0 to IODevice
        Get value item 2 to Index_Order
        Send Run_Report IODevice FileName Index_Order
    end_procedure
end_object

We have to keep track of the item numbers (they are zero-based). This can be difficult. What if we counted wrong? What if we moved the items around?

The following example shows how the same would be done using on_name_item:

Object My_Form is a Form
    item_list
        on_name_item Form_IODevice## '' Send None
        on_name_item Form_FileName## '' Send None
        on_name_item Form_Index## '' Send None
    end_item_list

    Procedure Run_report
        String IODevice FileName
        Integer Index_Order
        Get value item Form_FileName## to FileName
        Get value item Form_IODevice## to IODevice
        Get value item Form_Index## to Index_Order
        Send Run_Report IODevice FileName Index_Order
    end_procedure
end_object

Note that you do not need to use on_name_item everywhere you would have used on_item. In fact, it is best to only name the items that you actually need. Certain limitations of on_name_item are described in the article above on the entry_name_item command, as well as techniques for using the command to address items in Grid objects.