Board index » cppbuilder » A question about OpenDialog

A question about OpenDialog


2004-04-24 11:39:50 AM
cppbuilder12
Hi,I get a problem on using the OpenDialog Component.I want to use the
OpenDialog component to get the full path of the selected file(to show in an
TEdit component),and then put the path into an XML file.But when I try to
open an existed XML file I failed.The problem occurs when I run to this
line:
MyXML=LoadXMLDocument(WideString(".\\test.xml"));//Open an XML file
It just throw an exception.It seems that I've opened two files at the same
time.
If I do not use OpenDialog and type the full path by myself it works very
well.Does the OpenDialog component really open a file?If it does how can I
close it?Can anyone tell me how to solve this problem?
the code is like this:
if (OpenDialog1->Execute())
{
Edit4->Text = OpenDialog1->FileName;
}
 
 

Re:A question about OpenDialog

"zack" < XXXX@XXXXX.COM >wrote in message
Quote
I want to use the OpenDialog component to get the full
path of the selected file
Use the dialog's FileName property for that.
Quote
But when I try to open an existed XML file I failed.
Please be more specific. What is the actual problem?
Quote
It just throw an exception.
What is the actual exception that is thrown?
Quote
It seems that I've opened two files at the same time.
Are you using the dialog to choose the XML file to open? If so, then you
should be using the dialog's FileName when calling LoadXMLDocument(). Also,
LoadXMLDocument() only works if the file actually exists. If you are
allowing a non-existant file to be choosen, then you need to use
NewXMLDocument() instead.
Quote
If I do not use OpenDialog and type the full path by
myself it works very well.
Please show a more complete code snippet.
Quote
Does the OpenDialog component really open a file?
No. It only returns the selected filename, nothing else.
Quote
the code is like this:
if (OpenDialog1->Execute())
{
Edit4->Text = OpenDialog1->FileName;
}
There is nothing wrong with that code. But what does that code have to do
with your XML handling?
Gambit
 

Re:A question about OpenDialog

My code to deal with the XML file:
_di_IXMLDocument MyXML;
try
{
MyXML=LoadXMLDocument(WideString(".\\test.xml"));
}
I first select a file from the OpenDialog component ,and then it returns a
full path for me.
I show the path in an TEdit component.Now I want to write the path string
into an XML file.
But when I load the XML file it raise an exception class EDOMParseError and
declare that it
is a system error.
I'm sure the XML is existed because if I type the path myself it works well.
I doubt there is sth. wrong with XML handling now.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >写入消息新闻
:4089ff13$ XXXX@XXXXX.COM ...
Quote

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

>I want to use the OpenDialog component to get the full
>path of the selected file

Use the dialog's FileName property for that.

>But when I try to open an existed XML file I failed.

Please be more specific. What is the actual problem?

>It just throw an exception.

What is the actual exception that is thrown?

>It seems that I've opened two files at the same time.

Are you using the dialog to choose the XML file to open? If so, then you
should be using the dialog's FileName when calling LoadXMLDocument().
Also,
LoadXMLDocument() only works if the file actually exists. If you are
allowing a non-existant file to be choosen, then you need to use
NewXMLDocument() instead.

>If I do not use OpenDialog and type the full path by
>myself it works very well.

Please show a more complete code snippet.

>Does the OpenDialog component really open a file?

No. It only returns the selected filename, nothing else.

>the code is like this:
>if (OpenDialog1->Execute())
>{
>Edit4->Text = OpenDialog1->FileName;
>}

There is nothing wrong with that code. But what does that code have to do
with your XML handling?


Gambit


 

{smallsort}

Re:A question about OpenDialog

My code to deal with the XML file:
_di_IXMLDocument MyXML;
try
{
MyXML=LoadXMLDocument(WideString(".\\test.xml"));
}
I first select a file from the OpenDialog component ,and then it returns a
full path for me.
I show the path in an TEdit component.Now I want to write the path string
into an XML file.
But when I load the XML file it raise an exception class EDOMParseError and
declare that it
is a system error.
I'm sure the XML is existed because if I type the path myself it works well.
I doubt there is sth. wrong with XML handling now.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >写入消息新闻
:4089ff13$ XXXX@XXXXX.COM ...
Quote

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

>I want to use the OpenDialog component to get the full
>path of the selected file

Use the dialog's FileName property for that.

>But when I try to open an existed XML file I failed.

Please be more specific. What is the actual problem?

>It just throw an exception.

What is the actual exception that is thrown?

>It seems that I've opened two files at the same time.

Are you using the dialog to choose the XML file to open? If so, then you
should be using the dialog's FileName when calling LoadXMLDocument().
Also,
LoadXMLDocument() only works if the file actually exists. If you are
allowing a non-existant file to be choosen, then you need to use
NewXMLDocument() instead.

>If I do not use OpenDialog and type the full path by
>myself it works very well.

Please show a more complete code snippet.

>Does the OpenDialog component really open a file?

No. It only returns the selected filename, nothing else.

>the code is like this:
>if (OpenDialog1->Execute())
>{
>Edit4->Text = OpenDialog1->FileName;
>}

There is nothing wrong with that code. But what does that code have to do
with your XML handling?


Gambit


 

Re:A question about OpenDialog

"zack" < XXXX@XXXXX.COM >wrote in message
Quote
MyXML=LoadXMLDocument(WideString(".\\test.xml"));
You should always use absolute paths, don't use relative paths (especially
not "." as the folder it points to can change during the appication's
lifetime):
MyXML = LoadXMLDocument(ExtractFilePath(Application->ExeName) +
"test.xml");
Quote
But when I load the XML file it raise an exception class
EDOMParseError and declare that it is a system error.
Does the XML file actually exist prior to calling LoadXMLDocument()? If so,
does it have any actual XML content inside of it? What is the EXACT error
message of the exception?
Gambit