Board index » cppbuilder » CPPWebBrowser in thread

CPPWebBrowser in thread


2005-06-29 02:16:32 PM
cppbuilder99
Hi
i'm dynamically create CPPWebBrowser in a thread using this code . The
strange thing
is that i can load the page/content . If i use it in single thread program ,
it work like a charm .
I use SaveHTML() to see if it already success loading the content . So far ,
no luck.. the Save html
always result with blank page .
Please enlight me..i've been searching the newsgroup to look for multithread
topic..but there's none !
//--------------------------------------------------------------------------
-
CHTMLFormParser::CHTMLFormParser(String content)
{
parser = new TCppWebBrowser((TComponent *)NULL);
parser->TOleControl::Parent = (TWinControl*) FormMain;
TMemoryStream* pStream = new TMemoryStream();
pStream->Write(content.c_str(),content.Length());
LoadHtmlFromStream(parser, pStream);
//debug purpose
SaveHtml();
SAFE_DELETE(pStream);
try
{
Load();
}
catch (Exception &E)
{
}
}
//--------------------------------------------------------------------------
-
void CHTMLFormParser::LoadHtmlFromStream(TCppWebBrowser*
pCppWebBrowser,TMemoryStream* pMemStream)
{
if(pMemStream && pCppWebBrowser)
{
IPersistStreamInit* pPSI;
pMemStream->Seek(0, 0);
if(!pCppWebBrowser->Document)
{
pCppWebBrowser->Navigate(WideString("about:blank"));
while (pCppWebBrowser->ReadyState !=
Shdocvw_tlb::READYSTATE_COMPLETE )
{
Application->ProcessMessages();
}
}
TStreamAdapter* pStreamAdapter = new TStreamAdapter(pMemStream,
soReference);
if(SUCCEEDED(pCppWebBrowser->Document->QueryInterface(IID_IPersistStreamInit
, (LPVOID*)&pPSI)))
pPSI->Load(*pStreamAdapter);
if (pPSI) pPSI->Release();
}
}
//--------------------------------------------------------------------------
-
void CHTMLFormParser::SaveHtml()
{
IHTMLDocument2 *HTMLDocument;
IPersistFile *PersistFile;
parser->Document->QueryInterface(IID_IHTMLDocument,
&((void *)HTMLDocument) );
HTMLDocument->QueryInterface(IID_IPersistFile, &((void *)PersistFile));
PersistFile->Save(WideString("c:\\Output.html"), true);
PersistFile->Release();
HTMLDocument->Release();
}
//--------------------------------------------------------------------------
-
regards
bayufa
 
 

Re:CPPWebBrowser in thread

"bayufa" < XXXX@XXXXX.COM >wrote in message
Quote
i'm dynamically create CPPWebBrowser in a thread using this code .
You should not be doing that. TCppWebBrowser is a visual component. It
needs to be used from the main VCL thread only.
What EXACTLY are you trying to accomplish in the first place?
Gambit
 

Re:CPPWebBrowser in thread

Quote

"bayufa" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>i'm dynamically create CPPWebBrowser in a thread using this code .

You should not be doing that. TCppWebBrowser is a visual component. It
needs to be used from the main VCL thread only.

What EXACTLY are you trying to accomplish in the first place?
My plan is to use TCPPWebBrowser as HTML Parser for my application .
I create several thread that connect to a web site ( Indy HTTP ) and parse
it .
Any idea how to use TCPPWebBrowser inside a thread ?
thanks
bayufa
 

{smallsort}

Re:CPPWebBrowser in thread

"bayufa" < XXXX@XXXXX.COM >wrote in message
Quote
My plan is to use TCPPWebBrowser as HTML Parser for my application .
I create several thread that connect to a web site ( Indy HTTP ) and parse
it .
I do not recommend doing things that way.
Quote
Any idea how to use TCPPWebBrowser inside a thread ?
You cannot, nor should you. Use a real HTML parser instead.
Gambit