WebBrowser載入自定義HTML內容並顯示
阿新 • • 發佈:2019-01-05
use Winapi.ActiveX; //呼叫IPersistStreamInit類 procedure TForm1.Button2Click(Sender: TObject); var PostList: TStringList; Response, StrStream: TStringStream; ResultString: string; begin // 註冊 PostList := TStringList.Create; Response := TStringStream.Create('', TEncoding.UTF8); try IdHTTP1.HandleRedirects := True; PostList.Add('forward='); PostList.Add('jumpurl=http://www.hualongxiang.com/index.php'); PostList.Add('step=2'); PostList.Add('pwuser=' + Trim(Edit1.Text)); PostList.Add('lgt=0'); PostList.Add('pwpwd=' + Trim(Edit2.Text)); PostList.Add('cktime=31536000'); ResultString := IdHTTP1.Post('http://jia.hualongxiang.com/register.php', PostList); if Pos('200 OK', IdHTTP1.ResponseText) > 0 then begin Memo1.Lines.Add(ResultString); // 以下程式碼為WebBrowser顯示自定義HTML內容 WebBrowser1.Navigate('about:blank'); // 必要 StrStream := TStringStream.Create(ResultString); try StrStream.Position:=0; (WebBrowser1.Document as IPersistStreamInit).Load(TStreamadapter.Create(StrStream)); // 關鍵語句 finally StrStream.Free; end; // 至此結束 end; finally PostList.Free; Response.Free; end; end;