ehxz 发表于 2007-10-10 16:53:38

[转帖]介绍一些用于提高数据窗口性能的技术

1. &nbsp; 减少连接数据库的次数 &nbsp; <br/>连库操作是非常影响执行速度的操作. &nbsp; 因此在程序中,一旦与数据库连接后就应当尽量保持与数据库的连接, &nbsp; 减少连接数据库的次数.PowerBuilder &nbsp; 提供里两个函数来建立数据窗口与事务对象的连接: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTrans() &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetTransObject() &nbsp; <br/>在程序中应当尽量使用 &nbsp; SETTRANSOBJECT(), &nbsp; 因为SETTRANS() &nbsp; 函数在每次调用 &nbsp; RETRIEVE(), &nbsp; UPDATE() &nbsp; 等函数之后, &nbsp; 都要执行数据库的连接和断开操作. &nbsp; <br/>2. &nbsp; 下拉数据窗口与表的连接 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 对于数据库服务器来说, &nbsp; 表的连接操作是一项非常大的开销, &nbsp; 而 &nbsp; POWERBUILDER &nbsp; 提供的下拉数据窗口在某些情况下可以代替表的连接操作.例如, &nbsp; 为了在数据窗口上显示用户的电话号码和姓名:如果用表的连接的方法, &nbsp; 数据窗口对应的 &nbsp; SQL &nbsp; 语句应是这样的: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp; "DA_DH"."DHHM", &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "DA_HTH"."DWM" &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; "DA_HTH", &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "DA_DH" &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; ("DA_HTH"."DHHM"="DA_DH"."DHHM") &nbsp; <br/>同样的程序可用下拉数据窗口来完成, &nbsp; 这里不再具体介绍.但是, &nbsp; 应当注意, &nbsp; 以上两种方法究竟哪一种数据更快, &nbsp; 与表的结构, &nbsp; 表的数量, &nbsp; 连接的方法等均有关系, &nbsp; 应当具体分析. &nbsp; <br/>3. &nbsp; 共享数据 &nbsp; <br/>在一个应用程序中, &nbsp; 某些数据需要频繁的使用, &nbsp; 如果在每次使用时都从数据库中进行检索, &nbsp; 则需占用大量的服务器资源和网络资源. &nbsp; 为了减少开销, &nbsp; 可以在客户端对这些数据只进行一次检索, &nbsp; 然后允许其它任务共享这些数据. &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 例如, &nbsp; 如果有两个数据窗口, &nbsp; 都需要从第三方表中检索出用户的电话号码, &nbsp; 且此列用下拉数据窗口给出. &nbsp; 如果每次都对电话号码进行检索, &nbsp; 则性能较低. &nbsp; 因此, &nbsp; 可以单独建立一个关于电话号码的数据窗口. &nbsp; 在每次打开窗口时, &nbsp; 首先将电话号码检索到此数据窗口中, &nbsp; 然后另外两个数据窗口中关于电话号码的下拉数据窗口可以共享此数据窗口中的数据. &nbsp; <br/>在窗口的 &nbsp; OPEN &nbsp; 事件中编写如下程序: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_1.settransobject(sqlca) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_2.settransobject(sqlca) &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_3.settransobject(sqlca) &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 检索 &nbsp; dw_1 &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_1.retrieve() &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 使 &nbsp; DW_2 &nbsp; 的下拉数据窗口共享 &nbsp; DW_1 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datawindowchild &nbsp; child1 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_2.getchild( "dhhm ",child1) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child1.settransobject(sqlca) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_1.sharedata(child1) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 使 &nbsp; DW_2 &nbsp; 的下拉数据窗口共享 &nbsp; DW_1 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datawindowchild &nbsp; child2 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_3.getchild( "dhhm ",child2) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child2.settransobject(sqlca) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_1.sharedata(child1) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 使用这种方法, &nbsp; 避免了各个数据窗口间物理的拷贝数据, &nbsp; 因此减少了空间上的开销,提高了应用程序的综合性能. &nbsp; <br/>4. &nbsp; 数据窗口间数据的拷贝 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 如果需要在数据窗口间共享数据, &nbsp; 应当尽量使用 &nbsp; SHAREDATA() &nbsp; 函数, &nbsp; 但是, &nbsp; SHAREDATA() &nbsp; 函数并不是物理地在数据窗口间拷贝数据, &nbsp; 如工在显示数据的同时, &nbsp; 还要对数据进行操作, &nbsp; 则需要进行数据的拷贝. &nbsp; <br/>例如, &nbsp; 要求将 &nbsp; DW_1 &nbsp; 中选定的行拷贝到 &nbsp; DW_2 &nbsp; 中: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 在窗口的 &nbsp; OPEN &nbsp; 事件中编程: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_1.settransobject(sqlca) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_2.settransobject(sqlca) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dw_1.retrieve() &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 在数据窗口 &nbsp; DW_1 &nbsp; 的 &nbsp; ROWFOCUSCHANGED &nbsp; 事件中编写下列程序: &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long &nbsp; lr &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lr &nbsp; = &nbsp; dw_1.selectrow(0,false) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lr &nbsp; = &nbsp; dw_1.getrow() &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lr &nbsp; = &nbsp; dw_1.selectrow(lr,true) &nbsp; <br/>要完成从 &nbsp; DW_1 &nbsp; 到 &nbsp; DW_2 &nbsp; 的拷贝工作, &nbsp; 有两种方法: &nbsp; <br/>第一种: &nbsp; &nbsp; <br/>在按钮 &nbsp; "拷贝" &nbsp; 的 &nbsp; CLICKED &nbsp; 事件中编程 &nbsp; <br/>long &nbsp; lr &nbsp; &nbsp; <br/>lr &nbsp; = &nbsp; dw_1.getselectedrow(0) &nbsp; <br/>dw_1.rowscopy(lr,lr,primary!,dw_2,100,primary!) &nbsp; <br/>执行程序, &nbsp; 利用 &nbsp; POWERBUILDER &nbsp; PROFILER &nbsp; 得出所需时间为 &nbsp; 1.7034(百分之一秒) &nbsp; <br/>第二种: &nbsp; &nbsp; <br/>在按钮 &nbsp; "拷贝" &nbsp; 的 &nbsp; CLICKED &nbsp; 事件中编程 &nbsp; <br/>dw_2.object.data &nbsp; = &nbsp; da_1.object.data.selected &nbsp; <br/>执行程序, &nbsp; 利用 &nbsp; POWERBUILDER &nbsp; PROFILER &nbsp; 得出所需时间为 &nbsp; 0.8062(百分之一秒) &nbsp; <br/>5. &nbsp; 数据窗口属性的访问和修改 &nbsp; <br/>A. &nbsp; 数据窗口属性的访问 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 在程序中访问数据窗口的属性有下列几种方法: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A1. &nbsp; 采用点表达式访问 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A2. &nbsp; 应用多个独立的 &nbsp; DESCRIBE() &nbsp; 函数访问 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A3. &nbsp; 只使用一个 &nbsp; DESCRIBE() &nbsp; 函数, &nbsp; 采用复合参数访问多个属性 &nbsp; <br/>上面三中方法, &nbsp; 通常第一种方法最慢, &nbsp; 第三种方法最快. &nbsp; &nbsp; <br/>例如: &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 在窗口的 &nbsp; OPEN &nbsp; 事件中 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.SETTRANSOBJECT(SQLCA) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.RETRIEVE() &nbsp; <br/>第一种方法: &nbsp; &nbsp; <br/>在检索按钮的 &nbsp; CLICKED &nbsp; 事件中编程. &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; dx, &nbsp; dy, &nbsp; dh, &nbsp; dw &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dx &nbsp; = &nbsp; dw_1.object.da_dh.x &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dy &nbsp; = &nbsp; dw_1.object.da_dh.y &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dx &nbsp; = &nbsp; dw_1.object.da_dh.height &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dy &nbsp; = &nbsp; dw_1.object.da_dh.width &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; st_1.text &nbsp; =dx+","+dy+","+dh+","+dw &nbsp; <br/>第二种方法: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; dx, &nbsp; dy, &nbsp; dh, &nbsp; dw &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dx=dw_1.describe("da_dh.x") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dx=dw_1.describe("da_dh.y") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dx=dw_1.describe("da_dh.height") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dx=dw_1.describe("da_dh.width") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; st_1.text &nbsp; =dx+","+dy+","+dh+","+dw &nbsp; <br/>第三种方法: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; dx, &nbsp; dy, &nbsp; dh, &nbsp; dw &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; st_1.text=dw_1.describe("da_dh.x" &nbsp; +&amp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "da_dh.y" &nbsp; +&amp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "da_dh.height" &nbsp; +&amp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "da_dh.width") &nbsp; <br/>实验证明, &nbsp; 第三种方法的速度是最快的. &nbsp; 但是程序的可读性最差. &nbsp; <br/>B. &nbsp; 数据窗口属性的修改 &nbsp; <br/>在程序中修改数据窗口的属性有下列几种方法: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A1. &nbsp; 采用点表达式修改 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A2. &nbsp; 应用多个独立的 &nbsp; MODIFY() &nbsp; 函数访问 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A3. &nbsp; 只使用一个 &nbsp; MODIFY() &nbsp; 函数, &nbsp; 采用复合参数访问多个属性 &nbsp; <br/>上面三中方法, &nbsp; 通常第一种方法最慢, &nbsp; 第三种方法最快. &nbsp; &nbsp; <br/>例如: &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 在窗口的 &nbsp; OPEN &nbsp; 事件中 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.SETTRANSOBJECT(SQLCA) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.RETRIEVE() &nbsp; <br/>第一种方法: &nbsp; &nbsp; <br/>在检索按钮的 &nbsp; CLICKED &nbsp; 事件中编程. &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.SETREDRAW(FALSE) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.da_dh.x &nbsp; = &nbsp; 18 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.da_dh.y &nbsp; = &nbsp; 16 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.da_dh.height &nbsp; = &nbsp; 100 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.da_dh.width &nbsp; = &nbsp; 200 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.setredraw(true) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; st_1.text &nbsp; =dx+","+dy+","+dh+","+dw &nbsp; <br/>第二种方法: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; DW_1.SETREDRAW(FALSE) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.modify("da_dh.x &nbsp; = &nbsp; 18") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.modify("da_dh.y &nbsp; = &nbsp; 16") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.modify("da_dh.height &nbsp; = &nbsp; 100") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.modify("da_dh.width &nbsp; = &nbsp; 200") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.setredraw(true) &nbsp; <br/>第三种方法: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.modify("da_dh.x=18" &nbsp; +&amp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "da_dh.y=16" &nbsp; +&amp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "da_dh.height=100" &nbsp; +&amp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "da_dh.width=200") &nbsp; <br/>实验证明, &nbsp; 第三种方法的速度是最快的. &nbsp; 但是程序的可读性最差.注意, &nbsp; 在方法一和方法二中, &nbsp; 都使用的 &nbsp; setredraw() &nbsp; 函数以减少屏幕的重绘, &nbsp; 否则, &nbsp; 执行速度将严重下降. &nbsp; <br/>6. &nbsp; 数据窗口中数据的访问 &nbsp; &nbsp; <br/>在程序中, &nbsp; 经常会需要动态的修改数据窗口中的数据. &nbsp; 对此, &nbsp; PB &nbsp; 提供了多种方法, &nbsp; 各种方法在性能上会有一些差异. &nbsp; <br/>A. &nbsp; 数据窗口中数据的访问 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 目的: &nbsp; 将数据窗口中的电话号码存放在一个数组中.请比较下面两中方法. &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 方法一: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; da_dh[] &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; long &nbsp; ll,i &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; ll &nbsp; = &nbsp; dw_1.rowcount() &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; for &nbsp; i &nbsp; = &nbsp; ll &nbsp; to &nbsp; 1 &nbsp; stet &nbsp; -1 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; da_dh &nbsp; = &nbsp; dw_1.getitemstring(i,"dhhm") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; next &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 方法二: &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; da_dh[] &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; da_dh[] &nbsp; = &nbsp; dw_1.object.dhhm.current &nbsp; <br/>测试发现, &nbsp; 第二种方法比第一种方法快将近一倍. &nbsp; 数据量越大这种差异越明显. &nbsp; <br/>B. &nbsp; 数据窗口中数据的修改 &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 目的: &nbsp; 修改数据窗口中的电话号码列的值. &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 请比较下面两中方法. &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 方法一: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.setitem(i,"dhhm",l_name) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 方法二: &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.name &nbsp; = &nbsp; l_name &nbsp; <br/>测试发现, &nbsp; 第二种方法比第一种方法快将近一倍. &nbsp; 数据量越大这种差异越明显. &nbsp; <br/>7. &nbsp; 数据窗口事件对性能的影响 &nbsp; <br/>对于数据窗口控制中经常发生的事件, &nbsp; 应当尽量减少其中的程序代码. &nbsp; <br/>特别是如下事件: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; A. &nbsp; itemchanged &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; b. &nbsp; editchanged &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; c. &nbsp; itemfocuschanged &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; d. &nbsp; pbm_dwnkey &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; e. &nbsp; rowfocuschanged &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; f. &nbsp; retrieverow &nbsp; <br/>在这些事件中的任何处理程序, &nbsp; 都会降低应用程序的处理速度. &nbsp; 所以应当尽量减少这些事件中的处理程序, &nbsp; 必要时, &nbsp; 可以考虑只将重要的代码放在这些事件中, &nbsp; 而将剩余的代码放在一个传递的事件中. &nbsp; <br/>例如,如果需要用到数据窗口的 &nbsp; ROWFOCUSCHANGED &nbsp; 事件,可以为数据窗口定义一用户事件 &nbsp; "UE_RE",而在数据窗口的 &nbsp; ROWFOCUSCHANGED &nbsp; 事件中写如下代码: &nbsp; <br/>&nbsp; &nbsp; &nbsp; PARENT.postevent("ue_re") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; 在 &nbsp; UE_RE &nbsp; 事件中再编写相应的程序代码,如: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; code &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.selectrow(0,false) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.selectrow(rownum,true) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; code &nbsp; = &nbsp; getitemstring(dw_1,rownum,"dhhm") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_2.retrieve(code) &nbsp; <br/>另外, &nbsp; 为了获得当前行号,应尽量使用数据窗口的 &nbsp; CURRENTROW &nbsp; 变量,而少用 &nbsp; GETROW() &nbsp; 函数。 &nbsp; <br/>8、 &nbsp; 数据窗口的列名称与列编号 &nbsp; <br/>对数据窗口的某列进行访问, &nbsp; 可以采用该列的名称, &nbsp; 也可以使用该列的编号, &nbsp; <br/>例如: &nbsp; <br/>采用列编号: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.data &nbsp; <br/>dw_1.getitemstring(3,2) &nbsp; <br/>采用列名称表示某列: &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.object.article_text &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.getitemstring(3,"dhhm") &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; dw_1.setitem(3,"date",1999-03-31) &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; ... &nbsp; <br/>对于以上两种方法, &nbsp; 如果只进行一次查询, &nbsp; 在速度上并没有太大的区别,如过需要循环访问数据窗口上的某一列, &nbsp; 则速度上的差异就表现的比较明显,才用第一种方法要快, &nbsp; 但是程序的可读性比较差。但是, &nbsp; 在使用函数时(如 &nbsp; GETITEM() &nbsp; 和 &nbsp; setitem() &nbsp; ), &nbsp; 执行速度往往没有很大差别。 &nbsp; <br/>9、 &nbsp; 计算域 &nbsp; <br/>数据窗口的计算域会对数据的操作性能产生影响。 &nbsp; 如果数据窗口中包含许多复杂的计算域,将严重影响数据窗口的执行速度。

JohnPhan 发表于 2007-10-11 09:04:08

<p><font face="Courier">string da_dh[]&nbsp;&nbsp; <br/>da_dh[] = dw_1.object.dhhm.current</font></p><p><font face="Courier">这个方法头一次见到. 新奇.</font></p>

28860823 发表于 2007-10-17 00:08:03

这是个好贴哦

lovelyni 发表于 2007-12-19 22:09:42

看看

langzpin 发表于 2007-12-22 23:28:59

<p>顶</p>

miscode 发表于 2008-2-28 12:22:15

<p>好贴</p>

fxyang13 发表于 2008-3-27 21:38:30

<p>高见!学习学习!!!</p>

nxspharm 发表于 2008-5-8 22:22:00

<div class="msgheader">QUOTE:</div><div class="msgborder"><b>以下是引用<i>JohnPhan</i>在2007-10-11 9:04:08的发言:</b><br/>
<p><font face="Courier">string da_dh[]&nbsp;&nbsp; <br/>da_dh[] = dw_1.object.dhhm.current</font></p>
<p><font face="Courier">这个方法头一次见到. 新奇.</font></p></div>
<p>这是直接得到指定列的所有行,不用循环了</p>
页: [1]
查看完整版本: [转帖]介绍一些用于提高数据窗口性能的技术

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com