公司原來做的橫向報表用pb的外部數據源的做的,只支持固定列,列數相當於是在數據窗口中固定好的,橫向的數據項一多,列就支持不了,需要自己在跑到數據窗口中增加,改程序,於是想列的創建能不能改成動態的呢?通過數據窗口的語法工具,發現有辦法:
<DW Control Name>.Modify(& "create column( id=<an integer> tabsequence=<an integer> accelerator='<a single letter>' moveable=<0 - False, 1 - True> resizeable=<0 - Fals...."
然后用edit source打開數據窗口,發現每一列都有對應的語法,
column(band=detail id=1 alignment="0" tabsequence=32766 border="0" color="33554432" x="9" y="8" height="68" width="411" format="[general]" html.valueishtml="0" name=szybh01 visible="1" edit.limit=14 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="宋體" font.height="-9" font.weight="400" font.family="0" font.pitch="2" font.charset="134" background.mode="1" background.color="536870912" )
按理說,通過在該語法的前邊加上create ,然后放到Modify中就可以了,但是沒有效果,
然后通過ls_syntax = adw_main.Describe("datawindow.syntax"),查開語法,列的語法已經在數據窗口的語法中了,原來Modify函數,就是對數據窗口語法的增加或修改的函數,經查看,發現原因是出現在id上,每一個數據窗口的列,對應的是數據窗口語法table中column中的id,而這個id就是列的序號,這樣就需要在table中,將需要增加列到table的語法中,而id就以 Long(adw_main.object.datawindow.column.count) + 1 為開始的id。
這樣算法就確定了
//獲取數據窗口語法 String ls_syntax ls_syntax = adw_main.Describe("datawindow.syntax") Long ll_table_start,ll_table_end //獲取table內容開始的字符串位置 ll_table_start = Pos(ls_syntax, "table(") + len("table(") IF ll_table_start <= 0 THEN as_error = "數據窗口中沒有表數據!" RETURN -1 END IF //獲取table內容的結束位置,以)~r~n)為結束 ll_table_end = Pos(ls_syntax, ")~r~n)",ll_table_start) String ls_table_syntax ls_table_syntax = Mid (ls_syntax,ll_table_start, ll_table_end - ll_table_start + 1) //獲取數據窗口列的個數,確定id Long ll_old_col_count ll_old_col_count = Long(adw_main.object.datawindow.column.count) IF ll_old_col_count <= 0 THEN as_error = "數據窗口中沒有列!" RETURN -1 END IF Long ll_last_colname ll_last_colname = al_last_colname Long ll_add_count ll_add_count = al_add_count IF ll_add_count < 1 THEN as_error = "增加的列數必須大於0" RETURN -1 END IF pfc_n_cst_string lnv_string Long i String ls_col_syntax //增加一般項目字段 //增加table中的字段 FOR i = 1 TO ll_add_count ls_col_syntax = "column=(type=decimal(3) updatewhereclause=no name=xm" + String(ll_last_colname + i) + " dbname=~"xm" + String(ll_last_colname + i) + "~")" ls_col_syntax = "~r~n" + ls_col_syntax IF NOT lnv_string.of_isempty(ls_col_syntax) THEN ls_table_syntax = ls_table_syntax + ls_col_syntax END IF NEXT //把增加的table列寫回到數據窗口的語法中 ls_syntax = Replace (ls_syntax, ll_table_start, ll_table_end - ll_table_start + 1, ls_table_syntax ) String ls_syntax_error adw_main.Create(ls_syntax, ls_syntax_error) IF Len(ls_syntax_error) > 0 THEN as_error = "創建數據窗口出錯!" + ls_syntax_error RETURN -1 END IF
總結:Modify函數是對datawindow語法的修改,數據窗口的每一列,是與table語法中定義的column對應的,這個對應是通過id來實現的,這個id實際上就是table中 column的序號,只要修改datawindow的語法,就能對數據窗口的對象進行修改
