PB代碼動態(tài)解析執(zhí)行器
博客分類:?
pb腳本SybaseF#VB百度
PB代碼動態(tài)解析執(zhí)行器?
當(dāng)你看到VB、VFP等開發(fā)語言提供的強(qiáng)大的宏執(zhí)行功能,是不是很羨慕呢?當(dāng)你尋遍PB的幫助、關(guān)于PB開發(fā)的書籍或網(wǎng)站而不可得的時候,是不是感到有一絲的遺憾?如果你看到這篇文章,你應(yīng)該感到振奮,因為你終于可以解決這個問題,而且解決問題的思路既是如此簡單、代碼既是如此簡短。如果再加上你的智慧,應(yīng)該比我的解決方法更漂亮。?
先讓我們來了解一些基本知識。?
一.代碼的載體?
在PB中,只有三個地方可以存放代碼,那就是函數(shù)、事件、屬性。這里所指的函數(shù)包括有返回值的通常意義下的函數(shù)和無返回值的過程以及聲明的WINAPI函數(shù),所指的事件指在對象中定義的處理程序,所指的屬性指PB系統(tǒng)屬性之外的實例變量、共享變量、全局變量。函數(shù)和事件是可以用來調(diào)用執(zhí)行的,屬性則只能用來賦值和取值。通常我們是在函數(shù)或事件中編寫代碼。?
二.對象的創(chuàng)建?
如果對象類型是已知的,可以使用CREATE objecttype 來創(chuàng)建對象,如果對象類型是動態(tài)的,可以使用CREATE USING objecttypestring來創(chuàng)建對象。?
三.對象函數(shù)的調(diào)用方式?
如果調(diào)用一個已知類型的對象的函數(shù)或事件,通常采用靜態(tài)模式,也可采用動態(tài)模式,如果調(diào)用一個動態(tài)創(chuàng)建的對象的函數(shù)或事件,則必須采用動態(tài)模式,否則編譯出錯。采用動態(tài)模式調(diào)用函數(shù)是在函數(shù)前加dynamic 關(guān)鍵字。讀者可查閱PB幫助。?
四.庫文件的搜索?
PB中用于編程的對象是保存在PBL、PBD、DLL中的,如果想要使庫文件中的對象在應(yīng)用程序運行時有效,常用的方法是直接將該PBL編譯進(jìn)去或者說使該PBL在庫搜索列表中。如果需要在運行狀態(tài)下改變庫文件搜索列表,PB提供了SetLibraryList和AddToLibraryList兩個函數(shù)。SetLibraryList函數(shù)只能在應(yīng)用對象的open事件腳本中使用,否則應(yīng)用程序會崩潰,AddToLibraryList為PB9新增的函數(shù),用于將新文件加入到庫文件搜索列表中,這兩個函數(shù)都是只能在編譯環(huán)境下有效。?
五.PB庫文件的創(chuàng)建與銷毀?
PB提供了LibraryCreate函數(shù)用于創(chuàng)建庫文件,提供LibraryDelete、FileDelete函數(shù)用于刪除庫文件。?
六.PB實體的導(dǎo)入?
PB提供了LibraryImport函數(shù)用于根據(jù)對象語法創(chuàng)建PB實體并導(dǎo)入到庫文件中,但該函數(shù)目前只支持?jǐn)?shù)據(jù)窗口對象類型的導(dǎo)入。不過,PB提供了相應(yīng)的WINAPI函數(shù)支持其它類型實體的導(dǎo)入,這些相關(guān)的WINAPI包括在PBORCX0.DLL中(不同的PB版本有不同的文件名稱,如PBORC90.DLL、PBORC80.DLL)。有關(guān)實體的導(dǎo)入的WINAPI包括PBORCA_SessionOpen、PBORCA_SessionClose、PBORCA_SessionSetLibraryList、PBORCA_SessionSetCurrentAppl、PBORCA_CompileEntryImport等,讀者可以到Sybase網(wǎng)站找ORCA
Guide相應(yīng)文章尋求支持。?
七.PB實體的查找?
使用FindClassDefinition或FindFunctionDefinition或LibraryDirectory可以在庫文件中查找PB實體是否存在,使用FindClassDefinition或FindFunctionDefinition性能要好。?
以下講開發(fā)思路。?
一.創(chuàng)建臨時庫文件?
1.? 取臨時目錄作為庫文件的存放目錄?
2.? 取待創(chuàng)建的臨時庫文件名稱,保證不與已有文件重名?
3.? 使用LibraryCreate函數(shù)創(chuàng)建臨時庫文件?
二.構(gòu)造用于導(dǎo)入庫文件的臨時PB實體語法?
1. 取臨時PB實體名稱,保證不與庫文件列表中已有PB實體重名?
2. 構(gòu)造臨時PB實體語法,區(qū)分函數(shù)和過程?
三.將臨時PB實體導(dǎo)入臨時庫文件?
1. 取庫文件列表和應(yīng)用對象所在pbl?
2. 將實際不存在的庫文件從庫文件列表中刪除,目的是使調(diào)用PBORCA_SessionSetLibraryList成功?
3. 調(diào)用PBORCA_CompileEntryImport將臨時PB實體導(dǎo)入臨時庫文件?
四.將臨時庫文件加入到庫文件搜索列表?
1. 調(diào)用AddToLibraryList加入新文件到庫文件搜索列表?
五.創(chuàng)建臨時PB實體所對應(yīng)的對象并調(diào)用其函數(shù)以執(zhí)行動態(tài)腳本?
1. 使用CREATE USING objecttypestring語句創(chuàng)建對象?
2. 通過動態(tài)調(diào)用對象的of_exec函數(shù)執(zhí)行動態(tài)腳本,區(qū)分返回值類型?
六.銷毀所有臨時對象?
1. 調(diào)用LibraryDelete函數(shù)刪除創(chuàng)建的臨時庫文件?
以下講我在開發(fā)時遇到的一些矛盾或問題。?
一.代碼是逐行解釋還是讓PB編譯器去解釋?
有些開發(fā)人員試圖對動態(tài)腳本自行逐行解釋,這是很困難的事情。一行代碼如果脫離它的語境去執(zhí)行,可能會產(chǎn)生錯誤的結(jié)果,即便你對PB所支持的函數(shù)全部做出解釋,使用PB開發(fā)出來的對象、函數(shù)、事件等,你又如何去解釋?這等同于你要花很大力氣去編寫一個PB編譯器,除非你與PB編譯器的開發(fā)團(tuán)隊合作,否則你很難獲得成功。所以你必須想辦法讓PB編譯器去解釋。既然每行代碼不能脫離其它代碼而執(zhí)行,那就創(chuàng)建一個函數(shù)或事件,讓這個函數(shù)或事件包括你想寫的所有代碼。而函數(shù)或事件又不能脫離對象而存在,所以你必須想辦法動態(tài)創(chuàng)建對象以及函數(shù)或事件,對象的聲明必須依賴于庫文件中的PB實體,由此推出關(guān)鍵是創(chuàng)建PB實體。?
二.如何創(chuàng)建PB實體?
前面已講過要使用PBORCX0.DLL中的WINAPI函數(shù)來創(chuàng)建并導(dǎo)入實體,這項技術(shù)并不難,在sybase的網(wǎng)站或隨便狗狗(百度)一下就能出來一大把。?
三.創(chuàng)建的PB實體是存放在現(xiàn)有庫文件中還是新文件中再導(dǎo)入?
我最初的想法是放在現(xiàn)有庫文件中,這樣就不必花費時間在創(chuàng)建庫文件和刪除庫文件的執(zhí)行上,結(jié)果發(fā)現(xiàn),創(chuàng)建是成功,但運行時PB就是不“認(rèn)識”我創(chuàng)建的PB實體,一創(chuàng)建該實體的對象就報錯,想來PB在程序啟動時就讀取庫文件中有哪些實體形成列表,在沒有改變庫文件列表之前,其實體列表不會改變,這樣對新建的實體就視而不見了。所以我不得不試著新建一個PBL,在新建的PBL中創(chuàng)建PB實體,然后使用AddToLibraryList將新建的PBL包括進(jìn)來,這一試果然成功。?
四.使用數(shù)據(jù)窗口的Describe調(diào)用全局函數(shù)還是其它方式來取得返回值?
大家都知道,使用數(shù)據(jù)窗口的Describe函數(shù)可以調(diào)用全局函數(shù),但是它有很多的局限性,全局函數(shù)必須有簡單類型的返回值,所有參數(shù)只能是簡單數(shù)據(jù)類型而且不能通過參考傳值。如果在需要調(diào)用的地方直接使用新建對象的函數(shù)將不受這些限制。?
五.如何進(jìn)行垃圾對象的清理?
既然每次執(zhí)行動態(tài)腳本要創(chuàng)建PB實體,如果執(zhí)行得多了,就有很多垃圾對象,所以應(yīng)進(jìn)行清理??梢酝ㄟ^LibraryDelete函數(shù)或FileDelete刪除庫文件。有意思的是,一旦創(chuàng)建PB實體,即便你刪除了,使用FindClassDefinition或FindFunctionDefinition還是能夠找到,但你想使用該實體創(chuàng)建對象則失敗,這再次說明PB在程序啟動時就讀取庫文件中有哪些實體形成列表,在沒有改變庫文件列表之前,其實體列表不會改變。?
以下是所附代碼的幾點說明?
一.所附代碼是在PB9環(huán)境下開發(fā)的,程序運行時必須有PBORC90.DLL,如果改成PB其它版本,請將nvo_pbcompiler中WINAPI函數(shù)所使用的動態(tài)庫做相應(yīng)修改。?
二.nvo_pbcompiler用于創(chuàng)建PB實體,這是PB動態(tài)腳本解釋器的核心函數(shù);f_execpbscript()用于執(zhí)行一段PB腳本的樣例代碼函數(shù),返回值類型為字符串,如果要使用到其它場合,讀者可自行編寫函數(shù),思路類似;w_pbcompiler_test為一個用來執(zhí)行PB腳本的樣例界面窗口;其它函數(shù)有各自功能。?
三.如果想運行PB動態(tài)腳本編譯器,請先將所有代碼分對象導(dǎo)入庫文件,然后編譯,PB動態(tài)腳本編譯器在PB開發(fā)環(huán)境下無效。?
四.為了程序方面的簡化,有些所使用的全局函數(shù)請參考作者的其它文章。?
五.所附代碼僅為腳本沒有參數(shù)的情況下有效,如果你想代碼有參數(shù),只需要簡單地對腳本語法作些改變就可,當(dāng)然前臺需要用戶定義參數(shù)。?
六.本PB動態(tài)腳本解釋器可執(zhí)行所有有效的PB代碼,例如訪問全局變量、使用PB所有的系統(tǒng)函數(shù)、使用程序員開發(fā)的自定義函數(shù)、打開窗口、訪問菜單、使用數(shù)據(jù)窗口等。?
七.通常將本PB動態(tài)腳本解釋器嵌入到現(xiàn)有的使用PB開發(fā)出來的系統(tǒng)而不是單獨使用,這樣可以加載很多免編譯的外掛程序。?
八.如果再拓寬它的應(yīng)用范圍,你甚至可以做到只需要一個框架程序,其它代碼全部動態(tài)加載和執(zhí)行,這樣就只需一次編譯,升級和維護(hù)就變得非常簡單,不過你要考慮系統(tǒng)的可用性、系統(tǒng)性能和系統(tǒng)的穩(wěn)定性等。?
附完整源代碼?
一.pbcompiler?
$PBExportHeader$pbcompiler.sra?
$PBExportComments$PB動態(tài)腳本解釋器應(yīng)用對象?
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$執(zhí)行動態(tài)腳本的樣例函數(shù)?
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);/*******************************************************************?
函數(shù)名稱:f_execpbscript()?
參數(shù):???? as_returntype string 返回值類型?
????????? as_pbscript string 動態(tài)代碼?
返回值:? string 用戶自定義或錯誤信息?
功能描述:執(zhí)行動態(tài)代碼(只返回字符串)?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期: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?
//創(chuàng)建實體對象?
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()//執(zhí)行動態(tài)代碼?
?? ls_return = string(la_return)?
? case '','none'?
?? luo_pbcompiler.dynamic of_exec()//執(zhí)行動態(tài)代碼?
?? ls_return = "none"?
? case else?
?? luo_pbcompiler.dynamic of_exec()//執(zhí)行動態(tài)代碼?
?? 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?
$PBExportHeader$f_parse.srf?
$PBExportComments$分解字符串到數(shù)組?
global type f_parse from function_object?
end type?
forward prototypes?
global function long f_parse (readonly string as_text, readonly string as_sep, ref string as_list[])?
end prototypes?
global function long f_parse (readonly string as_text, readonly string as_sep, ref string as_list[]);/*******************************************************************?
函數(shù)名稱:f_parse()?
參數(shù):???? as_text string 來源字符串?
????????? as_sep string 分隔字符?
??? as_list[] ref string 分析后形成的字符串?dāng)?shù)組?
返回值:? long 分析后形成的數(shù)組元素個數(shù)?
功能描述:分析字符串到一個數(shù)組中?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2002-11-19?
版本號:? V1.0?
*******************************************************************/?
long i,ll_pos?
string ls_null[],ls_text?
ls_text = as_text?
as_list = ls_null?
i=0?
ll_pos = posw(lower(ls_text),lower(as_sep))?
do while ll_pos > 0?
i ++?
as_list[i]=leftw(ls_text,ll_pos - 1)?
ls_text=midw(ls_text,ll_pos + lenw(as_sep),lenw(ls_text))?
ll_pos = posw(lower(ls_text),lower(as_sep))?
loop?
as_list[i + 1] = ls_text?
return upperbound(as_list[])?
end function?
四.f_replacetext?
$PBExportHeader$f_replacetext.srf?
$PBExportComments$替換字符串?
global type f_replacetext from function_object?
end type?
forward prototypes?
global function string f_replacetext (readonly string as_source, readonly string as_oldtag, readonly string as_newtag, readonly long al_seq)?
end prototypes?
global function string f_replacetext (readonly string as_source, readonly string as_oldtag, readonly string as_newtag, readonly long al_seq);/*******************************************************************?
函數(shù)名稱:f_replacetext()?
參數(shù):???? as_source string 源字符串?
????????? as_oldtag string 待替換特征字符串?
??? as_newtag string 替換后特征字符串?
??? al_seq long 第幾個特征替換字符串需替換,0表示全部?
返回值:? string 替換后字符串?
功能描述:用一特征字符串替換指定字符串中的特征字符串,參數(shù)al_seq=0時表示全部替換?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2002-11-19?
版本號:? V1.0?
*******************************************************************/?
long ll_start_pos=1,ll_len_old_tag,i = 0?
string ls_left,ls_return='',ls_source=''?
ls_source = as_source?
ll_len_old_tag = lenw(as_oldtag)?
ll_start_pos = posw(lower(ls_source),lower(as_oldtag),1)?
if al_seq = 0 then?
DO WHILE ll_start_pos > 0?
? ls_left = leftw(ls_source,ll_start_pos - 1) + as_newtag?
? ls_return = ls_return + ls_left?
? ls_source = midw(ls_source,ll_start_pos + lenw(as_oldtag),lenw(ls_source))?
? ll_start_pos = posw(lower(ls_source),lower(as_oldtag),1)?
LOOP?
elseif al_seq > 0 then?
DO WHILE ll_start_pos > 0?
? i ++?
? if al_seq = i then?
?? ls_left = leftw(ls_source,ll_start_pos - 1) + as_newtag?
?? ls_return = ls_return + ls_left?
?? ls_source = midw(ls_source,ll_start_pos + lenw(as_oldtag),lenw(ls_source))?
?? ll_start_pos = posw(lower(ls_source),lower(as_oldtag),1)?
? end if?
loop?
end if?
ls_return = ls_return + ls_source?
return ls_return?
end function?
五.nvo_pbcompiler?
$PBExportHeader$nvo_pbcompiler.sru?
$PBExportComments$PB動態(tài)腳本解釋器?
forward?
global type nvo_pbcompiler from nonvisualobject?
end type?
end forward?
global type nvo_pbcompiler from nonvisualobject?
end type?
global nvo_pbcompiler nvo_pbcompiler?
type prototypes?
//打開一個會話?
Function long SessionOpen () Library "PBORC90.DLL" Alias for "PBORCA_SessionOpen"?
//關(guān)閉一個會話?
Subroutine SessionClose ( long hORCASession ) Library "PBORC90.DLL" Alias for "PBORCA_SessionClose"?
//設(shè)置當(dāng)前會話的庫清單?
Function int SessionSetLibraryList ( long hORCASession, ref string pLibNames[], int iNumberOfLibs) Library "PBORC90.DLL" Alias for "PBORCA_SessionSetLibraryList"?
//設(shè)置當(dāng)前會話對應(yīng)的應(yīng)用?
Function int SessionSetCurrentAppl ( long hORCASession, string lpszApplLibName, string lpszApplName ) Library "PBORC90.DLL" Alias for "PBORCA_SessionSetCurrentAppl"?
//導(dǎo)入并編譯實體?
Function int CompileEntryImport ( long hORCASession, string lpszLibraryName, string lpszEntryName, long otEntryType, string lpszComments, string lpszEntrySyntax, long lEntrySyntaxBuffSize, long pCompErrorProc, long pUserData ) Library "PBORC90.DLL" Alias for
"PBORCA_CompileEntryImport"?
//取臨時目錄?
Function long GetTempPath(long nBufferLength, ref string lpBuffer)? Library "kernel32" Alias for "GetTempPathA"?
//獲取一個已裝載模板的完整路徑名稱?
FUNCTION ulong GetModuleFileName(ulong hModule,ref string lpFileName,ulong nSize) LIBRARY "kernel32.dll" ALIAS FOR "GetModuleFileNameA"?
end prototypes?
type variables?
end variables?
forward prototypes?
public function string of_gettemppath ()?
public function string of_getapppath ()?
public function integer of_createentry (string as_returntype, string as_pbscript, ref string as_libraryname, ref string as_entryname)?
end prototypes?
public function string of_gettemppath ();/*******************************************************************?
函數(shù)名稱:of_gettemppath()?
參數(shù):???? 無?
返回值:? string 臨時路徑?
功能描述:取臨時路徑?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2006-12-26?
版本號:? V1.0?
*******************************************************************/?
string ls_path?
ulong lu_size=256?
ls_path=space(256)?
GetTempPath(lu_size,ls_path)?
return trimw(ls_path)?
end function?
public function string of_getapppath ();/*******************************************************************?
函數(shù)名稱:of_getapppath()?
參數(shù):???? 無?
返回值:? string 應(yīng)用程序路徑?
功能描述:取應(yīng)用程序路徑?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2002-11-22?
版本號:? V1.0?
*******************************************************************/?
string ls_apppath?
ls_apppath=space(256)?
GetModuleFileName(Handle(GetApplication()),ls_apppath,256)?
ls_apppath=Reverse(ls_apppath)?
ls_apppath=Reverse(midw(ls_apppath,posw(ls_apppath,'',1)))?
return ls_apppath?
end function?
public function integer of_createentry (string as_returntype, string as_pbscript, ref string as_libraryname, ref string as_entryname);/*******************************************************************?
函數(shù)名稱:of_createentry()?
參數(shù):???? as_returntype string 返回值類型?
????????? as_pbscript string 動態(tài)代碼?
??? as_libraryname ref string 創(chuàng)建的庫文件名稱?
??? as_entryname ref string 創(chuàng)建的實體名稱?
返回值:? long 是否成功(1表示成功,-1表示失敗)?
功能描述:根據(jù)動態(tài)代碼創(chuàng)建實體?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2007-02-12?
版本號:? V1.0?
*******************************************************************/?
long ll_sid//會話編號?
long ll_index//對象序號?
string ls_librarylist[]//庫文件列表?
string ls_librarylist_tmp[]//庫文件列表(臨時)?
string ls_temp_libraryname//臨時庫文件名稱?
string ls_temp_path//臨時目錄?
string ls_syntax//實體語法?
string ls_app_libraryname//應(yīng)用程序所在庫文件名稱?
integer li_result//結(jié)果?
string ls_entryname//對象名稱?
classdefinition lcd_app//應(yīng)用程序類定義對象?
string ls_librarylist_files//庫文件?
integer i,j//臨時變量?
//開發(fā)環(huán)境下直接退出?
if handle(GetApplication()) <= 0 then return -1?
//取庫文件列表?
ls_librarylist_files = getlibrarylist ()?
//取應(yīng)用對象所在pbl?
lcd_app = getapplication().classdefinition?
ls_app_libraryname = lcd_app.libraryname?
ls_temp_path = this.of_gettemppath( )//取臨時目錄?
//取待創(chuàng)建的臨時庫文件名稱?
ll_index = 1?
ls_temp_libraryname = ls_temp_path + "temp"+string(ll_index) + ".pbl"?
do while fileexists(ls_temp_libraryname) or posw(","+ls_librarylist_files+",",","+ls_temp_libraryname+",") > 0?
ll_index ++?
ls_temp_libraryname = ls_temp_path + "temp"+string(ll_index) + ".pbl"?
loop?
//創(chuàng)建臨時庫文件?
LibraryCreate(ls_temp_libraryname,"臨時庫文件")?
f_parse(ls_librarylist_files,',',ls_librarylist)//分解字符串到數(shù)組?
//判斷庫文件是否存在并形成新列表?
j = 0?
for i = 1 to upperbound(ls_librarylist)?
if fileexists(ls_librarylist[i]) then?
? j ++?
? ls_librarylist_tmp[j] = ls_librarylist[i]?
end if?
next?
ls_librarylist = ls_librarylist_tmp?
ls_librarylist[upperbound(ls_librarylist)+1] = ls_temp_libraryname?
ll_sid = SessionOpen()//打開一個會話?
//設(shè)置當(dāng)前會話的庫清單?
li_result = SessionSetLibraryList (ll_sid, ls_librarylist, upperbound(ls_librarylist))?
if li_result = 0 then?????
//設(shè)置當(dāng)前會話對應(yīng)的應(yīng)用?
li_result = SessionSetCurrentAppl (ll_sid, ls_app_libraryname, getapplication().appname )?
?? if li_result = 0 then??????
? //取實體名稱(保證不重復(fù))?
? ll_index = 1?
? do while not isnull(FindClassDefinition("nvo_"+string(ll_index)))?
?? ll_index ++?
? loop?
? ls_entryname = "nvo_"+string(ll_index)?
? //實體聲明?
? ls_syntax = "$PBExportHeader$"+ls_entryname+".sru"+"~r~n"&?
??? + "forward"+"~r~n"&?
??? + "global type "+ls_entryname+" from nonvisualobject"+"~r~n"&?
??? + "end type"+"~r~n"&?
??? + "end forward"+"~r~n"&?
??? + "~r~n"&?
??? + "global type "+ls_entryname+" from nonvisualobject"+"~r~n"&?
??? + "end type"+"~r~n"&?
??? + "global "+ls_entryname+" "+ls_entryname+""+"~r~n"&?
??? + "~r~n"&?????
??? + "forward prototypes"+"~r~n"?
? //區(qū)分函數(shù)還是過程?
? if trimw(lower(as_returntype)) = 'none' or trimw(lower(as_returntype)) = '' then?
?? ls_syntax = ls_syntax + "public subroutine of_exec ()"+"~r~n"&?
??? + "end prototypes"+"~r~n"&?
??? + "~r~n"&?
??? + "public subroutine of_exec ();"+as_pbscript+"~r~n"&?
??? + "end subroutine"?
? else?
?? ls_syntax = ls_syntax + "public function " + as_returntype + " of_exec ()"+"~r~n"&?
??? + "end prototypes"+"~r~n"&?
??? + "~r~n"&?
??? + "public function " + as_returntype + " of_exec ();"+as_pbscript+"~r~n"&?
??? + "end function"?
? end if?
? //實體語法尾部?
? ls_syntax = ls_syntax + "~r~n" + "on " + ls_entryname + ".create"+"~r~n"&?
?? + "call super::create"+"~r~n"&?
?? + "TriggerEvent( this, ~"constructor~" )"+"~r~n"&?
?? + "end on"+"~r~n"&?
?? + "~r~n"&?
?? + "on " + ls_entryname + ".destroy"+"~r~n"&?
?? + "TriggerEvent( this, ~"destructor~" )"+"~r~n"&?
?? + "call super::destroy"+"~r~n"&?
?? + "end on"?
? //導(dǎo)入并編譯實體?
? li_result = CompileEntryImport (ll_sid, ls_temp_libraryname, ls_entryname, 6 , "comment - new object", ls_syntax, len(ls_syntax), 0, 0 )?
?? end if?
end if?
SessionClose(ll_sid)//關(guān)閉一個會話?
as_libraryname = ls_temp_libraryname?
as_entryname=ls_entryname?
//加入新文件到庫文件搜索列表?
AddToLibraryList(ls_temp_libraryname)?
if li_result = 0 then?
return 1?
else?
return -1?
end if?
end function?
on nvo_pbcompiler.create?
call super::create?
TriggerEvent( this, "constructor" )?
end on?
on nvo_pbcompiler.destroy?
TriggerEvent( this, "destructor" )?
call super::destroy?
end on?
六.w_pbcompiler_test?
$PBExportHeader$w_pbcompiler_test.srw?
$PBExportComments$PB動態(tài)腳本解釋器測試窗口?
forward?
global type w_pbcompiler_test from window?
end type?
type st_returnvalue from statictext within w_pbcompiler_test?
end type?
type st_returntype from statictext within w_pbcompiler_test?
end type?
type st_script from statictext within w_pbcompiler_test?
end type?
type sle_returnvalue from singlelineedit within w_pbcompiler_test?
end type?
type cb_exit from commandbutton within w_pbcompiler_test?
end type?
type sle_returntype from singlelineedit within w_pbcompiler_test?
end type?
type mle_script from multilineedit within w_pbcompiler_test?
end type?
type cb_ok from commandbutton within w_pbcompiler_test?
end type?
end forward?
global type w_pbcompiler_test from window?
integer width = 1979?
integer height = 1100?
boolean titlebar = true?
string title = "PB腳本解釋器(測試)"?
boolean controlmenu = true?
boolean minbox = true?
boolean maxbox = true?
boolean resizable = true?
long backcolor = 67108864?
string icon = "AppIcon!"?
boolean center = true?
st_returnvalue st_returnvalue?
st_returntype st_returntype?
st_script st_script?
sle_returnvalue sle_returnvalue?
cb_exit cb_exit?
sle_returntype sle_returntype?
mle_script mle_script?
cb_ok cb_ok?
end type?
global w_pbcompiler_test w_pbcompiler_test?
type prototypes?
end prototypes?
type variables?
end variables?
on w_pbcompiler_test.create?
this.st_returnvalue=create st_returnvalue?
this.st_returntype=create st_returntype?
this.st_script=create st_script?
this.sle_returnvalue=create sle_returnvalue?
this.cb_exit=create cb_exit?
this.sle_returntype=create sle_returntype?
this.mle_script=create mle_script?
this.cb_ok=create cb_ok?
this.Control[]={this.st_returnvalue,&?
this.st_returntype,&?
this.st_script,&?
this.sle_returnvalue,&?
this.cb_exit,&?
this.sle_returntype,&?
this.mle_script,&?
this.cb_ok}?
end on?
on w_pbcompiler_test.destroy?
destroy(this.st_returnvalue)?
destroy(this.st_returntype)?
destroy(this.st_script)?
destroy(this.sle_returnvalue)?
destroy(this.cb_exit)?
destroy(this.sle_returntype)?
destroy(this.mle_script)?
destroy(this.cb_ok)?
end on?
type st_returnvalue from statictext within w_pbcompiler_test?
integer x = 9?
integer y = 608?
integer width = 297?
integer height = 60?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
long textcolor = 33554432?
long backcolor = 67108864?
string text = "返回值:"?
boolean focusrectangle = false?
end type?
type st_returntype from statictext within w_pbcompiler_test?
integer x = 9?
integer y = 476?
integer width = 297?
integer height = 60?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
long textcolor = 33554432?
long backcolor = 67108864?
string text = "返回值類型:"?
boolean focusrectangle = false?
end type?
type st_script from statictext within w_pbcompiler_test?
integer x = 9?
integer y = 12?
integer width = 206?
integer height = 60?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
long textcolor = 33554432?
long backcolor = 67108864?
string text = "PB腳本:"?
boolean focusrectangle = false?
end type?
type sle_returnvalue from singlelineedit within w_pbcompiler_test?
integer x = 334?
integer y = 608?
integer width = 1582?
integer height = 104?
integer taborder = 30?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
long textcolor = 33554432?
borderstyle borderstyle = stylelowered!?
end type?
type cb_exit from commandbutton within w_pbcompiler_test?
integer x = 1664?
integer y = 856?
integer width = 242?
integer height = 104?
integer taborder = 50?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
string text = "退出"?
end type?
event clicked;close(parent)?
end event?
type sle_returntype from singlelineedit within w_pbcompiler_test?
integer x = 334?
integer y = 476?
integer width = 1582?
integer height = 104?
integer taborder = 20?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
long textcolor = 33554432?
borderstyle borderstyle = stylelowered!?
end type?
type mle_script from multilineedit within w_pbcompiler_test?
integer x = 334?
integer y = 12?
integer width = 1582?
integer height = 432?
integer taborder = 10?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
long textcolor = 33554432?
boolean vscrollbar = true?
boolean autovscroll = true?
borderstyle borderstyle = stylelowered!?
end type?
type cb_ok from commandbutton within w_pbcompiler_test?
integer x = 1417?
integer y = 856?
integer width = 242?
integer height = 104?
integer taborder = 40?
integer textsize = -9?
integer weight = 400?
fontcharset fontcharset = ansi!?
fontpitch fontpitch = variable!?
fontfamily fontfamily = swiss!?
string facename = "Arial"?
string text = "執(zhí)行"?
end type?
event clicked;sle_returnvalue.text = f_execpbscript(sle_returntype.text,mle_script.text)?
end event