Populate Code Tables from constants

Link to this posting

Postby Ursego » 24 May 2013, 12:07

Creating a control with a Code Table (like DropDownListBox or RadioButton), populate its Code Table programmatically if constants are defined in the application for the added values (instead of hard-coding in the DataWindow painter). That is done using the SetValue() method of DataWindow.

For example, you have to create a radio button for the field "payment_method" in your DW while constants n_payment_method.CREDIT_CARD (with value "C") and n_payment_method.PAYPAL (with value "P") exist in your system (see here):

Code: Select all
dw_payment.SetValue("payment_method", 1, "Credit Card~t" + n_payment_method.CREDIT_CARD)
dw_payment.SetValue("payment_method", 2, "PayPal~t" + n_payment_method.PAYPAL)

The easiest way is to simply hard-code the values "C" and "P" in the DataWindow painter. But what if those system codes will be changed in the future? In fact, that's why we enjoy constants at all: it's enough to change one value (of the constant itself), and that change automatically spreads out through the whole application, so the existing logic keeps working everywhere. I don't believe you will argue about using constants in PowerScript; but if you use constants only in PowerScript (forgetting about Code Tables and, by the way, SQL SELECTs of DWs, to which the constsant must be sent as parameters), it won't be really "through the whole application"... :cry:

Prefer the correct programming, not the quickest!
User avatar
Site Admin
Posts: 118
Joined: 19 Feb 2013, 20:33

IF you want to ((lose weight) OR (have unbelievable (brain function AND mental clarity))) THEN click:

free counters

eXTReMe Tracker