📄 pfc详细教程.txt
字号:
RU菜单项。
使用MRU Service步骤
1. 调用n_cst_appmanager中的of_SetMRU函数开启MRU Service 。
gnv_app.of_SetMRU(TRUE)
2. 调用n_cst_appmanager的函数of_SetUserKey(尽适用于WIN95与WINNT)或of
_SetUserINIFile函数(使用于所有的平台)确定需要保留的信息。下面的例子假
设你已经为n_cst_appmanager建立好了的用户键(保存到注册表)或者INI文件(
保存到INI文件)。下面的代码位于应用程序管理器(n_cst_appmanager)的构造
事件。
IF this.of_IsRegistryAvailable() THEN
this.inv_mru.of_SetUserKey(this.of_GetUserKey())
ELSE
this.inv_mru.of_SetUserINIFile(this.of_GetUserINIFile())
END IF
3. Register IDs with the MRU service by calling the n_cst_mru of_Regis
ter function. An ID is the identifier that the window will use to retr
ieve information out of the MRU service. This is an example of code yo
u can add to the pfc_PreOpen event of the MDI frame window:
IF IsValid(gnv_app.inv_mru) THEN gnv_app.inv_mru.of_Register("myapp")
END IF
4. Extend the pfc_MRUProcess event in each window that uses exclusive
processing, adding code to open the sheet passing the necessary argume
nts (be sure to add similar code to the frame window if you want to sp
ecify exclusive items on the frame menu):
Window lw_frame, lw_window n_cst_menu lnv_menu n_cst_mruattrib lnv_mru
attrib // Check parameters. IF IsNull(ai_row) THEN Return -1 END IF
IF NOT IsValid(gnv_app.inv_mru) THEN Return -1 END IF // Retrieve row
from DataStore. gnv_app.inv_mru.of_GetItem & (ai_row, lnv_mruattri
b) // Get the MDI frame, if necessary. lnv_menu.of_GetMDIFrame(this.me
nuid, lw_frame) OpenSheet(lw_window, & lnv_mruattrib.is_classname,
lw_frame) Return 1
Performing other actions in the pfc_MRUProcess eventTo see other types
of processing you can perform in the pfc_MRUProcess event, see the co
mments in the pfc_w_master pfc_MRUProcess event.5Extend the pfc_PreMRU
Save event in each window that uses the MRU service. In this event, po
pulate the n_cst_mruattrib object with the id, classname, key, item, a
nd MicroHelp to be saved:
anv_mruattrib.is_id = "myapp" anv_mruattrib.is_classname = this.ClassN
ame() anv_mruattrib.is_menuitemname = this.Title anv_mruattrib.is_menu
itemkey = this.ClassName() anv_mruattrib.is_menuitemmhelp = & "O
pens " + this.Title Return 1 6Extend the pfc_MRURestore event in eac
h window that uses the MRU service. In this event, set the ID of the i
nformation you want to display on the menu:
If IsValid(gnv_app.inv_mru) Then Return gnv_app.inv_mru.of_Restore
("myapp", This) End If
5. Error message service
概要
Error Message service提供了许多用于显示、纪录应用程序的错误信息。你既可
以显示PowerBuilder提供的标准的Message对话框,也可以显示PFC的W_Message对
话框。两种显示效果都具有如下的功能:
l_ 消息日志:将消息纪录到文件中,支持多种平台。PFC会自动的将严重级别大
于某个值的消息纪录到文件中。
l_ 支持MAPI:通过Email发出错误警告。PFC会自动将严重级别大于某个值的消息
作为邮件发出。
l_ 消息数据库:通过已经定义好的形式(可以是数据库或文件)来存取消息。定
义好了消息格式,使得消息有一种标准的形式、消息的重复减到最少、容易查询
。
l_ 参数替代:消息可以具有参数,这样它会依据程序运行而变化。
l_ 不显示,直接纪录:消息可以不显示直接纪录到日志中。
l_ 注释与打印:用户可以打印消息,甚至可以增加注释。对消息日志用于邮件时
非常有用的。
l_ 自动关闭:w_message过了数秒后会自动关闭。
W_message 位图
如果你使用w_message ,位图在运行时必须有效。
用法
Error service可以处理应用程序所有的错误信息。如果你打算将错误信息保存到
数据库中,你可以使用PFC.DB中关于消息的几个表,或使用消息管道将它传到你
的数据库中。
使用Messages表
大多数情况下,你应该将Messages表复制到你的数据库中。这个表已经包含了PF
C的错误信息格式。
使用步骤:
1. 调用n_cst_appmanager的of_SetError函数开启error message service(创建
n_cst_error实例),下面的代码位于n_cst_appmanager的pfc_Open事件:
this.of_SetError(TRUE)
2. 定义错误消息的源:
l_ 如果消息源是文件,调用如下函数:
this.inv_error.of_SetPredefinedSource(揷:\eisapp\eiserr.txt?
l_ 如果消息源是数据库,调用如下函数:
this.inv_error.of_SetPredefinedSource (itr_error)
消息源:当你使用文件作为消息源时,文件中必须包括PFC.DB中Messages表中的
所有数据。同时列必须由TAB键隔开。
PFC uses predefined messages in certain situations. If you enable the
error message service and receive message display errors, make sure th
e error message source has been established correctly. Additional user
-defined messages must conform to the format of the messages table (al
so used by the d_definedmessages DataWindow object).
l_ (可选)设置日志文件名(调用函数of_SetLogFile参数为空字符串可以不进
行日志纪录):
this.inv_error.of_SetLogFile(擟:\pb6\errlog.txt敚?
l_ (可选)设置用户ID(用于日志文件):
this.inv_error.of_SetUser(this.of_GetUserID())
l_ (可选)设置什么类型的消息需要自动纪录:
this.inv_error.of_SetNotifySeverity(5)
this.inv_error.of_SetLogSeverity(4)
l_ (可选)如果你的应用程序使用了错误自动通告功能。你需要设置当前用户的
Email、密码。还可以设置其他的Email用户与密码。下面的例子展示了如何设置
Email ID与Password 。
this.inv_error.of_SetNotifyConnection(ims_mailsess) this.inv_error.of
_SetNotifyWho(is_autonotify)
说明:以上的代码都可以在n_cst_appmanager的pfc_Open事件中。
l_ 在应用程序的错误检测中,使用函数of_Message显示对话框。同时你还可以将
它纪录到日志中。函数of_Message可以使用数据库中的消息,也可以动态的指定
消息。下面的例子就是使用数据库中的消息:
gnv_app.inv_error.of_Message(擡IS0210敚?
使用参数表(只限于已定义的消息)
1. 在消息表中定义如下的数据。%运行时将被替换:
EIS1030 Unable to find the file % in %
2. 定义一个参数数组:
String ls_parms[]
ls_parms[1] = 揕ogfile.txt?
ls_parm[2] = 揷:\windows\system?
3. 调用of_Message ,传递参数:
gnv_app.inv_error.of_Message(擡IS1030敚琹s_parms)
PFC在显示消息时使用数组中的第一个元素替换第一个% ,第二元素替换第二个%
。
6. Security service
概要
PFC的安全机制可以处理许多你的应用程序安全性问题。它包括应用程序管理员组
件、安全对象(security object)n_cst_security 。
用法:在使用Security service时,你必须要定义用户组与用户,然后分别与窗
口、菜单、用户对象、控件相关联,然后再编写代码。
使用步骤:
1. 定义用户、用户组。参考第七章擯FC Utilities?
为你的窗口控件、菜单、用户对象、其他控件定义安全属性。参考第七章擯FC
Utitities?
2. 调用n_cst_appmanager的of_SetSecurity函数创建安全对象
this.of_SetSecurity(TRUE)
3. 为安全对象建立一个事务对象。
Itr_sec = Create n_tr
Connect using itr_sec;
4. 调用函数of_InitSecurity初始化安全对象。
This.inv_security.of_InitSecurity(itr_sec.擡ISAPP敚琯nv_app.of_GetU
serID(),擠EFAULT敚?
5. 以上的代码全部在n_cst_appmanager的pfc_Open事件中编写。
6. 应用程序关闭时,断开事务对象的连接、删除事务对象。以下的例子在n_cst
_appmanager的pfc_Close事件中。
Disconnect using itr_sec;
Destroy itr_sec
7. 在你需要使用安全对象的窗口的Open事件或pfc_PreOpen事件中调用函数of_S
etSecurity()
IF NOT gnv_app.inv_security.of_SetSecurity(this) THEN
MessageBox("Security","Unable to set security")
Close(this)
End if
说明:你可以在其他对象(Datawindow、可视用户对象、菜单,所有你想实现安
全机制的对象)。
7. Transaction registration service
概要
Transaction registration service可以追踪你的应用程序中的事务对象的使用
过程。这个服务只对基于n_tr的对象有效。PFC使用n_cst_trregistration对象实
现Transaction registration service 。
用法
当应用程序中使用多个事务对象时,你应该使用Transaction registration ser
vice跟踪所有的事务对象。当你的应用程序关闭时,该对象将会自动删除所有已
注册的事务对象。使用n_tr的函数of_SetAutoRollback设置ib_autorollback的值
。如果ib_SetAutoRollback的值为False ,则事务对象关闭时将会自动提交。如
果ib_SetAutoRollback的值为True ,则事务对象关闭时会自动回滚。
启动 Transaction registration service
l_ 调用n_cst_appmanager的of_SetTrRegistration函数
gnv_app.of_SetTrRegistration(True)
当应用程序关闭时,应用程序会自动删除 Trasaction registration service 。
注册事务对象:
l_ 调用n_cst_trregistration的of_Register函数
gnv_app.inv_trregistration.of_Register(SQLCA)
控制当事务对象正处于连接时被删除时的行为
l_ 调用n_tr的of_SetAutoRollback函数
SQLCA.of_SetAutoRollback(True)
如果你设置为True ,同时该对象正处于连接状态,当它被删除时Service会回滚
该事务。如果你设置为False ,Service回提交该事务。尽管如此,你应该显示的
提交或回滚、断开连接。
2 Datawindow服务
概要
大部分的PowerBuilder的应用程序都大量的使用了Datawindow控件。PFC因此提供
了功能强大的Datawindow Services 。大部分的Service使用时只需一点代码或者
根本不需要编码。PFC的Datawindow Servies实际上都是由一个公共的父类对象(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -