Hi Imran,
There are more choices but some of them are depending from what your component is enabling user to do.
Which Uniface version are you using? This proposal is for U9 or U10.
Going to only optimize the current code: Larry has already pointed out that there is an overhead if the field name include string "PBTN", probably buttons. I try to preserve your logic into this optimized code proposal:
l_fieldnames = $entinfo("entity_nm", "PAINTEDFIELDS")
l_curocc = $curocc (entity_nm)
l_totdbocc = $totocc(entity_nm)
l_rowselectdark = "green"
l_rowselectlight = "white"
forentity "entity_nm"
forlist l_fieldname in l_fieldnames
if ($scan(l_fieldname, "PBTN") = 0)
if ($curocc(l_entity)%2 = 0)
$fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectdark%%%"
else
$fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectlight%%%"
endif
endif
endfor
if ($curocc(entity_nm) = l_totdbocc) break ; this is avoiding to build the whole hitlist
endfor
setocc "entity_nm", l_curocc
You could also try to furtherly improve perf applying the coloring routine only:
- from ($curocc(entity_nm) - $paintedocc(entity_nm)) when greater than zero
- to ($curocc(entity_nm) + $paintedocc(entity_nm)) but not greater than $totocc()
It becomes:
l_fieldnames = $entinfo("entity_nm", "PAINTEDFIELDS")
l_curocc = $curocc (entity_nm)
l_totdbocc = $totocc(entity_nm)
l_startrow = $curocc(entity_nm) - $paintedocc(entity_nm)
if (l_startrow < 1) l_startrow = 1
l_endrow = $curocc(entity_nm) + $paintedocc(entity_nm)
if (l_endrow > l_totdbocc) l_endrow = l_totdbocc
l_rowselectdark = "green"
l_rowselectlight = "white"
setocc "entity_nm", l_startrow
while $status > 0
if ($curocc(l_entity)%2 = 0)
forlist l_fieldname in l_fieldnames
if ($scan(l_fieldname, "PBTN") = 0)
$fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectdark%%%"
endif
endfor
else
forlist l_fieldname in l_fieldnames
if ($scan(l_fieldname, "PBTN") = 0)
$fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectdark%%%"
endif
endfor
endif
if ($curocc(entity_nm) = l_endrow) break
setocc "entity_nm", $curocc(entity_nm) + 1
endwhile
setocc "entity_nm", l_curocc
This last example should always work quite fast (less than 2 secs) everywhere...
Let us know if it help you.
Regards,
Gianni