Object Properties Table Lookups
- List Box Configuration
- Vendor Choices for List Box
- Product Choices for List Box
- Product Filter for List Box
- Combo Box Configuration
- Vendor Choices for Combo Box
- Product Choices for Combo Box
- Product Filter for Combo Box
- Record List - List Box Configuration
- Vendor Choices for Record List - List Box
- Product Choices for Record List - List Box
- Product Filter for Record List - List Box
- Record List - Combo Box Configuration
- Tabbed2 OnTabChange
- Table_Lookups OnFetch
- Vendor OnChange
- Refresh_Products()
- Tabbed2 OnTabChange Event
- Vendor OnChange Event
- Table Lookups OnFetch Event
- Refresh_Products() function
Description
The value of using object properties to populate a list is that the developer can use a variety of other control types. The Object Properties tab of the Table Lookups form demonstrates five different ways to do table lookups.
List Box Configuration
The List Box tab of the Table Lookups form contains two list boxes.
Vendor Choices for List Box
The Choices tab of the list box displays the vendor_name field and stores the vendor_no field from the Vendor table. The records are sorted alphabetically by vendor_name.
Select the list box and right click.
Select Properties... .
Display the Choices tab.
Select "Computed Automatically" in the Choices for control are list.
Select "Values from a table/set" in the Source list.
Select "vendor" in the From Table list.
In the Field/expression value to display control enter " vendor_name + "|" + vendor_no ". This expression returns two fields: vendor_name, which is displayed, and vendor_no, which is stored.
Select "vendor_name" in the Display order list. This sorts the records alphabetically on the vendor_name field.
Click OK to return to the Form Editor.
Product Choices for List Box
The Choices tab of the List Box displays the product_name field and stores the product_no field from the Product table. The records are sorted alphabetically by product_name.
Select the list box and right click.
Select Properties... .
Display the Choices tab.
In the Choices for control are list select "Computed Automatically".
In the Source list select "Values from a table/set".
In the From Table list select "product".
In the Field/expression value to display control enter " product_name + "|" + product_no ". This expression returns two fields: product_name, which is displayed, and product_no, which is stored.
In the Display order list select "product_name". This sorts the records alphabetically on the product_name field.
Select Enable Filter Expression and click Edit Filter Expression.
Product Filter for List Box
In addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op1. A change in the quote_vendor_no_op1 field triggers a refresh of the Product list.
The table name in the Field Expression (in target table) must not be fully qualified. However, the table names in Field Expression (in current table) and Watch Expression fields must be fully qualified. The reason is that Alpha Anywhere evaluates the expression from the point of view of the Product table.
Enter "Product_Vendor_No" in the Field Expression (in target table) list.
Select "=" in the Operator list.
Select "Quote_Vendor_No_OP1" in the Field Expression (in current table) list.
Select "Quote_Vendor_No_OP1" in the Watch Expression list.
Click OK to return to the Field Properties dialog.
Click OK to return to the Form Editor.
Combo Box Configuration
The Combo Box tab of the Table Lookups form contains two combo boxes.
Vendor Choices for Combo Box
The Choices tab of the Vendor combo box displays the vendor_name field from the Vendor table. The records are sorted alphabetically by vendor_name. The implementation is the same as described in Vendor Choices for List Box.
Product Choices for Combo Box
The Choices tab of the Product combo box displays the product_name field from the Product table. The records are sorted alphabetically by product_name. The implementation is the same as described in Product Choices for List Box.
Product Filter for Combo Box
In addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op2. A change in the quote_vendor_no_op2 field triggers a refresh of the Product list. The implementation is the same as described in Product_Filter_for_List_Box, with the exception of that the variable names change from Quote_Vendor_No_Op1 to Quote_Vendor_No_Op2.
The table name in Field Expression (in target table) must not be fully qualified. However, the table names in Field Expression (in current table) and Watch Expression fields must be fully qualified. The reason is that Alpha Anywhere evaluates the expression from the point of view of the Product table.
Record List - List Box Configuration
The Record List - List Box tab of the Table Lookups form contains two record list boxes.
Vendor Choices for Record List - List Box
The Choices tab of the record list - list box displays the vendor_name field and stores the vendor_no from the Vendor table. The records are sorted alphabetically by vendor_name.
Select the record list - list box and right click.
Select Properties... .
Display the Choices tab.
Select "vendor" in the From Table list.
Select "vendor_no" in the Return Value list. This is the field that the form will store.
Click Add New Column to Record List.
Select "vendor_name" in the Field list.
Change the column title in the Header control to "Name".
Click OK.
Click A dd New Column to Record List.
Select "vendor_no" in the Field list.
Change the column title in the Header control to "Number".
Product Choices for Record List - List Box
The Choices tab of the record list - list box displays the product_name field and stores the product_no field from the Product table. The records are sorted alphabetically by product_name.
Select the record list - list box and right click.
Click Properties... .
Display the Choices tab.
Select "product" in the From Table control.
Select "product_no" in the Return value control. This is the field that the form will store.
Click Add New Column to Record List.
Select "product_name" in the Field list.
Change the column title in the Header field to "Name".
Click OK.
Click Add New Column to Record List.
Select "product_symbol" in the Field list.
Change the column title in the Header field to "Symbol".
Product Filter for Record List - List Box
In addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op3. A change in the quote_vendor_no_op3 field triggers a refresh of the Product list.
Select Enable Filter Expression and click Edit Filter Expression.
In the Field Expression (in target table) control enter "Product_Vendor_No".
Select "=" in the Operator list.
In the Field Expression (in current table) control enter "Product_Vendor_No_OP3".
Select "Quote_Vendor_No_OP3" in the Watch Expression control.
Select "product_name" in the Display order list.
Click OK to return to the Field Properties dialog.
Click OK to return to the Form Editor.
Record List - Combo Box Configuration
The Record List - List Box tab of the Table Lookups form contains two list boxes.
Vendor Choices for Record List - Combo BoxThe Choices tab of the record list - combo box displays the vendor_name field and stores the vendor_no field from the Vendor table. The records are sorted alphabetically by vendor_name. The implementation is the same as described in Vendor Choices for Record List-List Box.Product Choices for Record List - Combo BoxThe Choices tab of the record list - combo box displays the product_name field and stores the product_no field from the Product table. The records are sorted alphabetically by product_name. The implementation is the same as described in Product Choices for Record_List-List Box.Product Filter for Record List - Combo BoxIn addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op4. A change in the quote_vendor_no_op4 field triggers a refresh of the Product list. The implementation is the same as described in Product Filter for Record List-List Box, except that the variable quote_vendor_no_op3 changes to quote_vendor_no_op4.Radio Button ConfigurationThe Radio Button tab of the Table Lookups form contains two radio buttons. There are no field rules or choices defined in object properties. The implementation is based on Xbasic code as follows.
Tabbed2 OnTabChange
This event refreshes the list of Vendors when the user arrives at the Event Driven tab. The code retrieves a list of Vendors, counts the number of records, and limits the list to a maximum of 7 items (because of the size of the area allocated to radio buttons).
Table_Lookups OnFetch
This event refreshes the list of Products when the user reads a new record. The script calls a function named Refresh_Products.
Vendor OnChange
This event refreshes the list of Products when the user selects a different vendor. The script calls a function named Refresh_Products.
Refresh_Products()
This function receives pointers to the Vendor and Product radio button objects. It uses this information to retrieve the appropriate list of Product_name fields. It limits the list to a maximum of 7 items.
Tabbed2 OnTabChange Event
dim cFieldList as C dim nCounter as N dim nRecordCount as N dim cWord as C cFieldList = table.external_record_content_get("Vendor", \ "Vendor_Name + '|' + Vendor_No", "Vendor_Name", "") nRecordCount = w_count(cFieldList, crlf()) nRecordCount = min(7, nRecordCount) if (nRecordCount = 0) then end end if vendor.choice.list.redim(nRecordCount) for nCounter = 1 to nRecordCount cWord = word(cFieldList, nCounter, crlf()) vendor.choice.listnCounter.value = word(cWord, 2, "|") vendor.choice.listnCounter.text = word(cWord, 1, "|") next nCounter
Vendor OnChange Event
dim vendor_ptr as P dim product_ptr as P dim nRecordCount as N vendor_ptr = Vendor.this product_ptr = Product.this nRecordCount = refresh_products(vendor_ptr, product_ptr)
Table Lookups OnFetch Event
dim vendor_ptr as P dim product_ptr as P dim nRecordCount as N vendor_ptr = Vendor.this product_ptr = Product.this nRecordCount = refresh_products(vendor_ptr, product_ptr)
Refresh_Products() function
FUNCTION Refresh_Products as C (Vendor as P, Product as P) dim cFieldList as C dim nCounter as N dim nRecordCount as N dim cWord as C dim cVendor as C cVendor = Vendor.value cFieldList = table.external_record_content_get("Product",\ "Product_Name + '|' + Product_No","Product_Name",\ "Product_Vendor_No = " + quote(cVendor)) nRecordCount = w_count(cFieldList,crlf()) if (nRecordCount = 0) then end end if nRecordCount = min(7, nRecordCount) Product.choice.list.redim(nRecordCount) for nCounter = 1 to nRecordCount cWord = word(cFieldList, nCounter, crlf()) Product.choice.listnCounter.value = word(cWord, 2, "|") Product.choice.listnCounter.text = word(cWord, 1, "|") next nCounter END FUNCTION