 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Danzer Guest
|
Posted: Mon Jul 21, 2003 9:12 pm Post subject: TCppWebBrowser->Document - View Source |
|
|
Are there any programming examples of accessing the text which defines
the HTML on a page? I would like to be able to read in a program each
line of text you see when you right-click on a page and select the View
Source option.
Danzer
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Jul 21, 2003 10:08 pm Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
"Danzer" <danzer767 (AT) yahoo (DOT) com> wrote
| Quote: | Are there any programming examples of accessing the text
which defines the HTML on a page? I would like to be
able to read in a program each line of text you see when you
right-click on a page and select the View Source option.
|
Have a look at this previous posting:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3b03faaf%24
1_1%40dnews
You might be able to use TPersistStream instead of IPersistFile so that you
do not need to use a temporary file, but I have not tried it myself yet.
Gambit
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Tue Jul 22, 2003 5:51 am Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | You might be able to use TPersistStream instead of IPersistFile so that you
do not need to use a temporary file, but I have not tried it myself yet.
|
In that case try:
http://tinyurl.com/hne5
Hans.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jul 22, 2003 8:10 am Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
"Hans Galema" <j.m.galema.dontusethis (AT) maartens (DOT) nl> wrote
Rather than manipulating the IStream manually, I would suggest using a
TStreamAdapter instead. That will allow you to pass a VCL TStream to
IPersistStreamInit::Save(), and it will then allow you to use the TStream
normally afterwards, such as passing it to a TMemo's LoadFromStream()
method. For example:
TComInterface<IHTMLDocument2> HTMLDoc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&HTMLDoc);
if( HTMLDoc )
{
TComInterface<IPersistStreamInit> HTMLStream;
HTMLDoc->QueryInterface(IID_IPersistStreamInit,
(LPVOID*)&HTMLStream);
if( HTMLStream )
{
TStringStream *StrStream = new TStringStream("");
try
{
TComInterface<IStream> Adapter(*new
TStreamAdapter(StrStream, soReference));
HTMLStream->Save(Adapter, true);
StrStream->Position = 0;
Memo1->Lines->LoadFromStream(StrStream);
}
__finally {
delete StrStream;
}
}
}
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jul 22, 2003 8:12 am Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
"Hans Galema" <j.m.galema.dontusethis (AT) maartens (DOT) nl> wrote
Rather than manipulating the IStream manually, I would suggest using a
TStreamAdapter instead. That will allow you to pass a VCL TStream to
IPersistStreamInit::Save(), and it will then allow you to use the TStream
normally afterwards, such as passing it to a TMemo's LoadFromStream()
method. For example:
TComInterface<IHTMLDocument2> HTMLDoc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&HTMLDoc);
if( HTMLDoc )
{
TComInterface<IPersistStreamInit> HTMLStream;
HTMLDoc->QueryInterface(IID_IPersistStreamInit,
(LPVOID*)&HTMLStream);
if( HTMLStream )
{
TStringStream *StrStream = new TStringStream("");
try
{
TComInterface<IStream> Adapter(*new
TStreamAdapter(StrStream, soReference));
HTMLStream->Save(Adapter, true);
StrStream->Position = 0;
Memo1->Lines->LoadFromStream(StrStream);
}
__finally {
delete StrStream;
}
}
}
Using this same technique, if you did want an actual AnsiString, after
loading the HTML content into the TStringStream via the TStreamAdapter, you
could use TStringStream's DataString property to extract the AnsiString.
You wouldn't have to allocate and fill it yourself manually.
Gambit
|
|
| Back to top |
|
 |
Danzer Guest
|
Posted: Tue Jul 22, 2003 1:29 pm Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Hans Galema" <j.m.galema.dontusethis (AT) maartens (DOT) nl> wrote in message
news:3f1cd0b9$1 (AT) newsgroups (DOT) borland.com...
|
[snip code]
| Quote: |
Using this same technique, if you did want an actual AnsiString, after
loading the HTML content into the TStringStream via the TStreamAdapter, you
could use TStringStream's DataString property to extract the AnsiString.
You wouldn't have to allocate and fill it yourself manually.
Gambit
|
Perfect. That is just what I need.
Many Thanks,
Danzer
|
|
| Back to top |
|
 |
Danzer Guest
|
Posted: Tue Jul 22, 2003 8:05 pm Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | TComInterface<IStream> Adapter(*new
TStreamAdapter(StrStream, soReference));
|
I had to change the above code fragment to the following.
/* begin changed code */
TComInterface<IStream> Adapter(*new
TStreamAdapter(StrStream, soReference),true);
/* end changed code */
This change prevented an exception from being raised. I am not
proficient with COM applications. What are the ramifications of
changing the addRef parameter to true?
Danzer
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jul 22, 2003 9:08 pm Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
"Danzer" <danzer767 (AT) yahoo (DOT) com> wrote
| Quote: | I had to change the above code fragment to the following.
snip |
The orignal code I posted earlier worked fine for me when I tested it.
| Quote: | This change prevented an exception from being raised.
|
I would expect that change to introduce a memory leak, not solve an
exception. The original code did not generate any exceptions when I tested
it myself before posting it. Which version of Builder are you using? I
wrote and tested the code in BCB5.
| Quote: | I am not proficient with COM applications. What are
the ramifications of changing the addRef parameter to true?
|
You force the TStreamAdapter to have its reference count incremented an
additional time that was not needed. Interfaces do not free themselves
until the reference count falls to 0. Your change causes the reference
count to remain at 1. Interface reference counts already start at 1, and
then you are incrementing it again, but then only releasing the interface
once instead of the needed twice in order to keep the reference count
balanced.
Gambit
|
|
| Back to top |
|
 |
Danzer Guest
|
Posted: Wed Jul 23, 2003 1:21 pm Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | I would expect that change to introduce a memory leak, not solve an
exception. The original code did not generate any exceptions when I tested
it myself before posting it. Which version of Builder are you using? I
wrote and tested the code in BCB5.
|
I am using BCB6. Consider the following code fragments from Utilcls.h.
The fragments are executed by the instantiation and destruction of the
Adapter object.
/* begin code fragments */
TComInterface(T* p, bool addRef = false)
{
if (((intf = p) != 0) && addRef)
intf->AddRef(); // Line A.
}
void Reset(T* p = 0)
{
if (intf)
intf->Release(); // Line B.
intf=p;
}
/* end code fragments */
Your version does not execute "Line A" and attempts to execute "Line B"
(called from destructor). "Line B" in your version causes the
exeception. In my version "Line A" and "Line B" are executed with no
exceptions.
Danzer
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jul 23, 2003 6:24 pm Post subject: Re: TCppWebBrowser->Document - View Source |
|
|
"Danzer" <danzer767 (AT) yahoo (DOT) com> wrote
| Quote: | I am using BCB6. Consider the following code fragments from Utilcls.h.
|
I am already aware of the UTILCLS code, and my code snippet was already
taking that into account. I was intentionally passing the TStreamAdapter to
the TComInterface constructor rather than using the '=' operator
specifically for the reason that the constructor does not call AddRef() by
default, which is the behavior I actually wanted. I did not want the code
to call AddRef() on the TStreamAdapter otherwise the reference count would
be wrong, as I pointed out earlier.
| Quote: | Your version does not execute "Line A"
|
I know. I did not want it to.
| Quote: | and attempts to execute "Line B" (called from destructor).
|
Correct. That is fine.
| Quote: | "Line B" in your version causes the exeception.
|
Not when I run it, it didn't.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|