Solved

TWebBrowser LOAD FROM MEMO

Posted on 2002-05-25
5
1,163 Views
Last Modified: 2012-05-04
TWebBrowser LOAD FROM MEMO

How to load WebBrowser1 HTML from Memo1.Text (HTML TEXT) ?

Thanks.
0
Comment
Question by:treqw
5 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 350 total points
ID: 7034242
Hi treqw,

maybe this can get you going a bit
http://www.swissdelphicenter.ch/torry/showcode.php?id=1096&PHPSESSID=813405c0944d27364a4d6dff9ae62775

you can put the memo text into the html string

HTH:O)Bruintje
0
 
LVL 8

Expert Comment

by:Cesario
ID: 7034295
uses ActiveX;

{Loads the contents of the "Stream" into the "WebBrowser"
"Stream" should contain HTML code}
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;


{Let's test. You could also create a TResourceStream or TFileStream etc. here.}
procedure TForm1.Button2Click(Sender: TObject);
var
  S: TStringStream;
begin
  {To use this code, replace [ ] brackets with <> ones in the following two lines !}
  S:= TStringStream.Create(Memo1.Text)
  try
    LoadStream(WebBrowser1, S);
  finally
    S.Free;
  end;
end;

Best Regards

Cesario
0
 

Expert Comment

by:delpro
ID: 7034414
go to http://www.pbear.com/ 
and download the HTML Display Components

This is how easy it is.

   HTMLViewer1.LoadFromString(memo1.Text);
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7034429
nice :)
another way would be to install EmbededWB from http://www.euromind.com/iedelphi/
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7034612
wow, thanks for the grade
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now