全國最多中醫師線上諮詢網站-台灣中醫網
上鎖的討論區 上鎖的討論區 瀏覽次數:2523
推到 Plurk!
推到 Facebook!

Delphi程式設計感想補遺--如何避免active x Form的安全性問題(word檔案部分)

 
delphiwww
資深會員


發表:145
回覆:363
積分:368
註冊:2002-03-13

發送簡訊給我
#1 發表時間:2002-12-31 11:06:22 IP:202.145.xxx.xxx 未訂閱
如題
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#2 發表時間:2002-12-31 12:21:20 IP:192.168.xxx.xxx 未訂閱
站長轉貼內文供參考    Delphi程式設計感想補遺—如何避開Active X Form的安全性問題 Write by Delphiwww 只要是寫過Active X Form的人都知道,當使用者開啟一個Active X Form時,有兩個煩人的問題: 1.        需要設定對該網站的安全性:當然另外可以利用數位簽章的方式,對該程式進行加簽的聲明,可以不需要設定程式的安全性。 2.        開啟Active X Form的安全性警告:由於Active X Form會對Client端進行ocx的安裝,所以不可避免的是會有安全性警告的問題。 事實上,以上兩個問題都可以用一個方法解決,就是將網頁與Ocx通通都移到Client端來執行,就不需要再設定安全性同時也不會再提出安全性的警告,各位讀者可以自行測試一下,測試的方式如下: 1.        將網頁與ocx複製到local端(請記得先移除在電腦上的ocx,同時清除信任的網域)。 2.        修改網頁內容:將原來有http://…的部分取消,範例如下:(如表1,2) 表1,原來的Active X Form的內容    表2,處理過的Active X Form的內容 3.        直接執行該網頁 經由以上的處理,相信各位讀者一定會發現,原來在local執行一個Active X Form並不會有Active X Form的安全性問題,為了方便處理Delphi Active X Form的分發,以避免需要另外使用人工更改htm檔,筆者利用更改之前所介紹的CallIE程式,成為GetAx程式,用來判別版本及更新抓取ocx(當然本程式並不適用夾帶其他dll、ocx或bpl的程式),程式設計如下: 1.        程式啟動時,啟動Timer。 procedure TForm1.FormCreate(Sender: TObject); begin    Timer1.Enabled:=true; end; 2.        在Timer1的OnTimer下,有以下幾個動作 a.        抓取需要啟動的htm名稱:止抓取第一行 b.        利用NMHttp抓取在網路上htm的內容,並取得ocx的版本(當然程式設計者假如在Intranet另外可以利用檔案管理程式,直接取得該檔案,並複製該檔案) c.        抓取local端htm的ocx版本的內容,並與網路上htm的ocx版本做比較。 d.        假如網路上的ocx版本較大,則更新ocx(用nmhttp去下載,local端可以用copyfile的api函數),並更改local端的htm檔案。 e.        啟動IE並呼叫該htm    程式設計如下: procedure TForm1.Timer1Timer(Sender: TObject); var s,s1,ver1,ver2:string;     f:textfile;     i,j,k:integer;     IE:olevariant;     st:Tstringlist;     filename,ocxname:string; begin    Timer1.Enabled:=false;    s:= ChangeFileExt(Application.ExeName,'.txt');    if fileexists(s) then  //設定檔,需要執行程式,請先設定內容    begin       assignfile(f,s);       reset(f);       readln(f,s);       closefile(f);       s1:=s;       s1:=Extractfilename(s1);       i:=pos('/',s1);       while (i>0) do       begin          s1:=copy(s1,i+1,length(s1)-i);          i:=pos('/',s1);       end;       filename:=extractfilepath(application.ExeName)+s1;       if fileexists(filename) then       begin          st:=Tstringlist.Create;          st.LoadFromFile(filename);          ver1:=getver(st.Text);          st.Free;       end else          ver1:='';       try          StatusBar1.SimpleText := '比較版本中...';          application.ProcessMessages;          nmhttp1.Get(s);          s:=nmhttp1.Body;          ver2:=getver(s);          if compar(ver1,ver2) then          begin             i:=pos('<OBJECT',s); s:=copy(s,1,6) copy(s,i,length(s)-i-1); i:=pos('width',s); j:=pos('align',s); s:=copy(s,1,i-1) 'width=100%' ' height=100% ' copy(s,j,length(s)-j 1); i:=pos(uppercase('codebase="'),uppercase(s)); j:=pos(uppercase('#version='),uppercase(s)); ocxname:=copy(s,i length('codebase="'),j-i-length('codebase="')); s1:=Extractfilename(ocxname); k:=pos('/',s1); while (k>0) do begin s1:=copy(s1,k 1,length(s1)-k); k:=pos('/',s1); end; s:=copy(s,1,i length('codebase="')-1) s1 copy(s,j,length(s)-j 1); assignfile(f,filename); rewrite(f); write(f,s); closefile(f); StatusBar1.SimpleText := '下載新版本中...'; Application.ProcessMessages; nmhttp1.Get(ocxname); s:=nmhttp1.Body; ocxname:=extractfilepath(application.ExeName) Extractfilename(s1); assignfile(f,ocxname); rewrite(f); write(f,s); closefile(f); end; ie:=CreateOleObject('InternetExplorer.Application'); ie.addressbar:=true; ie.menubar:=true; ie.Statusbar:=true; ie.toolbar:=0; ie.registerasbrowser:=true; ie.Navigate(filename); ie.visible:=true; except showmessage('連線失敗'); end; end; self.Close; end; 比較版本 function TForm1.compar(s1,s2:string):boolean; var i,j:integer; a,b:integer; begin i:=pos(',',s1); j:=pos(',',s2); if (s1='') then a:=0 else a:=strtoint(copy(s1,1,i-1)); if (s2='') then b:=0 else b:=strtoint(copy(s2,1,j-1)); while (a=b) and (length(s1)>0) and (length(s2)>0) do begin s1:=copy(s1,i 1,length(s1)-i); s2:=copy(s2,i 1,length(s2)-i); i:=pos(',',s1); j:=pos(',',s2); if i=0 then i:=length(s1) 1; if j=0 then j:=length(s2) 1; if (s1='') then a:=0 else a:=strtoint(copy(s1,1,i-1)); if (s2='') then b:=0 else b:=strtoint(copy(s2,1,j-1)); end; result:=a0 then begin s:=copy(s,i length('version='),length(s)-i-length('version=') 1); i:=pos('"',s); result:=copy(s,1,i-1) end; end; 程式執行畫面,如圖40、圖41 圖40 圖41
------
~~~Delphi K.Top討論區站長~~~
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#3 發表時間:2002-12-31 12:23:41 IP:192.168.xxx.xxx 未訂閱
程式原始檔部份在此:http://delphi.ktop.com.tw/topic.php?TOPIC_ID=24464 ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
moxa
一般會員


發表:2
回覆:7
積分:1
註冊:2002-04-15

發送簡訊給我
#4 發表時間:2003-03-14 09:50:37 IP:202.39.xxx.xxx 未訂閱
你好 程式說明文件無法下載....請協助,THANK YOU
delphiwww
資深會員


發表:145
回覆:363
積分:368
註冊:2002-03-13

發送簡訊給我
#5 發表時間:2003-03-14 15:51:32 IP:202.145.xxx.xxx 未訂閱
不會啊,你是從哪一個主機?
引言: 你好 程式說明文件無法下載....請協助,THANK YOU
系統時間:2024-04-20 6:58:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!