For most scenarios, predefined styles stored in the repository will cover application requirements. However, there are situations where dynamic styles are required, for example for font or color selection. In these situations, Styles can be defined and instances created just like any other component, meaning their properties can be set at runtime.
The following shows a color picker dialog when the form is clicked. The selected color is applied to the style and thus to the background of the form:
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_Form) Clientheight(284) Clientwidth(464) Height(323) Left(695) Style(#Style) Top(223) Width(480)
Define_Com Class(#prim_vs.Style) Name(#Style) Normbackcolor(White)
Define_Com Class(#Prim_appl.ICommonDialogColor) Name(#ColorPicker) Reference(*dynamic)
Define_Com Class(#PRIM_LABL) Name(#Label1) Caption('Click form to show color picker') Displayposition(1) Ellipses(Word) Height(25) Left(29) Parent(#COM_OWNER) Tabposition(1) Tabstop(False) Top(29) Verticalalignment(Center) Width(396) Alignment(Center)
Evtroutine Handling(#Com_owner.CreateInstance)
#Com_owner.Cursor <= #sys_appln.Cursors<Hand>
Endroutine
Evtroutine Handling(#Com_owner.Click)
If (#ColorPicker *Is *null)
#ColorPicker <= #sys_appln.CreateColorDialog
#ColorPicker.FullyOpen := true
Endif
#ColorPicker.Show
* Set Com(#Style) Normbackcolor(#ColorPicker.ChosenColor)
#Style.NormBackColor := #ColorPicker.ChosenColor
Endroutine
End_Com