在PB中使用JavaScript指令碼函數

來源:互聯網
上載者:User

     現在許多的資訊系統都是基於B/S版本,但PB寫的資訊系統生存空間也比較大,往往是一個資訊系統即有PB版本也有B/S版本。資訊系統會有許多的商務規則,B/S中商務規則的檢查在JavaScript指令碼中實現,如果在PB中又實現一次,費時費力不說,

商務規則改變又要重新編譯分發。如果在PB中調用在B/S中實現的JavaScript指令碼來完成商務規則,省時省力維護量減小,下面就讓我們來實現吧。

    一、環境說明

           在PB中運行指令碼語言需要藉助msscript.ocx組件。註冊表中的對象是MSScriptControl.ScriptControl.

           運行regedit.exe尋找一下看是否已存在,如果沒有就下載一個吧,別忘了註冊呵!

  二、在PB中聲明

         oleobject io_script

         io_script = create oleobject
long ll_1=io_script.connecttonewobject( "MSScriptControl.ScriptControl")
if ll_1<>0 then
    messagebox('提示','建立MSScriptControl.ScriptControl對象出錯,請註冊msscript.ocx')
    return -1
end if

 

三、裝入js檔案

li_file = FileOpen(gs_currentpath+"Check.js")
if li_file=-1 then
 return -1
end if
li_readline=FileRead ( li_file, ls_1 )
do while li_readline>-1
 ls_js=ls_js+ls_1+'~r~n'
 li_readline=FileRead ( li_file, ls_1 )
loop
fileclose(li_file)
io_script.language="JScript"
io_script.addcode(ls_js)

 

四、調用JS中的函數

 

any la_1=io_script.run("CheckFile",ls_filename)

CheckFile 是JS中的函數,ls_filename是CheckFile 函數的參數。

 

還用等什麼,趕快試試吧!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.