Delphi How to use the State Property

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,206
Credits
4,037
How to use the State Property
By Muhammad Azizul Hakim June 23, 2021

State property is used as an indicator for which items are selected or checked.

For example, for each member of the Items array, we use State to determine whether the checkbox is selected (cbChecked), cleared (cbUnchecked), or dimmed (cbGrayed).

Note: cbGrayed corresponds to the indeterminate state.

State combines the information provided by the Boolean Checked property and the Boolean ItemEnabled property:
  • When Checked is True, State is cbChecked. However, when Checked is False, State may be either cbUnchecked or cbGrayed.
  • When State is cbGrayed, ItemEnabled is False. However, ItemEnabled may also be False when State is cbUnchecked or cbChecked.)
Another example of a State use case is in Draw Grid creation. State will show us the selected cell in the created grid or table.

Here is the working example of the implementation of State in Draw Grid creation:
Python:
def grdTestDrawCell(Sender, Col, Row, Rect, State):
    if gdSelected in State:
        Sender.Canvas.Brush.Color = clBlue # 0x00ff0000 # blue
        Sender.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, "%d @ %d" % (Col, Row))
 
def grdTestSelectCell(Sender, Col, Row, CanSelect):
    if Col == 2 and Row == 2:
        CanSelect.Value = False
 
grdTest.OnDrawCell = grdTestDrawCell
grdTest.OnSelectCell = grdTestSelectCel
See the complete code Для просмотра ссылки Войди или Зарегистрируйся.

The result:
1624442712904.png
1624442718602.png