RecordGridのカラム幅をPixcelで取得するには

【ご質問】
レコードグリッド上のカラム幅を任意に伸縮した後に当該カラムの幅をPixcelで取得するには
どのようにしたらよいのでしょうか。

【回答】
カラムの幅は何も処理を加えずに単純に取得するとSI-単位のm(メートル)で返されます。
これをpixelに変換するにはDisplayContext.pixel-sizeを使用して計算する必要があります。

詳細は以下のサンプルをご参照ください。
「First」列のカラム幅をドラッグで適当に変更して
「Savevalue」ボタンを押してください。
「First」列の幅の値がpxで表示されます。

{curl 6.0,7.0,8.0 applet}
{curl-file-attributes character-encoding = “shift-jis”}
{applet
    {compiler-directives
        allow-any-calls? = true,
        allow-implicit-any-casts? = true
    }
}
{import * from  CURL.GRAPHICS.DISPLAY}
{def display = {Display.get-primary}}

{import * from CURL.LANGUAGE.SOURCE}
{let display-context:DisplayContext =
    {get-default-display-context}}

{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField “First”, domain = String},
            {RecordField “Last”, domain = String},
            {RecordField “Age”, domain = int}
        },
        {RecordData First = “John”, Last = “Smith”, Age = 25},
        {RecordData First = “Jane”, Last = “Smith”, Age = 29},
        {RecordData First = “Jane”, Last = “Jones”, Age = 28}
    }
}
{def rgc1 = {RecordGridColumn
                width = 100px,
                “First”}
}
{def rgc2 = {RecordGridColumn width = 2cm,“Last”}}
{def rgc3 = {RecordGridColumn width = 1.5cm,“Age”}}

{let save-width-value:String = {format “%s”,rgc1.width }}

{value
    {VBox
        {RecordGrid
            record-source = people,
            cells-take-focus? = false,
            select-current-record? = true,
            height = 10cm,
            width = 13cm,
            automatic-columns? = false,
            rgc1,
            rgc2,
            rgc3
        },
        {VBox
            {HBox
                {TextDisplay value = “Set-width with cm”},
                {TextField
                    {on ValueFinished at tf:TextField do
                        {if tf.value != “” then
                            set rgc1.width = {evaluate {format “%scm”,tf.value}}
                        }
                        {popup-message
                            tf.value & “cm = “ &
                            {format “%s”,{round rgc1.width / display-context.pixel-size}} &
                            ” px”
                        }
                    }  
                }
            },
            {HBox
                {TextDisplay value = “Set-width with px”},
                {TextField
                    {on ValueFinished at tf:TextField do
                        {if tf.value != “” then
                            ||String型で保存していたので、単位をつけてevaluate
                            set rgc1.width = {evaluate {format “%spx”,tf.value}}
                        }
                    }  
                }  
            }          
        },
        {HBox
            {CommandButton label = “Show width !”,
                {on Action do
                    {popup-message
                        {VBox
                            “rgc1.width = “ & {format “%s”,rgc1.width}
                        }
                    }
                }
            },
            {CommandButton label = “Save value”,
                {on Action do
                    set save-width-value =
                        {if rgc1.width isa PixelDistance then
                            {format “%s”,rgc1.width}
                         else
                            {format “%spx”,{round rgc1.width / display-context.pixel-size}}
                        }
                    {popup-message
                        “saved-value = “ & save-width-value    
                    }
                }
            },
            {CommandButton label = “Restore value”,
                {on Action do
                    set rgc1.width = {evaluate save-width-value}
                }
            }
        }
    }
}