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

TXMLDocument - Access violation

82 views
Skip to first unread message

nikhil

unread,
May 3, 2005, 1:49:34 AM5/3/05
to

"Raised exception class EAccessViolation with message 'Access violation at address 00000000. Read of address 00000000'".
Raised while accessing the root node with TXMLDocument created at runtime.The same code works fine if the TXMLDocument component is placed on form at design time.
Environment: BCB-6 On O.S. Windows XP Professional.
Please help at the earliest.

Remy Lebeau (TeamB)

unread,
May 3, 2005, 2:55:19 AM5/3/05
to

"nikhil" <nikhil...@yahoo.com> wrote in message
news:427710ee$1...@newsgroups.borland.com...

> "Raised exception class EAccessViolation with message
> 'Access violation at address 00000000. Read of address
> 00000000'".

You are trying to access an object via a NULL pointer. Please show your
actual code.

> Raised while accessing the root node with TXMLDocument created at runtime.

Either 1) you did not instantiate the TXMLDocument properly to begin with
(which you should not be doing anyway - use the IXMLDocument interface
instead); 2) you did not load a document into the TXMLDocument at all; or 3)
you did not check for a failed load before trying to access the data.
Either way, you need to provide more detail about what your code is actually
doing. Your description is much too vague to diagnose your problem with.


Gambit


nikhil

unread,
May 3, 2005, 6:14:22 AM5/3/05
to

Hi Gambit.

Thanks, here is the EXTRACT of my code that's generating error

void CheckReply()
{
tagVARIANT Opt,Ui;
int AttCnt;long Status;
WideString Cmd(String("SaveAs"));
WideString Domain,CharSet;
IHTMLDocument2 *HTMLDocument = NULL;
TXMLDocument *XmlDoc;
bool Success;

Status=MyBrowser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&HTMLDocument);
if(Status!=0){ShowMessage("Could Not Read Response");return;}

HTMLDocument->get_domain(&Domain);
if(Domain==SetDom) //if the page loaded is from the domain predefined as SetDom
{
StatusPanel->Lines->Add(Domain); //Just for visual confirmation
StatusPanel->Lines->Add("Remote Service");

Opt.vt=VT_BSTR; Opt.bstrVal=WideString(SName); //SName is the generated file name with .txt extension
VARIANT_BOOL UI=VARIANT_FALSE;
VARIANT_BOOL __RPC_FAR RetVal;

//Saving the file
Status=HTMLDocument->execCommand(Cmd,UI,Opt,&RetVal); //I am having problem with this call also since it is not avoiding the save as dialogue box which I wish to

//creating TXMLDocument object dynamically out here.

XmlDoc=new TXMLDocument(TName);
//TName is the string variable holding the path and file name of xml file to be loaded.
XmlDoc->Options<<doNodeAutoCreate;
XmlDoc->Options<<doAttrNull;
XmlDoc->Options<<doAutoPrefix;
XmlDoc->Options<<doNamespaceDecl;
XmlDoc->NodeIndentStr=" ";

//XmlDoc->DOMVendor=
//XmlDoc->LoadFromFile(TName);

XmlDoc->Active=true;

ShowMessage(XmlDoc->XML->GetText());
//this message box successfully shows the contents of xml file loaded this suggest that the XmlDoc is not null
//however this next statement to retrieve the tagname generates the access violation.


TagName=XmlDoc->DocumentElement->GetNodeName();

if(TagName==WideString("Reply")) {
StatusPanel->Lines->Add(TagName);
StatusPanel->Lines->Add("Reading Reply"); }
else {
StatusPanel->Lines->Add("Error");
StatusPanel->Lines->Add("Invalid Reply");
return; }
}


Please check out whether it gives any insight to my problem and revert back.
Thank you again.

Remy Lebeau (TeamB)

unread,
May 3, 2005, 2:18:07 PM5/3/05
to

"nikhil" <nikhil...@yahoo.com> wrote in message
news:42774efe$1...@newsgroups.borland.com...

>
Status=MyBrowser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&HTML
Document);

You are not checking to make sure that the Document is actually valid before
trying to access it.

> Opt.vt=VT_BSTR; Opt.bstrVal=WideString(SName); //SName is
the generated file name with .txt extension

You are assigning a temporary WideString to the VARIANT. As soon as that
statement exists, the WideString is freed immediately, leaving the VARIANT
holding on to an invalid BSTR pointer. You need to keep the WideString in
scope until you are finished using the VARIANT. Otherwise, don't use a
WideString at all. Either call SysAllocString() directly and then call
SysFreeString() when you are done with the VARIANT. Or better yet, don't
use VARIANT at all, but use the VCL's Variant or TVariant class instead.

> VARIANT_BOOL __RPC_FAR RetVal;

Get rid of the __RPC_FAR, it has no effect in Win32 programming.

> XmlDoc=new TXMLDocument(TName);

Do not do that. TXMLDocument does not work properly when instantiated
dynamically. Use the IXMLDocument interface directly, ie:

_di_IXMLDocument XmlDoc;

XmlDoc = LoadXMLDocument(TName);
//...

> XmlDoc->Options<<doNodeAutoCreate;
> XmlDoc->Options<<doAttrNull;
> XmlDoc->Options<<doAutoPrefix;
> XmlDoc->Options<<doNamespaceDecl;

You cannot assign Set-based properties like that. You need to use the '='
operator as well, ie:

XmlDoc->Options = XmlDoc->Options << doNodeAutoCreate << doAttrNull <<
doAutoPrefix << doNamespaceDecl;

> TagName=XmlDoc->DocumentElement->GetNodeName();

You are not checking to make sure that the DocumentElement is actually valid
before trying to access it.


Gambit


nikhil

unread,
May 4, 2005, 8:28:57 AM5/4/05
to

Hi Gambit,

Thank you very much for your prompt suggestion. Use of IXMLDocument in place of TXMLDocument did work well and took me out of fix. However I am still struggling with SaveAs dialogue
Box...would post another message with elaboration in case its not solved. Meanwhile can u suggeste any method by which I can
programatically stimulate the click on save Button of Save As
Dialogue Box to close it without user intervention?

Thanking again..

Regards,

Nikhil.


Rod Runnheim

unread,
May 4, 2005, 12:00:13 PM5/4/05
to
Hi guys, this is related to TXMLDocument.

I have C++ Builder 6 Professional, but after installing I do not have
access to the TXMLDocument component. There is no wizard (as is stated in
the manual) and it is not on the "Internet" component panel. Do I have to
download this module and install it?

Thanks for any help.

Rod Runnheim


Remy Lebeau (TeamB)

unread,
May 4, 2005, 2:14:12 PM5/4/05
to

"Rod Runnheim" <ro...@lmcg.wisc.edu> wrote in message
news:4278f18c$1...@newsgroups.borland.com...

> I have C++ Builder 6 Professional, but after installing I do
> not have access to the TXMLDocument component.

TXMLDocument is not pre-installed in the Pro edition, only the Enterprise
edition. For Pro, you have to install it manually:

TXMLDocument for C++Builder 6 Professional
http://cc.borland.com/ccweb.exe/listing?id=18938

Gambit


Rod Runnheim

unread,
May 4, 2005, 6:23:30 PM5/4/05
to

"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:427911a6$1...@newsgroups.borland.com...

Thank you -- except I get
HTTP 500 - Internal server error
Internet Explorer
:-/


Rod


Rod Runnheim

unread,
May 5, 2005, 10:59:15 AM5/5/05
to
> >
> > TXMLDocument is not pre-installed in the Pro edition, only the
Enterprise
> > edition. For Pro, you have to install it manually:
> >
> > TXMLDocument for C++Builder 6 Professional
> > http://cc.borland.com/ccweb.exe/listing?id=18938
>
> Thank you -- except I get
> HTTP 500 - Internal server error
> Internet Explorer
> :-/
>

Okay, the beta search engine worked -- thanks!

Rod


Remy Lebeau (TeamB)

unread,
May 5, 2005, 1:00:21 PM5/5/05
to

"Rod Runnheim" <ro...@lmcg.wisc.edu> wrote in message
news:42794b60$1...@newsgroups.borland.com...

> Thank you -- except I get
> HTTP 500 - Internal server error
> Internet Explorer

Works fine when I use that link.


Gambit


0 new messages