[返回]
中国计算机报2000年第65期

如何创建数据窗口动态列

褚艳玲

  在数据窗口的应用中,开发者有时需要创建动态列,这也是PowerBuilder中的高级技术,下面列举一个具体实例进行分析。

  首先创建一个应用,新建一个窗口,再创建一个外部数据源,类型为Grid型的数据窗口(数据窗口只有一列,记录下数据窗口的x=9、width=384、y=8、height=88),示例如图1。

  图1

  通过窗口上的“创建”按钮,在数据窗口上创建“指定列数”。

  通过窗口上的“插入”按钮,在数据窗口上插入行,每次插入一行。

  定义窗口级实例变量:string is_temp

  图2

  用窗口函数实现数据窗口中列的动态调整,脚本如下:

  // Function Name: wf_dynamic // 

  //Access: Public//

  // Return: Integer//

  // Argument: as_syntax (Type string , Pass by reference)//

  // as_columnname (Type string , Pass by value)//

  // as_id (Type string , Pass by value)//

  // as_columnhead (Type string , Pass by value)//

  string ls_part1,ls_part2,ls_aux

  integer li_position

  constant long cil_posx=393,cil_width=384

  li_position=pos(as_syntax,"text",1)

  ls_part1=left(as_syntax,li_position -4)

  ls_part2=right(as_syntax,len(as_syntax) -li_position+4)

  ls_aux="column=(type=char(20) updatewhereclause=yes name="+as_columnname+" dbname='"+as_columnname+"'"+")"+"~n~r"

  as_syntax=ls_part1+ls_aux+ls_part2

  ls_aux="column(band=detail id="+string(ai_id+1)+" alignment='2' tabsequence="+string(ai_id*10)+" border='0' color='0' x='"+string(cil_posx+cil_width*ai_id)+"' y='8' height='88' width='"+string(cil_width)+"' format='[general]' name="+as_columnname+" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face='Arial' font.height='-9' font.weight='400' font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912' )"

  as_syntax+=ls_aux

  ls_aux="text(band=header alignment='2' text='"+as_columnhead+"' border='0' color='0' x='"+string(cil_posx+cil_width*ai_id)+"' y='8' height='77' width='"+string(cil_width)+"' name="+as_columnname+"_t font.face='Arial' font.height='-9' font.weight='400' font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912' )"

  as_syntax+=ls_aux

  return 0

  “创建”按钮的脚本如下:

  if IsNull(sle_1.Text) or sle_1.Text="" then

   MessageBox("Info","Provide column count")

  end if

  String ls_syntax

  Integer li_id,li_cnt

  Integer li_var

  dw_1.SetRedraw(False)

  dw_1.Create(is_temp)

  ls_syntax = is_temp

  li_cnt = Integer(sle_1.Text)

  ///调用函数

  For li_var = 1 To li_cnt

   wf_dynamic(ls_syntax,"ascol"+String(li_var+1),li_var,"col"+String(li_var+1)+"_t")

  Next

  dw_1.Create(ls_syntax)

  dw_1.SetRedraw(True)

  “插入”按钮的脚本如下:

  dw_1.InsertRow(0)

  “返回”按钮的脚本如下:

  Close(Parent)

  程序实例运行结果如图2。