例如访问全局变量、使用PB所有的系统函数、使用程序员开发的自定义函数、打开窗口、访问菜单、使用数据窗口等。
七.通常将本PB动态脚本解释器嵌入到现有的使用PB开发出来的系统而不是单独使用,这样可以加载很多免编译的外挂程序。
八.如果再拓宽它的应用范围,你甚至可以做到只需要一个框架程序,其它代码全部动态加载和执行,这样就只需一次编译,升级和维护就变得非常简单,不过你
要考虑
系统的可用性、系统性能和系统的稳定性等。
附完整
源代码 一.pbcompiler
$PBExportHeader$pbcompiler.sra
$PBExportComments$PB动态脚本解释器应用对象
forward
global type pbcompiler from application
end type
global transaction sqlca
global dynamicdescriptionarea sqlda
global dynamicstagingarea sqlsa
global error error
global message message
end forward
global variables
end variables
global type pbcompiler from application
string appname = "pbcompiler"
end type
global pbcompiler pbcompiler
on pbcompiler.create
appname="pbcompiler"
message=create message
sqlca=create transaction
sqlda=create dynamicdescriptionarea
sqlsa=create dynamicstagingarea
error=create error
end on
on pbcompiler.destroy
destroy(sqlca)
destroy(sqlda)
destroy(sqlsa)
destroy(error)
destroy(message)
end on
event open;open(w_pbcompiler_test)
end event
二.f_execpbscript
$PBExportHeader$f_execpbscript.srf
$PBExportComments$执行动态脚本的样例函数
global type f_execpbscript from function_object
end type
forward prototypes
global function string f_execpbscript (string as_returntype, string as_pbscript)
end prototypes
global function string f_execpbscript (string as_returntype, string as_pbscript);/*******************************************************************
函数名称:f_execpbscript()
参数: as_returntype string 返回值类型
as_pbscript string 动态代码
返回值: string 用户自定义或错误信息
功能描述:执行动态代码(只返回字符串)
创建人: 康剑民
创建日期:2007-02-12
版本号: V1.0
*******************************************************************/
nvo_pbcompiler lnv_pbcompiler
nonvisualobject luo_pbcompiler
string ls_entryname,ls_libraryname
string ls_return
any la_return
lnv_pbcompiler = create nvo_pbcompiler
//创建实体对象
if lnv_pbcompiler.of_createentry(as_returntype,as_pbscript,ls_libraryname,ls_entryname) = 1 then
if not isnull(FindClassDefinition(ls_entryname) ) then
luo_pbcompiler = create using ls_entryname
choose case lower(as_returntype)
case 'any','blob','boolean','char','character','date','datetime','dec','decimal','double','int','integer','long','real','string','time','uint','ulong','unsignedint','unsignedinteger','unsignedlong'
la_return = luo_pbcompiler.dynamic of_exec()//执行动态代码
ls_return = string(la_return)
case '','none'
luo_pbcompiler.dynamic of_exec()//执行动态代码
ls_return = "none"
case else
luo_pbcompiler.dynamic of_exec()//执行动态代码
ls_return = "result is disabled"
end choose
if isvalid(luo_pbcompiler) then destroy luo_pbcompiler
else
ls_return = "error"
end if
else
ls_return = "error"
end if
if isvalid(lnv_pbcompiler) then destroy lnv_pbcompiler
LibraryDelete(ls_libraryname)
return ls_return
end function
三.f_parse
$PBExportH