PFC 图解

PFC是什么?

Powerbuilder Foundation Class

PFC就是Sybase公司给我们做好的混凝土预制件(即扩展的对象),我们可以拿来用,这些对象具有新的功能,使我们在开发过程中事半功倍。

样例在以下环境通过:

1.  服务器:        Windows 2000 Server

2.  客户端:        Windows 2000 Professtion

3.  网络:          100兆以太网

4.  数据库系统: MS SQL Server 2000

5.  数据库:        pubs

6.  工具:          Powerbuilder 8.0.3 9704

7.  联接:          直接联接

安装PFC:

如果没有安装PFC,则要自定义安装

(图 1) 

PFC 图解 - limindo - 风雨无阻

 

PFC 图解 - limindo - 风雨无阻

 

(图2)

如图1,图2的高亮度选择,将PFC安装到系统中。

PFC 图解 - limindo - 风雨无阻

 (图3)

这样将会在系统的安装路径下面看到PFC文件夹。如图3

在PFC文件夹里面有11个.pbl文件,我们将用到其中的10个文件,pfcapp.pbl不用。

如表一

pfcapsrv.pbl      

     

        

pfcdwsrv.pbl

         

                  

pfcmain.pbl

 

 

pfcutil.pbl

 

 

pfcwnsrv.pbl

 

 

pfepsrv.pbl

 

 

pfedwsrv.pbl

 

 

pfemain.pbl

 

 

pfeutil.pbl

 

 

pfewnsrv.pbl

 

 

为了使用方便,可以将这10个文件拷贝到待开发的程序文件夹下面。例如:D:\study

其中的5个PFC开头的文件是PFC的基础层类库,而PFE开头的5个文件是PFC的扩展层,PFE文件在使用中不是必需的,但是考虑到今后的升级,强烈建议使用PFE文件,如果需要对PFC进行扩展或对属性进行修改,也要在PFE文件库中进行。

搭建PFC应用程序框架:

PFC 图解 - limindo - 风雨无阻

 (图4)

我们从一个实际应用开始详细的介绍PFC程序的开发,首先我们建立一个工作空间(workspace),名字叫study。如图4

PFC 图解 - limindo - 风雨无阻

 (图5)

建立一个目标名为study,选中第二项,即模板项。如图5

PFC 图解 - limindo - 风雨无阻

 (图6)

PFC 图解 - limindo - 风雨无阻

 (图7)

PFC 图解 - limindo - 风雨无阻

 (图8)

PFC 图解 - limindo - 风雨无阻
 

 (图9)

这里是关键,一定要选择第三项。如图9

PFC 图解 - limindo - 风雨无阻

 (图10)

将PFC的10个类库加进去。

PFC 图解 - limindo - 风雨无阻

 (图11)

PFC 图解 - limindo - 风雨无阻

 (图12)

PFC 图解 - limindo - 风雨无阻

 (图13)

PFC的基本框架就搭建起来了,这里就是我们PFC的家。如图13

但是这只是一个框架,还不能运行,我们还要做一些工作才可以。

PFC 图解 - limindo - 风雨无阻

 (图14)

PFC 图解 - limindo - 风雨无阻

 (图15)

从pfemain.pbl库文件中继承窗口名字叫w_frame_app,继承对象为w_frame,(也可以直接使用w_frame窗口),如图14、图15

 

PFC 图解 - limindo - 风雨无阻

 (图16)

PFC 图解 - limindo - 风雨无阻

 (图17)

从pfeapsrv.pbl库文件中继承用户对象名字叫u_cst_appmanager,继承对象为n_cst_appmanager,(也可以直接使用n_cst_appmanager),并且在u_cst_appmanager的pfc_open事件中添加脚本:

open(w_frame_app)

如图16、图17

PFC 图解 - limindo - 风雨无阻

 (图18)

PFC 图解 - limindo - 风雨无阻

 (图19)

打开应用程序对象,将全局变量定义中的n_cst_appmanager改为u_cst_appmanager。

将open事件中脚本的n_cst_appmanager改为:

u_cst_appmanager

如图19

PFC 图解 - limindo - 风雨无阻

 (图20)

这个时候,程序就可以运行了。如图20

PFC 图解 - limindo - 风雨无阻

 (图21)

PFC 图解 - limindo - 风雨无阻

 (图22)

好像标题栏缺少点什么?不要着急,u_cst_appmanager对象的constructor事件中写脚本:

iapp_object.DisplayName="PFC 应用程序"

引号里面的内容,各位自便。iapp_object.DisplayName是应用对象(application)的一个属性,PFC在运行的时将这个属性带进窗口的title属性。如图21、图22

PFC 图解 - limindo - 风雨无阻

 (图23)

从pfemain.pbl库文件中继承窗口对象名字叫w_sheet_authors,继承对象为w_sheet,(也可以直接使用w_sheet)。如图23

PFC 图解 - limindo - 风雨无阻

 (图24)

PFC 图解 - limindo - 风雨无阻

 (图25)

使用我们自己的菜单,从pfewnsrv.pbl库文件中继承菜单对象名字叫m_frame_app,继承对象为m_frame,(也可以直接使用m_frame)。在菜单的基本数据项的clicked事件下写脚本:

message.stringparm = 'w_sheet_authors'

of_sendmessage('pfc_open')

如图24、图25

PFC 图解 - limindo - 风雨无阻

 (图26)

将窗口w_frame_app的菜单指定为m_frame_app。在窗口的pfc_open事件下面写脚本:

string ls_sheet

w_sheet lw_sheet

ls_sheet = message.stringparm

opensheet(lw_sheet,ls_sheet,this,0,original!)

如图26

PFC 图解 - limindo - 风雨无阻

 (图27)

运行后的结果。如图27

到此为止,我们开始近距离接触PFC了。脚本:

message.stringparm = 'w_sheet_authors'

of_sendmessage('pfc_open')

就是利用了PFC的消息路由器将菜单m_frame_app的指令传给了窗口w_frame_app,在传递过程中指明了一个字符串和一个事件,例子中就是传递了w_sheet_authors字符串,指明调用w_frame_app窗口的pfc_open事件。

如果所调用的事件没有参数,则直接使用of_sendmessage('事件名')

数据库联接:

PFC 图解 - limindo - 风雨无阻

 (图28)

PFC有个登录窗口,在pfe_apsrv.pbl库中,名为w_logon,我们在u_cst_appmanager的pfc_open事件添加脚本:

       if of_logonDLG() <> 1 then halt close

这时候我们运行程序,就会弹出登录对话框。但是这个对话框只能接收用户提供的登录名和口令,更多的连接信息要在要在u_cst_appmanager的pfc_logon事件中完成。

PFC 图解 - limindo - 风雨无阻

 (图29)

我们在u_cst_appmanager的pfc_logon事件中添加脚本:

integer li_rc

SQLCA.DBMS = "MSS Microsoft SQL Server"

SQLCA.Database = "pubs"

SQLCA.LogPass = as_password

SQLCA.ServerName = "127.0.0.1"

SQLCA.LogId = as_userid

SQLCA.AutoCommit = False

SQLCA.DBParm = ""

li_rc = SQLCA.of_connect()

if li_rc = 0 then return 1

return li_rc

如图29

这样就可以连接到数据库上了。

PFC 图解 - limindo - 风雨无阻

 (图30)

其中登录窗口w_logon有个ii_logonattempts实例变量,缺省值为1。我们可以更改变量ii_logonattempts的值,来确定错误登录次数。如图30

PFC 图解 - limindo - 风雨无阻

 (图31)

但是这样后有一些不足,就是联接信息不能更改,所以我们要引入ini文件或注册表来更改和保存保存联接信息。在u_cst_appmanager的is_userinifile变量里面指定ini文件,要确保当前目录下有一个setup.ini文件,名字一定要保持一致(不一定是setup.ini)。如图31

pfc默认的是在注册表中取联接信息并在联接成功后将连接信息写回到注册表中。下面是u_cst_appmanager的of_logondlg函数关于写回联接信息的脚本(是pfc的脚本,不是我们要添加的脚本):

lnv_logonattrib = message.powerobjectparm

if Len (lnv_logonattrib.is_userid) > 0 then

              if of_IsRegistryAvailable() then

                     RegistrySet (is_userkey + "\logon", "userid", lnv_logonattrib.is_userid)

       else

                     SetProfileString (is_userinifile, "logon", "userid", lnv_logonattrib.is_userid)

       end if

              of_SetUserID (lnv_logonattrib.is_userid)

end if

return lnv_logonattrib.ii_rc

其中is_userinifile就是我们指定的ini文件名。

我们在这里主要介绍以ini文件的方式读取和保存联接信息的方法。

PFC 图解 - limindo - 风雨无阻

 (图32)

在u_cst_appmanager的of_isregistryavaliable函数下面添加脚本:

Return False

如图32

因为pfc应用在windows操作系统环境中是使用注册表来读取和保存信息,Return False脚本将应用改为使用ini文件来读取和保存信息。

PFC 图解 - limindo - 风雨无阻

 (图33)

在setup.ini文件里面添加脚本:

[logon]

DBMS = "MSS Microsoft SQL Server"

Database = "pubs"

UserID = sa

LogPass =

ServerName = "127.0.0.1"

AutoCommit = False

DBParm = ""

如图33

PFC 图解 - limindo - 风雨无阻

 (图34)

我们将u_cst_appmanager的pfc_logon事件脚本替换成下面的脚本:

integer li_rc

SQLCA.DBMS           = ProfileString (is_userinifile, "logon","DBMS", "")

SQLCA.Database        = ProfileString (is_userinifile, "logon","Database", "")

SQLCA.ServerName   = ProfileString (is_userinifile, "logon","ServerName", "")

SQLCA.DBParm               = ProfileString (is_userinifile, "logon","DBParm", "")

SQLCA.LogId            = as_userid

SQLCA.LogPass         = as_password

SQLCA.AutoCommit        = false

li_rc = SQLCA.of_connect()

if li_rc = 0 then return 1

return li_rc

如图34

这样我们就可以通过更改setup.ini文件来实现不同的连接。

PFC 图解 - limindo - 风雨无阻

 (图35)

如果要用注册表读取或保存信息,则要在is_userkey变量指明注册表项。如图35

需要特别说明的是,u_cst_appmanager的pfc_prelogondlg事件在setup.ini文件中或在用户指定的注册表项中未能得到userid时,则会调用API函数在操作系统注册表中读取操作系统的登录名。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
运行效果 http://hi.csdn.net/attachment/201012/9/0_1291865794j998.gif ************************************************************************* PowerBuilder Foundation Class Library Version 9.0 R E L E A S E N O T E S Copyright ?1996-2003 Sybase, Inc. and its subsidiaries. All rights reserved. ************************************************************************* Last Updated: January 17, 2003 ************************************************************************* Please take a few minutes to review this file for fixes that were made in PowerBuilder 8.0.2 and 9.0. ************************************************************************* BUG FIXES IN PFC 9.0 ************************************************************************* CR300376 Object: pfc_n_cst_fileSrv, pfc_n_cst_fileSrvwin32 Method: OfGetDiskSpace Fix: Method returned a negative number when the calculated amount of free disk space exceeded 2 gigabytes. Added new method of_GetDiskSpaceEx that takes decimals as arguments instead of longs. of_GetDiskSpace will be obsolete in a future release. ************************************************************************* BUG FIXES IN PFC 8.0.2 ************************************************************************* PFC.PBR CR256529 Fix: The PFC.PBR file can be used to copy bitmaps and dynamically referenced DataWindow objects into the executable file for deployment. The following bitmap files that were removed from PFC have now been removed from the PFC.PBR file: details.bmp, helptop.bmp, largeico.bmp, listv.bmp, and smallico.bmp. ======================================================== PFC DataStore CR261992 Object: pfc_u_ds Method: pfc_print/pfc_printdlg Fix: Changed the return code test to check for 1 on success, otherwise there is an error or the user cancelled. Fix: Set the
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值