1260 ObjectPAL: Combo field
VERSIONS: All

SUBJECT: Display text and store code when using dropdown fields

FROM: Paradox Technical Information document

Q: How can I design a drop-down edit field so it displays customer names but it stores customer numbers into the orders table?

I have a form that is based on one table, which contains order information for a relatively fixed number of customers. One of the fields in the Orders table is a customer number. I would prefer for my users to pick the correct customer from a drop-down edit box, rather than directly from the lookup table. The problem is that the users will not be able to recognize customers by their numbers, but they would recognize their names. However, the Orders table does not store the customer name. How can I design a drop-down edit field so it displays customer names but stores customer numbers into the Orders table?


A: As your users are using the form, your code would need to trap for two major events. First, if the user changes the value of the drop-down edit field, the value of the customer number field would need to be updated. Second, if the user opens the form or moves from one record to another, the drop-down edit field would need to reflect the proper value for that record. These events can be described by the different reason codes for the newValue built-in method.

One way to solve this problem to put ObjectPAL code on two fields: an undefined drop-down edit field that uses the Name field of the Customer table as a data source, and the Customer Number field, which can be invisible if necessary. Whenever the form is in edit mode and a user makes a choice from the drop-down edit field (NewValue event, reason() = EditValue), a TCursor locates the corresponding customer number and changes the value of the Customer Number field in the Orders table. When the user moves from record to record (NewValue event, reason() = FieldValue) or the user first opens the form (NewValue event, reason() = StartUpValue), a TCursor locates the appropriate name to display in the drop-down edit field.
    ;#page2::var
    var
       tc TCursor
    endvar

    ;#page2::open
    method open(var eventInfo Event)
       dodefault
       tc.open("Customer")  ; open the lookup table
       endmethod

    ;DropdownField::NewValue
    method newValue(var eventInfo ValueEvent)
       if eventInfo.reason() = EditValue and
       Customer_No.isEdit() then
       tc.locate("Name",self.value)
       Customer_No.value = tc."Customer No"
       endif
    endmethod

    ;DropdownField.ListObject::open
    method open(var eventInfo Event)
       self.datasource = "[customer.name]"
    endmethod

    ;Customer_No::newValue

    method newValue(var eventInfo ValueEvent)
       if eventInfo.reason() = FieldValue or
       eventInfo.reason() = StartUpValue then
       tc.locate("Customer No",self.value)
       DropDownField.value = tc.name
       endif
    endmethod

To index