Thread Rating:
  • 201 Vote(s) - 2.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
同名RecordGridを何度も生成したときの挙動
10-22-2015, 11:31 AM,
#1
同名RecordGridを何度も生成したときの挙動
以下のように呼ばれる度にVboxをクリアして同じ名前のRecordGridを追加するメソッドを作ったのですが、
2回目以降に呼ばれた際にグリッドのヘッダにcaptionの値が表示されません。
同じロジックでRecordGrid.nameを毎回違う名前にすると正常に動作するため、
追加した同名のRecordGridが残り続けていてそれが原因になっているのでは?と思ったのですが、
解決方法がわかりましたらご教授願います。

field package vb-detail-area:VBox
{method private {get-rg first-time?:bool}:void
let fields:{Array-of RecordField} = {new {Array-of RecordField}}
let rgc:{Array-of RecordGridColumn} = {new {Array-of RecordGridColumn}}

{self.vb-detail-area.clear}
{if first-time? then
{rgc.append {RecordGridColumn "row-header"}}
{rgc.append {RecordGridColumn "detail-amount-1"}}
{rgc.append {RecordGridColumn "detail-amount-2"}}
{rgc.append {RecordGridColumn "detail-amount-3"}}
{fields.append {RecordField "row-header", caption = "", domain = String}}
{fields.append {RecordField "detail-amount-1",caption= "初回1"}}
{fields.append {RecordField "detail-amount-2",caption= "初回2"}}
{fields.append {RecordField "detail-amount-3",caption= "初回3"}}
else
{rgc.append {RecordGridColumn "row-header"}}
{rgc.append {RecordGridColumn "detail-amount-1"}}
{rgc.append {RecordGridColumn "detail-amount-2"}}
{rgc.append {RecordGridColumn "detail-amount-3"}}
{rgc.append {RecordGridColumn "detail-amount-4"}}
{fields.append {RecordField "row-header", caption = "", domain = String}}
{fields.append {RecordField "detail-amount-1",caption= "2回目1"}}
{fields.append {RecordField "detail-amount-2",caption= "2回目2"}}
{fields.append {RecordField "detail-amount-3",caption= "2回目3"}}
{fields.append {RecordField "detail-amount-4",caption= "2回目4"}}
}
{self.vb-detail-area.add
{RecordGrid width = {make-elastic}, height = 165px, name = "rg-detail-1", {splice rgc}}
}

set self.rg-detail-1 = {g "rg-detail-1"} asa RecordGrid
set self.rg-detail-1.record-source = {RecordSet {RecordFields {splice fields}}}
}


Reply
10-22-2015, 12:26 PM,
#2
RE: 同名RecordGridを何度も生成したときの挙動
問題が起きているコードの一部抜粋のようなので推測ですが、
get-rgメソッドの中でfield vb-detail-areaに新しいRecordGridを格納した
Vboxをセットしていますが、これは画面に反映されていないようにも見えます。

また、下段で既に画面に追加されているRecordGridを取得して、record-sourceを
更新しているように見受けられますが、このRecordGridのヘッダを更新するのが
目的でしたら、Vboxごと入れ替えずに下記のコードで変更できないでしょうか?
Code:
set self.rg-detail-1 = {g "rg-detail-1"} asa RecordGrid
   set self.rg-detail-1.columns = rgc
   set self.rg-detail-1.record-source = {RecordSet {RecordFields {splice fields}}}
Reply
10-22-2015, 12:50 PM,
#3
RE: 同名RecordGridを何度も生成したときの挙動
実現したかったことはこんな感じでしょうか?

Code:
{curl 8.0 applet}

{def rg = {RecordGrid}}

{define-proc {set-columns-and-fields
                 rg:RecordGrid,
                 first-time?:bool = false
             }:void
    let fields:{Array-of RecordField} = {new {Array-of RecordField}}
    let rgc:{Array-of RecordGridColumn} = {new {Array-of RecordGridColumn}}
    
    {if first-time? then
        {rgc.append {RecordGridColumn "row-header"}}
        {rgc.append {RecordGridColumn "detail-amount-1"}}
        {rgc.append {RecordGridColumn "detail-amount-2"}}
        {rgc.append {RecordGridColumn "detail-amount-3"}}
        {fields.append {RecordField "row-header", caption = "", domain = String}}
        {fields.append {RecordField "detail-amount-1",caption= "初回1"}}
        {fields.append {RecordField "detail-amount-2",caption= "初回2"}}
        {fields.append {RecordField "detail-amount-3",caption= "初回3"}}
     else
        {rgc.append {RecordGridColumn "row-header"}}
        {rgc.append {RecordGridColumn "detail-amount-1"}}
        {rgc.append {RecordGridColumn "detail-amount-2"}}
        {rgc.append {RecordGridColumn "detail-amount-3"}}
        {rgc.append {RecordGridColumn "detail-amount-4"}}
        {fields.append {RecordField "row-header", caption = "", domain = String}}
        {fields.append {RecordField "detail-amount-1",caption= "2回目1"}}
        {fields.append {RecordField "detail-amount-2",caption= "2回目2"}}
        {fields.append {RecordField "detail-amount-3",caption= "2回目3"}}
        {fields.append {RecordField "detail-amount-4",caption= "2回目4"}}
    }
    
    set rg.columns = rgc
    set rg.record-source = {RecordSet {RecordFields {splice fields}}}
}

{value
    {VBox
        rg,
        {CommandButton
            label = "1回目",
            {on Action do
                {set-columns-and-fields
                    rg,
                    first-time? = true
                }
            }
        },
        {CommandButton
            label = "2回目",
            {on Action do
                {set-columns-and-fields
                    rg,
                    first-time? = false
                }
            }
        }
    }
}
Reply
10-22-2015, 05:12 PM,
#4
RE: 同名RecordGridを何度も生成したときの挙動
回答ありがとうございます。
回答内容でグリッドヘッダー、カラム数等は変更できる事を確認しました。
が、もう1つやりたい事がありまして実際はRecordGridColumnGroupがあり”set rg.columns = rgc”では設定できません。RecordGridColumnGroupの設定方法がありましたら、ご教示下さい。

Reply
10-22-2015, 06:15 PM,
#5
RE: 同名RecordGridを何度も生成したときの挙動
CurlドキュメントのRecordGridのcolumns (アクセサ)の説明をみると
「列グループを維持するには、代わりに RecordGrid.base-columns を使用します。」とあるので

・セット先をRecordGrid.columns →RecordGrid.base-columnsに変更、
・base-columns (アクセサ)の型が{Array-of BaseRecordGridColumn}なので、格納変数rgcの型も変更

とすれば、RecordGridColumnGroupもBaseRecordGridColumnを継承しているので指定できるように
なるかと思います。

こんな感じになるのでは

Code:
{curl 8.0 applet}

{def rg = {RecordGrid}}

{define-proc {set-columns-and-fields
                 rg:RecordGrid,
                 first-time?:bool = false
             }:void
    let fields:{Array-of RecordField} = {new {Array-of RecordField}}
    let rgc:{Array-of BaseRecordGridColumn} = {new {Array-of BaseRecordGridColumn}}
        
    {if first-time? then
        {rgc.append {RecordGridColumn "row-header"}}
        {rgc.append
            {RecordGridColumnGroup
                "group1",
                {RecordGridColumn "detail-amount-1"},
                {RecordGridColumn "detail-amount-2"},
                {RecordGridColumn "detail-amount-3"}
            }
        }
        
        {fields.append {RecordField "row-header", caption = "", domain = String}}
        {fields.append {RecordField "detail-amount-1",caption= "初回1"}}
        {fields.append {RecordField "detail-amount-2",caption= "初回2"}}
        {fields.append {RecordField "detail-amount-3",caption= "初回3"}}
     else
        {rgc.append {RecordGridColumn "row-header"}}
        {rgc.append
            {RecordGridColumnGroup
                "group1",
                {RecordGridColumn "detail-amount-1"},
                {RecordGridColumn "detail-amount-2"}
            }
        }
        {rgc.append
            {RecordGridColumnGroup
                "group2",
                {RecordGridColumn "detail-amount-3"},
                {RecordGridColumn "detail-amount-4"}
            }
        }
        
        {fields.append {RecordField "row-header", caption = "", domain = String}}
        {fields.append {RecordField "detail-amount-1",caption= "2回目1"}}
        {fields.append {RecordField "detail-amount-2",caption= "2回目2"}}
        {fields.append {RecordField "detail-amount-3",caption= "2回目3"}}
        {fields.append {RecordField "detail-amount-4",caption= "2回目4"}}
    }
    
    set rg.base-columns = rgc
    set rg.record-source = {RecordSet {RecordFields {splice fields}}}
}

{value
    {VBox
        rg,
        {CommandButton
            label = "1回目",
            {on Action do
                {set-columns-and-fields
                    rg,
                    first-time? = true
                }
            }
        },
        {CommandButton
            label = "2回目",
            {on Action do
                {set-columns-and-fields
                    rg,
                    first-time? = false
                }
            }
        }
    }
}
Reply
10-22-2015, 07:31 PM,
#6
RE: 同名RecordGridを何度も生成したときの挙動
早々の回答ありがとうございます。
さっそく試してみます。
Reply
10-22-2015, 09:08 PM,
#7
RE: 同名RecordGridを何度も生成したときの挙動
ありがとうございました。
思い通りの処理が出来ました。

Reply

Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('1270')