开发者

Delphi TADOQuery loadFromFile error: "The character '<' cannot be used in an attribute value"

I have a Delphi 2009 application that runs a query over a database using a TADOQuery component. When the query has returned data, I call the TADOQuery's saveToFile procedure, specifying "pfXML" as the format parameter, which obviously saves the data to an XML document. This works fine.

To view the data, I have a screen that contains a virtual listview. I use another TADOQuery component on this screen and call the loadFromFile procedure to read the data from the XML document. I can then display the data in the virtual listview using the TADOQuery's "fieldByName" function. Again, this works fine - or at least, it has been working fine for the past few months.

I encountered an error today, whereby I had run a certain query and when I tried to open the report, I got an error: "The character '<' cannot be used in an attribute value". I believe that this is an XML error, but I can't track down the cause.

I used Delphi's debugger to see where the error was cropping up, and the line that raises the exception is one which retrieves the TADOQuery's record count (i.e. adoquery.recordCount). If I hover my mouse over the .recordCount call via a breakpoint in my code, the tooltip says "Delphi exception at $1286F945".

Like I said, this has been working fine for months and now this error has suddenly cropped up. Obviously, there's something in the data that is being returned that is causing the problem, but I have no idea what. I've scanned the XML document and there are no "<" characters in there tha开发者_Go百科t aren't part of a tag.

Finally, just to pre-empt anyone that wants to respond with a "Why are you doing it like this? You should do it like that..." comment, one of the application's requirements is that the application must allow the user to run a query and save it to view offline at a later date, hence the saveToFile/loadToFile calls.


After spending all morning debugging the application, I found that the problem is caused by junk data causing the close tag (>) to be left off the end of one of the strings in the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜