Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Loading HTML directly into TCppWebBrowser



Permlink Replies: 5 - Last Post: Dec 12, 2016 10:39 AM Last Post By: Remy Lebeau (Te...
Milan Bačík

Posts: 10
Registered: 2/4/11
Loading HTML directly into TCppWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 9, 2016 6:02 AM
I'am trying to translate code to load HTML directly to TCppWebbrowser from pascal to C++ I'am stuck with following cast:
      (mWebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(HTMLStream));

Where mWebBrowser is declared as TWebBrowser pointer in pascal.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Loading HTML directly into TCppWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 9, 2016 10:13 AM   in response to: Milan Bačík in response to: Milan Bačík
El 09/12/2016 a las 15:02, Milan Bačík escribió:
I'am trying to translate code to load HTML directly to TCppWebbrowser from pascal to C++ I'am stuck with following cast:
      (mWebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(HTMLStream));

Where mWebBrowser is declared as TWebBrowser pointer in pascal.


Try this:

    mWebBrowser->Navigate(L"about:blank");
    while (mWebBrowser->ReadyState< READYSTATE_LOADED)
       Application->ProcessMessages();
 
    TComInterface<IPersistStreamInit> pPSI;
    if(SUCCEEDED(mWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&pPSI)))
    {
       _di_IStream pStream= *(new TStreamAdapter(HTMLStream, soOwned));
       pPSI->Load(pStream);
    }


Note that TStreamAdapter is created with the ownership parameter set to soOwned, so you don't must free HTMLStream
Milan Bačík

Posts: 10
Registered: 2/4/11
Re: Loading HTML directly into TCppWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 8:14 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 09/12/2016 a las 15:02, Milan Bačík escribió:
I'am trying to translate code to load HTML directly to TCppWebbrowser from pascal to C++ I'am stuck with following cast:
      (mWebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(HTMLStream));

Where mWebBrowser is declared as TWebBrowser pointer in pascal.


Try this:

    mWebBrowser->Navigate(L"about:blank");
    while (mWebBrowser->ReadyState< READYSTATE_LOADED)
       Application->ProcessMessages();
 
    TComInterface<IPersistStreamInit> pPSI;
    if(SUCCEEDED(mWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&pPSI)))
    {
       _di_IStream pStream= *(new TStreamAdapter(HTMLStream, soOwned));
       pPSI->Load(pStream);
    }


Note that TStreamAdapter is created with the ownership parameter set to soOwned, so you don't must free HTMLStream

Well this code works if called in button click event. But if I call it from TDataSet.AfterScroll event, then Application->ProcessMessages() causes "recursive" call of TDataSet.AfterScroll event. I tryed several workarounds without succes(separete thread, unregestering AfterScroll event before straming data ...). Any idea?
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Loading HTML directly into TCppWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 8:34 AM   in response to: Milan Bačík in response to: Milan Bačík
El 12/12/2016 a las 17:14, Milan Bačík escribió:
Antonio Estevez wrote:
El 09/12/2016 a las 15:02, Milan Bačík escribió:
I'am trying to translate code to load HTML directly to TCppWebbrowser from pascal to C++ I'am stuck with following cast:
      (mWebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(HTMLStream));

Where mWebBrowser is declared as TWebBrowser pointer in pascal.


Try this:

    mWebBrowser->Navigate(L"about:blank");
    while (mWebBrowser->ReadyState< READYSTATE_LOADED)
       Application->ProcessMessages();
 
    TComInterface<IPersistStreamInit> pPSI;
    if(SUCCEEDED(mWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&pPSI)))
    {
       _di_IStream pStream= *(new TStreamAdapter(HTMLStream, soOwned));
       pPSI->Load(pStream);
    }


Note that TStreamAdapter is created with the ownership parameter set to soOwned, so you don't must free HTMLStream

Well this code works if called in button click event. But if I call it from TDataSet.AfterScroll event, then Application->ProcessMessages() causes "recursive" call of TDataSet.AfterScroll event. I tryed several workarounds without succes(separete thread, unregestering AfterScroll event before straming data ...). Any idea?

The following code needs to execute only one time so try to move it to
the Form's OnShow event by example.

      mWebBrowser->Navigate(L"about:blank");
      while (mWebBrowser->ReadyState< READYSTATE_LOADED)
         Application->ProcessMessages();
Milan Bačík

Posts: 10
Registered: 2/4/11
Re: Loading HTML directly into TCppWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 10:27 AM   in response to: Antonio Estevez in response to: Antonio Estevez


The following code needs to execute only one time so try to move it to
the Form's OnShow event by example.

      mWebBrowser->Navigate(L"about:blank");
      while (mWebBrowser->ReadyState< READYSTATE_LOADED)
         Application->ProcessMessages();

Thank you, works like a charm now.

Edited by: Milan Bačík on Dec 12, 2016 10:27 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Loading HTML directly into TCppWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 10:39 AM   in response to: Milan Bačík in response to: Milan Bačík
Milan wrote:

Well this code works if called in button click event. But if I call it
from TDataSet.AfterScroll event, then Application->ProcessMessages()
causes "recursive" call of TDataSet.AfterScroll event. I tryed
several workarounds without succes(separete thread, unregestering
AfterScroll event before straming data ...). Any idea?

Rethink your approach. TCppWebBrowser is a visual UI component. It requires
message processing in order for it to progress through its state machine.
The browser must be in the proper state before you can stream HTML data
into it.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02