線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2044
推到 Plurk!
推到 Facebook!

看了先進的webbrowser 編碼, 但還是有問題....

尚未結案
tunnerking
一般會員


發表:8
回覆:1
積分:1
註冊:2003-12-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-02-18 11:15:14 IP:202.64.xxx.xxx 未訂閱
我試著把這個function 放到新的project用, 絕對沒有問題! procedure BrowserHtml(); var     hr: HRESULT;     pUnkBrowser, pUnkDisp: IUnknown;     pStream: IStream;     hHTMLText: HGLOBAL;     pHtmlDoc: IDispatch;     pPersistStreamInit: IPersistStreamInit;     szHTMLText: PChar;        Null : Variant; const     IID_IPersistStreamInit: TGUID = (     D1:$7FD52380;D2:$4E07;D3:$101B;D4:($AE,$2D,$08,$00,$2B,$2E,$C7,$13));        begin      //     try     szHTMLText:=PChar('<html>hihihihih</html>'); hHTMLText := GlobalAlloc(GPTR, StrLen(szHTMLText) 1); if (hHTMLText = Null) then Exit; lstrcpy(pchar(hHTMLText), szHTMLText); hr := CreateStreamOnHGlobal(hHTMLText, TRUE, pStream); pHtmlDoc := webContent.Document; hr := pHtmlDoc.QueryInterface(IID_IPersistStreamInit, pPersistStreamInit); if (SUCCEEDED(hr)) then begin hr := pPersistStreamInit.InitNew; if (SUCCEEDED(hr)) then begin hr := pPersistStreamInit.Load(pStream); end; pPersistStreamInit := nil; end; finally end; end; //========================================================= 但是當我加到另一個program裏時, 就出現error! Project abc.exe raised exception class EAccessViolation with message 'Access violation at address 635F544C in module 'mshtml.dll'. Read of address 000000'. Process stopped . Use step or run to continue.
David
一般會員


發表:13
回覆:26
積分:7
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-02-28 03:30:27 IP:203.217.xxx.xxx 未訂閱
你好,如果你確認你的mshtml.dll沒壞掉(因為網路上有人說這檔案會壞掉,跟IE有關,如果壞掉需衝灌IE),要不要再注意看看我做修改的部分,試試能不能run: 不一樣的部分有兩個: 1 在Form的Create event下增加一行code webContent.Navigate('about:blank'); 2 REMARK掉NULL的宣告,不過這可能是因為你用了Delphi6(我猜的)的原因,我是用Delphi5,所以不需要這行,所以如果我猜對的話,這行應該不需要變更。 3 最後再查閱最上面的uses部分,是否有遺漏。 Lucky. ================== unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, ActiveX, StdCtrls; type TForm1 = class(TForm) webContent: TWebBrowser; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } procedure BrowserHtml(); end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.BrowserHtml(); var hr: HRESULT; pUnkBrowser, pUnkDisp: IUnknown; pStream: IStream; hHTMLText: HGLOBAL; pHtmlDoc: IDispatch; pPersistStreamInit: IPersistStreamInit; szHTMLText: PChar; //Null : Variant; const IID_IPersistStreamInit: TGUID = ( D1:$7FD52380;D2:$4E07;D3:$101B;D4:($AE,$2D,$08,$00,$2B,$2E,$C7,$13)); begin // try szHTMLText:=PChar('hihihihih'); hHTMLText := GlobalAlloc(GPTR, StrLen(szHTMLText) 1); if (hHTMLText = Null) then Exit; lstrcpy(pchar(hHTMLText), szHTMLText); hr := CreateStreamOnHGlobal(hHTMLText, TRUE, pStream); pHtmlDoc := webContent.Document; hr := pHtmlDoc.QueryInterface(IID_IPersistStreamInit, pPersistStreamInit); if (SUCCEEDED(hr)) then begin hr := pPersistStreamInit.InitNew; if (SUCCEEDED(hr)) then begin hr := pPersistStreamInit.Load(pStream); end; pPersistStreamInit := nil; end; finally end; end; procedure TForm1.Button1Click(Sender: TObject); begin BrowserHtml; end; procedure TForm1.FormCreate(Sender: TObject); begin webContent.Navigate('about:blank'); end; end. 發表人 - David 於 2004/02/28 03:31:36
favinc
一般會員


發表:22
回覆:19
積分:8
註冊:2003-03-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-26 03:02:54 IP:211.147.xxx.xxx 未訂閱
以下代码可供参考: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, StdCtrls, activex, stdactns, mshtml; type TForm1 = class(TForm) Button1: TButton; WebBrowser1: TWebBrowser; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } ms: TMemoryStream; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure DispHtmlFromText(const WebBrowser: TWebBrowser; const Text: string); var hr: HRESULT; pStream: IStream; hHTMLText: HGLOBAL; // pHtmlDoc: IDispatch; pPersistStreamInit: IPersistStreamInit; const IID_IPersistStreamInit: TGUID = '{7FD52380-4E07-101B-AE2D-08002B2EC713}'; //(D1: $7FD52380; D2: $4E07; D3: $101B; D4: ($AE, $2D, $08, $00, $2B, $2E, $C7, $13)); begin hHTMLText := GlobalAlloc(GPTR, StrLen(Pchar(Text)) 1); if (hHTMLText = NULL) then Exit; lstrcpy(Pchar(hHTMLText), Pchar(Text)); hr := CreateStreamOnHGlobal(hHTMLText, TRUE, pStream); hr := WebBrowser.Document.QueryInterface(IID_IPersistStreamInit, pPersistStreamInit); if (Succeeded(hr)) then begin hr := pPersistStreamInit.InitNew; if (Succeeded(hr)) then begin hr := pPersistStreamInit.Load(pStream); end; pPersistStreamInit := nil; end; end; procedure DispHtmlFromStream(const WebBrowser: TWebBrowser; const MStream: TStream); var hr: HRESULT; pStream: IStream; pPersistStreamInit: IPersistStreamInit; const IID_IPersistStreamInit: TGUID = '{7FD52380-4E07-101B-AE2D-08002B2EC713}'; // (D1: $7FD52380; D2: $4E07; D3: $101B; D4: ($AE, $2D, $08, $00, $2B, $2E, $C7, $13)); begin if MStream = nil then Exit; hr := WebBrowser.Document.QueryInterface(IID_IPersistStreamInit, pPersistStreamInit); if (Succeeded(hr)) then begin hr := pPersistStreamInit.InitNew; if (Succeeded(hr)) then begin pStream := TStreamAdapter.Create(MStream); hr := pPersistStreamInit.Load(pStream); end; pPersistStreamInit := nil; end; end; procedure TForm1.Button1Click(Sender: TObject); begin ms.Clear; with TFileOpen.Create(self) do try dialog.Filter := '*.htm;*.html|*.htm;*.html'; if dialog.Execute then begin ms.LoadFromFile(dialog.FileName); DispHtmlFromStream(WebBrowser1, ms); end; finally Free; end; end; procedure TForm1.FormCreate(Sender: TObject); begin WebBrowser1.Navigate('about:blank'); ms := TMemoryStream.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin ms.Free; end; procedure TForm1.Button2Click(Sender: TObject); var doc: IHTMLDocument2; all: IHTMLElementCollection; len, I: integer; item: OleVariant; begin doc := WebBrowser1.Document as IHTMLDocument2; all := doc.Get_links; len := all.length; for I := 0 to len - 1 do begin item := all.item(I, varempty); Memo1.lines.add(item.href); end; end; end. 兵临城下,快活如故。
------
兵临城下,快活如故。
系統時間:2024-11-22 12:07:29
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!