天天看點

幾個WebBrowser相關的函數

 貼幾個 T WebBrowser 程式設計相關的函數。

{ 去掉 TWebBrowser 的邊框 }

procedure WB_Set3DBorderStyle(Sender: TWebBrowser; bValue: Boolean);

{ WebBrowser 從記憶體中讀取 HTML 檔案}

procedure WebBrowserLoadFromStream(WebBrowser: TWebBrowser; Stream: TStream);

procedure NavigateLoadFromStream(WebBrowser: TWebBrowser;  Stream:  TStream);

{ WebBrowser 從字元中讀取 HTML 檔案}

procedure WebBrowserLoadFromText(WebBrowser: TWebBrowser; HtmlText: String);

{ WebBrowser 儲存成 Html 檔案 }

function WebBrowserSaveHTMLCode(WebBrowser: TWebBrowser; const FileName: TFileName):  Boolean;

{ HTML 儲存成流 }

procedure SaveDocumentSourceToStream(Document: IDispatch; Stream: TStream);

uses Axctrls, ActiveX, MSHTML, OleCtrls, SHDocVw

幾個WebBrowser相關的函數

{ WB_Set3DBorderStyle }

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

procedure WB_Set3DBorderStyle(Sender: TWebBrowser; bValue: Boolean);

幾個WebBrowser相關的函數

var

幾個WebBrowser相關的函數

  Document: IHTMLDocument2;

幾個WebBrowser相關的函數

  Element: IHTMLElement;

幾個WebBrowser相關的函數

  StrBorderStyle: string;

幾個WebBrowser相關的函數

begin

幾個WebBrowser相關的函數

  //去掉邊框

幾個WebBrowser相關的函數

  try

幾個WebBrowser相關的函數

    Document := TWebBrowser(Sender).Document as IHTMLDocument2;

幾個WebBrowser相關的函數

    if Assigned(Document) then

幾個WebBrowser相關的函數

    begin

幾個WebBrowser相關的函數

      Element := Document.Body;

幾個WebBrowser相關的函數

      if Element <> nil then

幾個WebBrowser相關的函數

      begin

幾個WebBrowser相關的函數

        case BValue of

幾個WebBrowser相關的函數

          False: StrBorderStyle := 'none';

幾個WebBrowser相關的函數

          True: StrBorderStyle := '';

幾個WebBrowser相關的函數

        end;

幾個WebBrowser相關的函數

        Element.Style.BorderStyle := StrBorderStyle;

幾個WebBrowser相關的函數

      end;

幾個WebBrowser相關的函數

    end;

幾個WebBrowser相關的函數

  except

幾個WebBrowser相關的函數

    //..

幾個WebBrowser相關的函數

  end;

幾個WebBrowser相關的函數

end;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

{ WebBrowserLoadFromText }

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

procedure WebBrowserLoadFromText(WebBrowser: TWebBrowser; HtmlText: String);

幾個WebBrowser相關的函數

var

幾個WebBrowser相關的函數

  v: Variant;

幾個WebBrowser相關的函數

  IDoc: IHTMLDocument2;

幾個WebBrowser相關的函數

begin

幾個WebBrowser相關的函數

  WebBrowser.Navigate('about:blank');

幾個WebBrowser相關的函數

  repeat

幾個WebBrowser相關的函數

    Application.ProcessMessages;

幾個WebBrowser相關的函數

    Sleep(0);

幾個WebBrowser相關的函數

  until WebBrowser.ReadyState = READYSTATE_COMPLETE;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

  IDoc := WebBrowser.Document as IHTMLDocument2;

幾個WebBrowser相關的函數

  try

幾個WebBrowser相關的函數

    IDoc.designMode:='on';

幾個WebBrowser相關的函數

    while IDoc.readyState<>'complete' do

幾個WebBrowser相關的函數

      Application.ProcessMessages;

幾個WebBrowser相關的函數

    v:=VarArrayCreate([0,0],VarVariant);

幾個WebBrowser相關的函數

    v[0]:= HtmlText;

幾個WebBrowser相關的函數

    IDoc.write(PSafeArray(System.TVarData(v).VArray));

幾個WebBrowser相關的函數

    IDoc.designMode:='off';

幾個WebBrowser相關的函數

    while IDoc.readyState<>'complete' do

幾個WebBrowser相關的函數

      Application.ProcessMessages;

幾個WebBrowser相關的函數

  finally

幾個WebBrowser相關的函數

    IDoc := nil;

幾個WebBrowser相關的函數

  end;

幾個WebBrowser相關的函數

end;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

{ NavigateLoadFromStream }

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

procedure NavigateLoadFromStream(WebBrowser: TWebBrowser;  Stream:  TStream);

幾個WebBrowser相關的函數

begin

幾個WebBrowser相關的函數

  Stream.Seek(0, 0);

幾個WebBrowser相關的函數

  if Assigned(WebBrowser.Document) then

幾個WebBrowser相關的函數

    (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(Stream));

幾個WebBrowser相關的函數

end;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

{ WebBrowserLoadFromStream }

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

procedure WebBrowserLoadFromStream(WebBrowser: TWebBrowser;  Stream:  TStream);

幾個WebBrowser相關的函數

begin

幾個WebBrowser相關的函數

  WebBrowser.Navigate('about:blank');

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

  repeat

幾個WebBrowser相關的函數

    Application.ProcessMessages;

幾個WebBrowser相關的函數

    Sleep(0);

幾個WebBrowser相關的函數

  until WebBrowser.ReadyState = READYSTATE_COMPLETE;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

  NavigateLoadFromStream(WebBrowser, Stream);

幾個WebBrowser相關的函數

end;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

{ WebBrowserSaveHTMLCode }

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

function WebBrowserSaveHTMLCode(WebBrowser: TWebBrowser; const FileName: TFileName):  Boolean;

幾個WebBrowser相關的函數

var

幾個WebBrowser相關的函數

  ps: IPersistStreamInit;

幾個WebBrowser相關的函數

  fs: TFileStream;

幾個WebBrowser相關的函數

  sa: IStream;

幾個WebBrowser相關的函數

begin

幾個WebBrowser相關的函數

  ps := WebBrowser.Document as IPersistStreamInit;

幾個WebBrowser相關的函數

  fs := TFileStream.Create(FileName, fmCreate);

幾個WebBrowser相關的函數

  try

幾個WebBrowser相關的函數

    sa := TStreamAdapter.Create(fs, soReference) as IStream;

幾個WebBrowser相關的函數

    Result := Succeeded(ps.Save(sa, True));

幾個WebBrowser相關的函數

  finally

幾個WebBrowser相關的函數

    fs.Free;

幾個WebBrowser相關的函數

  end;

幾個WebBrowser相關的函數

end;

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

{ SaveDocumentSourceToStream }

幾個WebBrowser相關的函數
幾個WebBrowser相關的函數

procedure SaveDocumentSourceToStream(Document: IDispatch; Stream: TStream);

幾個WebBrowser相關的函數

var

幾個WebBrowser相關的函數

  PersistStreamInit: IPersistStreamInit;

幾個WebBrowser相關的函數

  StreamAdapter: IStream;

幾個WebBrowser相關的函數

begin

幾個WebBrowser相關的函數

  Stream.Size  :=  0;

幾個WebBrowser相關的函數

  Stream.Position  :=  0;

幾個WebBrowser相關的函數

  if Document.QueryInterface(IPersistStreamInit, PersistStreamInit) = S_OK then

幾個WebBrowser相關的函數

  begin

幾個WebBrowser相關的函數

    StreamAdapter := TStreamAdapter.Create(Stream, soReference);

幾個WebBrowser相關的函數

    PersistStreamInit.Save(StreamAdapter, False);

幾個WebBrowser相關的函數

    StreamAdapter := nil;

幾個WebBrowser相關的函數

  end;

幾個WebBrowser相關的函數

end;

幾個WebBrowser相關的函數