Hi,
I got this code from another website, and I am posting it here just in case more people need to work with the TCppWebBrowser.
Hopefully Borland will improve in component in the next Builder version.
Cheers,
Mick
Original link:
http://www.tek-tips.com/viewthread.cfm?qid=327272
Just copy/paste this code and you will end up with an AnsiString with the HTML. You can do whatever you want with that afterwards...
My code after copying/pasting and adapting the one from the link above:
Code:
IHTMLDocument2* htm = NULL; // #include <mshtml.h>
AnsiString Source;
if(CppWebBrowser1->Document)
{
if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&htm)))
{
IPersistStreamInit* spPsi = NULL; // ocidl.h
if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&spPsi)) && spPsi)
{
IStream *spStream = NULL; // objidl.h
OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
if(spStream)
{
__int64 nSize = 0;
STATSTG ss;
LARGE_INTEGER nMove;
nMove.QuadPart = 0;
OleCheck(spPsi->Save(spStream, true));
OleCheck(spStream->Seek(nMove, STREAM_SEEK_SET, (ULARGE_INTEGER*)&nSize));
OleCheck(spStream->Stat(&ss, STATFLAG_NONAME));
nSize = ss.cbSize.QuadPart;
Source.SetLength(nSize);
OleCheck(spStream->Read((void *)Source.data(), nSize, (ULONG*)&nSize));
OleCheck(spStream->Release());
}
spPsi->Release();
}
htm->Release();
}
}
MemoResults->Lines->Add(Source);