Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading "HTML string" into a new IHTMLDocument2

1,587 views
Skip to first unread message

Brendon Paine

unread,
Dec 13, 1999, 3:00:00 AM12/13/99
to
I want to be able to load a valid HTML string(or stream) into a document
which has no elements at all, a newly created document (I create the
document using the CoCreateInstance function:
CoCreateInstance(CLASS_HTMLDocument, nil, CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2, Doc); Doc is declared as IHTMLDocument2)

I have tried to use the IPersistStream interface, but the error I get is
'interface not supported'.

I have tried various other things(work arounds really, but noe seem to
work).

Can anybody shed some light on this for me.

Thanks

Brendon

Robert de Groote

unread,
Dec 13, 1999, 3:00:00 AM12/13/99
to
Hello Brendom,

I'm struggling with the same problem, and haven't worked anything out yet
too... I found a tutorial which explains how to load a HTML content from a
stream. I don't know how to do it, although it is described.. take a look
for yourself
http://msdn.microsoft.com/workshop/browser/webbrowser/tutorials/webocstream.
asp#stream
if you succeed in loading the HTML contents, please inform me in this
newsgroup.... I'm very eager to know how to solve this problem.....

good luck,
Robert de Groote.

Brendon Paine <bren...@korbitec.com> wrote in message
news:8328k5$ri...@forums.borland.com...

Ron Loewy

unread,
Dec 13, 1999, 3:00:00 AM12/13/99
to
Hi,

Take a look at my IE DOM article from the list of articles below. Here is
the relevant code:

procedure TForm1.MemLoadClick(Sender: TObject);
var
v : variant;
begin
Document := WebBrowser.Document as IHtmlDocument2;
if (assigned(Document)) then begin
v := VarArrayCreate([0, 0], varVariant);
v[0] := '<html><head><title>Hello World</title></head><body>Start me
up</body></html>');
Document.Write(PSafeArray(TVarData(v).VArray));
Document.Close;
end;
end;

--
Ron Loewy - List of Articles -
http://members.home.net/rloewy/RonPubList.html

Brendon Paine

unread,
Dec 14, 1999, 3:00:00 AM12/14/99
to
Hey Rob,

Thanks, you gave me the clue that I needed.

Below is one way to load a HTML string into a new IHTMLDocument2.

There is a website http://www.euromind.com/iedelphi/uiless.htm which has an
example of how to create a UILess parser for an HTML document. This example
shows you
how to load a new HTML document from a file. You can restrict the parser so
that it won't run scripts or activeX controls etc. It also shows you how to
set a message loop in order for you to know when the HTML document has
finished loading.

The code example (which can be downloaded) shows you how to load an HTML
document can be loaded from a moniker - or a file.

The code below shows you how you can load a HTML string into a new
IHTMLDocument2.


var
FDoc: IHTMLDocument2;


function TUILess.LoadHTMLFromString(HTMLString: widestring): HResult;
var
PS: IPersistStreamInit;
Stream: TStringStream;
StreamA: TStreamAdapter;
begin
FDoc.designMode := 'On';
PS := FDoc as IPersistStreamInit;
try
Stream := TStringStream.Create(HTMLString);
try
Result := PS.InitNew;
if SUCCEEDED(Result) then begin
StreamA := TStreamAdapter.Create(Stream);
Result := PS.Load(StreamA);
end;
finally
Stream.Free;
if StreamA <> nil then IUnknown(StreamA)._Release;
end;
finally
if PS <> nil then PS._Release;
end;
end;


Robert de Groote <e.deg...@student.utwente.nl> wrote in message
news:83319e$68...@forums.borland.com...


> Hello Brendom,
>
> I'm struggling with the same problem, and haven't worked anything out yet
> too... I found a tutorial which explains how to load a HTML content from a
> stream. I don't know how to do it, although it is described.. take a look
> for yourself
>
http://msdn.microsoft.com/workshop/browser/webbrowser/tutorials/webocstream.
> asp#stream
> if you succeed in loading the HTML contents, please inform me in this
> newsgroup.... I'm very eager to know how to solve this problem.....
>
> good luck,
> Robert de Groote.
>
>
>

Brendon Paine

unread,
Dec 14, 1999, 3:00:00 AM12/14/99
to
Hey Rob,

Thanks, this is the clue that I needed.

This is one way to load a HTML string into a new IHTMLDocument.

There is a website http://www.euromind.com/iedelphi/uiless.htm which has an

example of how to create a UILess parser for HTML. This example shows you


how to load a new HTML document from a file. You can restrict the parser so
that it won't run scripts or activeX controls etc. It also shows you how to
set a message loop in order for you to know when the HTML document has
finished loading.

The code example (which can be downloaded) shows you how to load an HTML

document from a moniker - and a file.

Brendon Paine

unread,
Dec 14, 1999, 3:00:00 AM12/14/99
to
Hey Rob,

Thanks, you gave me the clue that I needed.

Below is one way to load a HTML string into a new IHTMLDocument2.

There is a website http://www.euromind.com/iedelphi/uiless.htm which has an

example of how to create a UILess parser for an HTML document. This example


shows you
how to load a new HTML document from a file. You can restrict the parser so
that it won't run scripts or activeX controls etc. It also shows you how to
set a message loop in order for you to know when the HTML document has
finished loading.

The code example (which can be downloaded) shows you how to load an HTML

document from a moniker - or a file.


var
FDoc: IHTMLDocument2;

Brendon

0 new messages