當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]PB代碼動(dòng)態(tài)解析執(zhí)行器 博客分類:? pb腳本SybaseF#VB百度 PB代碼動(dòng)態(tài)解析執(zhí)行器?當(dāng)你看到VB、VFP等開發(fā)語言提供的強(qiáng)大的宏執(zhí)行功能,是不是很羨慕呢?當(dāng)你尋遍PB的幫助、關(guān)于PB

PB代碼動(dòng)態(tài)解析執(zhí)行器 博客分類:? pb腳本SybaseF#VB百度 PB代碼動(dòng)態(tài)解析執(zhí)行器?

當(dāng)你看到VB、VFP等開發(fā)語言提供的強(qiáng)大的宏執(zhí)行功能,是不是很羨慕呢?當(dāng)你尋遍PB的幫助、關(guān)于PB開發(fā)的書籍或網(wǎng)站而不可得的時(shí)候,是不是感到有一絲的遺憾?如果你看到這篇文章,你應(yīng)該感到振奮,因?yàn)槟憬K于可以解決這個(gè)問題,而且解決問題的思路既是如此簡(jiǎn)單、代碼既是如此簡(jiǎn)短。如果再加上你的智慧,應(yīng)該比我的解決方法更漂亮。?

先讓我們來了解一些基本知識(shí)。?

一.代碼的載體?

在PB中,只有三個(gè)地方可以存放代碼,那就是函數(shù)、事件、屬性。這里所指的函數(shù)包括有返回值的通常意義下的函數(shù)和無返回值的過程以及聲明的WINAPI函數(shù),所指的事件指在對(duì)象中定義的處理程序,所指的屬性指PB系統(tǒng)屬性之外的實(shí)例變量、共享變量、全局變量。函數(shù)和事件是可以用來調(diào)用執(zhí)行的,屬性則只能用來賦值和取值。通常我們是在函數(shù)或事件中編寫代碼。?

二.對(duì)象的創(chuàng)建?

如果對(duì)象類型是已知的,可以使用CREATE objecttype 來創(chuàng)建對(duì)象,如果對(duì)象類型是動(dòng)態(tài)的,可以使用CREATE USING objecttypestring來創(chuàng)建對(duì)象。?

三.對(duì)象函數(shù)的調(diào)用方式?

如果調(diào)用一個(gè)已知類型的對(duì)象的函數(shù)或事件,通常采用靜態(tài)模式,也可采用動(dòng)態(tài)模式,如果調(diào)用一個(gè)動(dòng)態(tài)創(chuàng)建的對(duì)象的函數(shù)或事件,則必須采用動(dòng)態(tài)模式,否則編譯出錯(cuò)。采用動(dòng)態(tài)模式調(diào)用函數(shù)是在函數(shù)前加dynamic 關(guān)鍵字。讀者可查閱PB幫助。?

四.庫(kù)文件的搜索?

PB中用于編程的對(duì)象是保存在PBL、PBD、DLL中的,如果想要使庫(kù)文件中的對(duì)象在應(yīng)用程序運(yùn)行時(shí)有效,常用的方法是直接將該P(yáng)BL編譯進(jìn)去或者說使該P(yáng)BL在庫(kù)搜索列表中。如果需要在運(yùn)行狀態(tài)下改變庫(kù)文件搜索列表,PB提供了SetLibraryList和AddToLibraryList兩個(gè)函數(shù)。SetLibraryList函數(shù)只能在應(yīng)用對(duì)象的open事件腳本中使用,否則應(yīng)用程序會(huì)崩潰,AddToLibraryList為PB9新增的函數(shù),用于將新文件加入到庫(kù)文件搜索列表中,這兩個(gè)函數(shù)都是只能在編譯環(huán)境下有效。?

五.PB庫(kù)文件的創(chuàng)建與銷毀?

PB提供了LibraryCreate函數(shù)用于創(chuàng)建庫(kù)文件,提供LibraryDelete、FileDelete函數(shù)用于刪除庫(kù)文件。?

六.PB實(shí)體的導(dǎo)入?

PB提供了LibraryImport函數(shù)用于根據(jù)對(duì)象語法創(chuàng)建PB實(shí)體并導(dǎo)入到庫(kù)文件中,但該函數(shù)目前只支持?jǐn)?shù)據(jù)窗口對(duì)象類型的導(dǎo)入。不過,PB提供了相應(yīng)的WINAPI函數(shù)支持其它類型實(shí)體的導(dǎo)入,這些相關(guān)的WINAPI包括在PBORCX0.DLL中(不同的PB版本有不同的文件名稱,如PBORC90.DLL、PBORC80.DLL)。有關(guān)實(shí)體的導(dǎo)入的WINAPI包括PBORCA_SessionOpen、PBORCA_SessionClose、PBORCA_SessionSetLibraryList、PBORCA_SessionSetCurrentAppl、PBORCA_CompileEntryImport等,讀者可以到Sybase網(wǎng)站找ORCA Guide相應(yīng)文章尋求支持。?

七.PB實(shí)體的查找?

使用FindClassDefinition或FindFunctionDefinition或LibraryDirectory可以在庫(kù)文件中查找PB實(shí)體是否存在,使用FindClassDefinition或FindFunctionDefinition性能要好。?

以下講開發(fā)思路。?

一.創(chuàng)建臨時(shí)庫(kù)文件?
1.? 取臨時(shí)目錄作為庫(kù)文件的存放目錄?
2.? 取待創(chuàng)建的臨時(shí)庫(kù)文件名稱,保證不與已有文件重名?
3.? 使用LibraryCreate函數(shù)創(chuàng)建臨時(shí)庫(kù)文件?

二.構(gòu)造用于導(dǎo)入庫(kù)文件的臨時(shí)PB實(shí)體語法?
1. 取臨時(shí)PB實(shí)體名稱,保證不與庫(kù)文件列表中已有PB實(shí)體重名?
2. 構(gòu)造臨時(shí)PB實(shí)體語法,區(qū)分函數(shù)和過程?

三.將臨時(shí)PB實(shí)體導(dǎo)入臨時(shí)庫(kù)文件?
1. 取庫(kù)文件列表和應(yīng)用對(duì)象所在pbl?
2. 將實(shí)際不存在的庫(kù)文件從庫(kù)文件列表中刪除,目的是使調(diào)用PBORCA_SessionSetLibraryList成功?
3. 調(diào)用PBORCA_CompileEntryImport將臨時(shí)PB實(shí)體導(dǎo)入臨時(shí)庫(kù)文件?

四.將臨時(shí)庫(kù)文件加入到庫(kù)文件搜索列表?
1. 調(diào)用AddToLibraryList加入新文件到庫(kù)文件搜索列表?

五.創(chuàng)建臨時(shí)PB實(shí)體所對(duì)應(yīng)的對(duì)象并調(diào)用其函數(shù)以執(zhí)行動(dòng)態(tài)腳本?
1. 使用CREATE USING objecttypestring語句創(chuàng)建對(duì)象?
2. 通過動(dòng)態(tài)調(diào)用對(duì)象的of_exec函數(shù)執(zhí)行動(dòng)態(tài)腳本,區(qū)分返回值類型?

六.銷毀所有臨時(shí)對(duì)象?
1. 調(diào)用LibraryDelete函數(shù)刪除創(chuàng)建的臨時(shí)庫(kù)文件?


以下講我在開發(fā)時(shí)遇到的一些矛盾或問題。?

一.代碼是逐行解釋還是讓PB編譯器去解釋?
有些開發(fā)人員試圖對(duì)動(dòng)態(tài)腳本自行逐行解釋,這是很困難的事情。一行代碼如果脫離它的語境去執(zhí)行,可能會(huì)產(chǎn)生錯(cuò)誤的結(jié)果,即便你對(duì)PB所支持的函數(shù)全部做出解釋,使用PB開發(fā)出來的對(duì)象、函數(shù)、事件等,你又如何去解釋?這等同于你要花很大力氣去編寫一個(gè)PB編譯器,除非你與PB編譯器的開發(fā)團(tuán)隊(duì)合作,否則你很難獲得成功。所以你必須想辦法讓PB編譯器去解釋。既然每行代碼不能脫離其它代碼而執(zhí)行,那就創(chuàng)建一個(gè)函數(shù)或事件,讓這個(gè)函數(shù)或事件包括你想寫的所有代碼。而函數(shù)或事件又不能脫離對(duì)象而存在,所以你必須想辦法動(dòng)態(tài)創(chuàng)建對(duì)象以及函數(shù)或事件,對(duì)象的聲明必須依賴于庫(kù)文件中的PB實(shí)體,由此推出關(guān)鍵是創(chuàng)建PB實(shí)體。?

二.如何創(chuàng)建PB實(shí)體?
前面已講過要使用PBORCX0.DLL中的WINAPI函數(shù)來創(chuàng)建并導(dǎo)入實(shí)體,這項(xiàng)技術(shù)并不難,在sybase的網(wǎng)站或隨便狗狗(百度)一下就能出來一大把。?

三.創(chuàng)建的PB實(shí)體是存放在現(xiàn)有庫(kù)文件中還是新文件中再導(dǎo)入?
我最初的想法是放在現(xiàn)有庫(kù)文件中,這樣就不必花費(fèi)時(shí)間在創(chuàng)建庫(kù)文件和刪除庫(kù)文件的執(zhí)行上,結(jié)果發(fā)現(xiàn),創(chuàng)建是成功,但運(yùn)行時(shí)PB就是不“認(rèn)識(shí)”我創(chuàng)建的PB實(shí)體,一創(chuàng)建該實(shí)體的對(duì)象就報(bào)錯(cuò),想來PB在程序啟動(dòng)時(shí)就讀取庫(kù)文件中有哪些實(shí)體形成列表,在沒有改變庫(kù)文件列表之前,其實(shí)體列表不會(huì)改變,這樣對(duì)新建的實(shí)體就視而不見了。所以我不得不試著新建一個(gè)PBL,在新建的PBL中創(chuàng)建PB實(shí)體,然后使用AddToLibraryList將新建的PBL包括進(jìn)來,這一試果然成功。?

四.使用數(shù)據(jù)窗口的Describe調(diào)用全局函數(shù)還是其它方式來取得返回值?
大家都知道,使用數(shù)據(jù)窗口的Describe函數(shù)可以調(diào)用全局函數(shù),但是它有很多的局限性,全局函數(shù)必須有簡(jiǎn)單類型的返回值,所有參數(shù)只能是簡(jiǎn)單數(shù)據(jù)類型而且不能通過參考傳值。如果在需要調(diào)用的地方直接使用新建對(duì)象的函數(shù)將不受這些限制。?

五.如何進(jìn)行垃圾對(duì)象的清理?
既然每次執(zhí)行動(dòng)態(tài)腳本要?jiǎng)?chuàng)建PB實(shí)體,如果執(zhí)行得多了,就有很多垃圾對(duì)象,所以應(yīng)進(jìn)行清理??梢酝ㄟ^LibraryDelete函數(shù)或FileDelete刪除庫(kù)文件。有意思的是,一旦創(chuàng)建PB實(shí)體,即便你刪除了,使用FindClassDefinition或FindFunctionDefinition還是能夠找到,但你想使用該實(shí)體創(chuàng)建對(duì)象則失敗,這再次說明PB在程序啟動(dòng)時(shí)就讀取庫(kù)文件中有哪些實(shí)體形成列表,在沒有改變庫(kù)文件列表之前,其實(shí)體列表不會(huì)改變。?


以下是所附代碼的幾點(diǎn)說明?

一.所附代碼是在PB9環(huán)境下開發(fā)的,程序運(yùn)行時(shí)必須有PBORC90.DLL,如果改成PB其它版本,請(qǐng)將nvo_pbcompiler中WINAPI函數(shù)所使用的動(dòng)態(tài)庫(kù)做相應(yīng)修改。?

二.nvo_pbcompiler用于創(chuàng)建PB實(shí)體,這是PB動(dòng)態(tài)腳本解釋器的核心函數(shù);f_execpbscript()用于執(zhí)行一段PB腳本的樣例代碼函數(shù),返回值類型為字符串,如果要使用到其它場(chǎng)合,讀者可自行編寫函數(shù),思路類似;w_pbcompiler_test為一個(gè)用來執(zhí)行PB腳本的樣例界面窗口;其它函數(shù)有各自功能。?

三.如果想運(yùn)行PB動(dòng)態(tài)腳本編譯器,請(qǐng)先將所有代碼分對(duì)象導(dǎo)入庫(kù)文件,然后編譯,PB動(dòng)態(tài)腳本編譯器在PB開發(fā)環(huán)境下無效。?

四.為了程序方面的簡(jiǎn)化,有些所使用的全局函數(shù)請(qǐng)參考作者的其它文章。?

五.所附代碼僅為腳本沒有參數(shù)的情況下有效,如果你想代碼有參數(shù),只需要簡(jiǎn)單地對(duì)腳本語法作些改變就可,當(dāng)然前臺(tái)需要用戶定義參數(shù)。?

六.本PB動(dòng)態(tài)腳本解釋器可執(zhí)行所有有效的PB代碼,例如訪問全局變量、使用PB所有的系統(tǒng)函數(shù)、使用程序員開發(fā)的自定義函數(shù)、打開窗口、訪問菜單、使用數(shù)據(jù)窗口等。?

七.通常將本PB動(dòng)態(tài)腳本解釋器嵌入到現(xiàn)有的使用PB開發(fā)出來的系統(tǒng)而不是單獨(dú)使用,這樣可以加載很多免編譯的外掛程序。?

八.如果再拓寬它的應(yīng)用范圍,你甚至可以做到只需要一個(gè)框架程序,其它代碼全部動(dòng)態(tài)加載和執(zhí)行,這樣就只需一次編譯,升級(jí)和維護(hù)就變得非常簡(jiǎn)單,不過你要考慮系統(tǒng)的可用性、系統(tǒng)性能和系統(tǒng)的穩(wěn)定性等。?

附完整源代碼?
一.pbcompiler?
$PBExportHeader$pbcompiler.sra?
$PBExportComments$PB動(dòng)態(tài)腳本解釋器應(yīng)用對(duì)象?
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í)行動(dòng)態(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 動(dòng)態(tài)代碼?
返回值:? string 用戶自定義或錯(cuò)誤信息?
功能描述:執(zhí)行動(dòng)態(tài)代碼(只返回字符串)?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2007-02-12?
版本號(hào):? 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)建實(shí)體對(duì)象?
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í)行動(dòng)態(tài)代碼?
?? ls_return = string(la_return)?
? case '','none'?
?? luo_pbcompiler.dynamic of_exec()//執(zhí)行動(dòng)態(tài)代碼?
?? ls_return = "none"?
? case else?
?? luo_pbcompiler.dynamic of_exec()//執(zhí)行動(dòng)態(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ù)組元素個(gè)數(shù)?
功能描述:分析字符串到一個(gè)數(shù)組中?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2002-11-19?
版本號(hào):? 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 第幾個(gè)特征替換字符串需替換,0表示全部?
返回值:? string 替換后字符串?
功能描述:用一特征字符串替換指定字符串中的特征字符串,參數(shù)al_seq=0時(shí)表示全部替換?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2002-11-19?
版本號(hào):? 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動(dòng)態(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?
//打開一個(gè)會(huì)話?
Function long SessionOpen () Library "PBORC90.DLL" Alias for "PBORCA_SessionOpen"?
//關(guān)閉一個(gè)會(huì)話?
Subroutine SessionClose ( long hORCASession ) Library "PBORC90.DLL" Alias for "PBORCA_SessionClose"?
//設(shè)置當(dāng)前會(huì)話的庫(kù)清單?
Function int SessionSetLibraryList ( long hORCASession, ref string pLibNames[], int iNumberOfLibs) Library "PBORC90.DLL" Alias for "PBORCA_SessionSetLibraryList"?
//設(shè)置當(dāng)前會(huì)話對(duì)應(yīng)的應(yīng)用?
Function int SessionSetCurrentAppl ( long hORCASession, string lpszApplLibName, string lpszApplName ) Library "PBORC90.DLL" Alias for "PBORCA_SessionSetCurrentAppl"?
//導(dǎo)入并編譯實(shí)體?
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"?
//取臨時(shí)目錄?
Function long GetTempPath(long nBufferLength, ref string lpBuffer)? Library "kernel32" Alias for "GetTempPathA"?
//獲取一個(gè)已裝載模板的完整路徑名稱?
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 臨時(shí)路徑?
功能描述:取臨時(shí)路徑?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2006-12-26?
版本號(hào):? 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?
版本號(hào):? 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 動(dòng)態(tài)代碼?
??? as_libraryname ref string 創(chuàng)建的庫(kù)文件名稱?
??? as_entryname ref string 創(chuàng)建的實(shí)體名稱?
返回值:? long 是否成功(1表示成功,-1表示失敗)?
功能描述:根據(jù)動(dòng)態(tài)代碼創(chuàng)建實(shí)體?
創(chuàng)建人:? 康劍民?
創(chuàng)建日期:2007-02-12?
版本號(hào):? V1.0?
*******************************************************************/?
long ll_sid//會(huì)話編號(hào)?
long ll_index//對(duì)象序號(hào)?
string ls_librarylist[]//庫(kù)文件列表?
string ls_librarylist_tmp[]//庫(kù)文件列表(臨時(shí))?
string ls_temp_libraryname//臨時(shí)庫(kù)文件名稱?
string ls_temp_path//臨時(shí)目錄?
string ls_syntax//實(shí)體語法?
string ls_app_libraryname//應(yīng)用程序所在庫(kù)文件名稱?
integer li_result//結(jié)果?
string ls_entryname//對(duì)象名稱?
classdefinition lcd_app//應(yīng)用程序類定義對(duì)象?
string ls_librarylist_files//庫(kù)文件?
integer i,j//臨時(shí)變量?
//開發(fā)環(huán)境下直接退出?
if handle(GetApplication()) <= 0 then return -1?
//取庫(kù)文件列表?
ls_librarylist_files = getlibrarylist ()?
//取應(yīng)用對(duì)象所在pbl?
lcd_app = getapplication().classdefinition?
ls_app_libraryname = lcd_app.libraryname?
ls_temp_path = this.of_gettemppath( )//取臨時(shí)目錄?
//取待創(chuàng)建的臨時(shí)庫(kù)文件名稱?
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)建臨時(shí)庫(kù)文件?
LibraryCreate(ls_temp_libraryname,"臨時(shí)庫(kù)文件")?
f_parse(ls_librarylist_files,',',ls_librarylist)//分解字符串到數(shù)組?
//判斷庫(kù)文件是否存在并形成新列表?
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()//打開一個(gè)會(huì)話?
//設(shè)置當(dāng)前會(huì)話的庫(kù)清單?
li_result = SessionSetLibraryList (ll_sid, ls_librarylist, upperbound(ls_librarylist))?
if li_result = 0 then?????
//設(shè)置當(dāng)前會(huì)話對(duì)應(yīng)的應(yīng)用?
li_result = SessionSetCurrentAppl (ll_sid, ls_app_libraryname, getapplication().appname )?
?? if li_result = 0 then??????
? //取實(shí)體名稱(保證不重復(fù))?
? ll_index = 1?
? do while not isnull(FindClassDefinition("nvo_"+string(ll_index)))?
?? ll_index ++?
? loop?
? ls_entryname = "nvo_"+string(ll_index)?
? //實(shí)體聲明?
? 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?
? //實(shí)體語法尾部?
? 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)入并編譯實(shí)體?
? 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)閉一個(gè)會(huì)話?
as_libraryname = ls_temp_libraryname?
as_entryname=ls_entryname?
//加入新文件到庫(kù)文件搜索列表?
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動(dòng)態(tài)腳本解釋器測(cè)試窗口?
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腳本解釋器(測(cè)試)"?
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

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國(guó)汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場(chǎng)的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營(yíng)業(yè)績(jī)穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤(rùn)率延續(xù)升勢(shì) 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長(zhǎng) 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競(jìng)爭(zhēng)力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競(jìng)爭(zhēng)優(yōu)勢(shì)...

關(guān)鍵字: 通信 BSP 電信運(yùn)營(yíng)商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國(guó)電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場(chǎng) NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長(zhǎng)三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡(jiǎn)稱"軟通動(dòng)力")與長(zhǎng)三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉