Advantages and drawbacks of the Modify method

Using the Modify method to access property values of a DataWindow object has advantages and drawbacks.

Advantages

You can set several properties in a single call to Modify, resulting in less code than multiple invocations of SetProperty or multiple assignments to a GraphicObject class instance.

For example, this code, which sets three properties to constant values, is not too complex:

rtn = DW1.Modify("emp_id.Font.Italic=0
      oval_1.Background.Mode=0
      oval_1.Background.Color=255");

In some cases, setting multiple properties at once is desirable from a performance standpoint. Dynamic crosstab manipulation is a specific case of this, since the crosstab might be destroyed and recreated when certain properties are adjusted. Supplying all properties in one Modify call ensures that the reconstruction of the crosstab occurs only once.

In comparison with setting GraphicObject properties, a Modify (or SetProperty) call might be the only recourse if the specific DataWindow control property has not been exposed as a property on a GraphicObject class.

Drawbacks

Modify can require complex quoted strings. When you specify an expression for a property value, it is difficult to specify nested quotes correctly—the code is hard to understand and prone to error.

For example, this string assigns a DataWindow expression to the Color property:

DW1.Modify("emp_id.Color=\"16777215 \t
      If(emp_status=~\"A~\",255,16777215)\"");

Compare that to the following code, which uses an explicit property of the GraphicObjectColumn class:

Dim colEmpID As Sybase.DataWindow.GraphicObjectEditableColumn

colEmpID = CType(DW1.GetObjectByName("emp_id"), GraphicObjectEditableColumn)

colEmpID.TextColor.Expression = "if(emp_status = 'A', 255, 16777215)"

If you want to use the Modify method to change multiple properties, one technique you can use is to test your code using separate calls to SetProperty, change them from SetProperty to Modify calls when each property is being set correctly, then concatenate the strings in the Modify calls to make a single Modify call.

For more information about quoted strings, see “Nested strings and special characters for DataWindow object properties”.