乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      關(guān)于WebBrowser使用的問(wèn)題,從流中載入出問(wèn)題 = = 求教高人指點(diǎn)

       quasiceo 2014-07-14

      關(guān)于WebBrowser使用的問(wèn)題,從流中載入出問(wèn)題 = = 求教高人指點(diǎn) [問(wèn)題點(diǎn)數(shù):100分,結(jié)帖人Anikox]

      Anikox
      關(guān)注
      Anikox
      Anikox
      等級(jí):Blank
      結(jié)帖率:83.33%
      樓主 發(fā)表于: 2006-10-27 10:32:27
      思路大概這個(gè)樣子,把WebBrowser數(shù)據(jù)寫(xiě)到流里面,然后將流寫(xiě)入字符串,進(jìn)行一部分替換以后,再將字符串寫(xiě)入流,再載入WebBrowser中。大概的功能就是,在某個(gè)網(wǎng)站提交表單中加入某個(gè)提交項(xiàng),然后一起提交。

      本人剛學(xué)Delphi沒(méi)多久,下面的問(wèn)題沒(méi)辦法解決了,眼淚阿 T_T

      我貼出原碼部分:

      ______________________________________________________________________

      這段是從網(wǎng)上找來(lái)的LoadStream和 SaveDocumentSourceToStream

      procedure  LoadStream(WebBrowser:  TWebBrowser;  Stream:  TStream);
      var
      PersistStreamInit:  IPersistStreamInit;
      StreamAdapter:  IStream;
      MemoryStream:  TMemoryStream;
      begin
      {Load  empty  HTML  document  into  Webbrowser  to  make  "Document"  a  valid  HTML  document}
      WebBrowser.Navigate('about:blank');
      {wait  until  finished  loading}
      repeat
      Application.ProcessMessages;
      Sleep(0);
      until
      WebBrowser.ReadyState  =  READYSTATE_COMPLETE;
      {Get  IPersistStreamInit  -  Interface}
      if  WebBrowser.Document.QueryInterface(IPersistStreamInit,  PersistStreamInit)  =  S_OK  then
      begin
      {Clear  document}
      if  PersistStreamInit.InitNew  =  S_OK  then
      begin
      {Make  local  copy  of  the  contents  of  Stream  if  you  want  to  use  Stream  directly,  you  have  to
      consider,  that  StreamAdapter  will  destroy  it  automatically}
      MemoryStream:=  TMemoryStream.Create;
      try
      MemoryStream.CopyFrom(Stream,  0);
      MemoryStream.Position:=  0;
      except
      MemoryStream.Free;
      raise;
      end;
      {Use  Stream-Adapter  to  get  IStream  Interface  to  our  stream}
      StreamAdapter:=  TStreamAdapter.Create(MemoryStream,  soOwned);
      {Load  data  from  Stream  into  WebBrowser}
      PersistStreamInit.Load(StreamAdapter);
      end;
      end;
      end;



      procedure  SaveDocumentSourceToStream(Document:  IDispatch;  Stream:  TStream);
      var
      PersistStreamInit:  IPersistStreamInit;
      StreamAdapter:  IStream;
      begin
      Stream.Size  :=  0;
      Stream.Position  :=  0;
      if  Document.QueryInterface(IPersistStreamInit,  PersistStreamInit)  =  S_OK  then
      begin
      StreamAdapter  :=  TStreamAdapter.Create(Stream,  soReference);
      PersistStreamInit.Save(StreamAdapter,  False);
      StreamAdapter  :=  nil;
      end;
      end;

      _____________________________________________________________


      下面是替換功能部分:


      procedure TForm1.Button2Click(Sender: TObject);
      var
        SS: TStringStream;
        SS3: TStringStream;
        Document: IDispatch;
        ss1 : String;
        ss2 : String;

      begin
        SS := TStringStream.Create('');
        try
        SaveDocumentSourceToStream(WebBrowser1.Document, SS);
         ss1 := SS.DataString ;

          ss2 := AnsiReplaceText(ss1,'</form>','加入的代碼</form>');
          SS.Free;
          SS3 := TStringStream.Create(ss2);
          LoadStream(WebBrowser1, SS3);
        finally
          SS3.Free;
        end;
      end;


      ——————————————————————————————————————————


      問(wèn)題是~~替換是能替換~~~可是顯示出來(lái)的可就不是那么回事了:

      http://img226./img226/7395/1zs7.jpg

      http://img208./img208/9917/2ba0.jpg

      最后一個(gè)最不明白~~為啥路徑都變成about.blank:了。。。。那個(gè)不是初始化的代碼么 T-T

      http://img142./img142/3694/3vf6.jpg

      還是我的思路根本就錯(cuò)了?

      望高人指點(diǎn)!
      回復(fù)次數(shù):4
      zzq4823
      關(guān)注
      zzq4823
      zzq4823
      等級(jí):Blank
      #1 得分:0 回復(fù)于: 2006-10-27 11:16:45
      你怎么確定     ~~替換是能替換~~~
      我覺(jué)得就沒(méi)有替換成功,你定義ss1:string,好象只能處理255各字符
      jiangsheng
      關(guān)注
      jiangsheng 版主
      蔣晟
      等級(jí):Blank
      11
      更多勛章
      #2 得分:60 回復(fù)于: 2006-10-27 13:57:37
      The easiest way to do this is to embed a <base> tag into the generated 
      HTML. You don't have to save it to disk, or make visible to the user, 
      just feed it in the stream with the rest of the content. 

      Another way is to write a custom implementation of IMoniker interface. 
      You only need a non-trivial implementation of two methods: BindToStorage 
      should return the IStream with your HTML content, and GetDisplayName 
      should return the base URL you want to use to resolve relative links. 
      You then use IPersistMoniker to feed the content into MSHTML using this 
      custom implementation, instead of IPersistStreamInit. Disclaimer: I have 
      not done this myself, but I've seen people reporting successful use of 
      this technique. 
      -- 
      With best wishes, 
          Igor Tandetnik 


      happyggy
      關(guān)注
      happyggy
      happyggy
      等級(jí):Blank
      #3 得分:40 回復(fù)于: 2006-10-27 15:14:26
      //get html 源碼
      function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean;
      var
        ps: IPersistStreamInit;
        s: string;
        ss: TStringStream;
        sa: IStream;
      begin
        ps := WB.document as IPersistStreamInit;
        s := '';
        ss := TStringStream.Create(s);
        try
          sa := TStreamAdapter.Create(ss, soReference) as IStream;
          Result := Succeeded(ps.Save(sa, Bool(True)));
          if Result then ACode.Add(ss.Datastring);
        finally
          ss.Free;
        end;
      end;
      //webbrowser 載入html源碼
      procedure WB_LoadHTML(WebBrowser: TWebBrowser; HTMLCode: string);
      var
        sl: TStringList;
        ms: TMemoryStream;
      begin
        if Assigned(WebBrowser.Document) then
        begin
          sl := TStringList.Create;
          try
            ms := TMemoryStream.Create;
            try
              sl.Text := HTMLCode;
              sl.SaveToStream(ms);
              ms.Seek(0, 0);
              (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
            finally
              ms.Free;
            end;
          finally
            sl.Free;
          end;
        end;
      end;
      //---------------------
      你先取源碼,修改完源碼后再載入
      Anikox
      關(guān)注
      Anikox
      Anikox
      等級(jí):Blank
      #4 得分:0 回復(fù)于: 2006-10-31 15:06:20
      終于弄好了~~開(kāi)始我的方法也是對(duì)的~~只是一個(gè)相對(duì)路徑的問(wèn)題在搗亂啊~~

      謝謝答復(fù)的各位了 ^^

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類(lèi)似文章 更多