[Lazarus] How to use ExceptProc and application.CaptureExceptions
Alexander Grau
alex at grauonline.de
Mon Feb 15 18:01:39 CET 2010
dear all,
I have some problems reading xml files.
If I read xml files using ReadXMLFile it works only if I use:
1. procedure ReadXMLFile(out ADoc: TXMLDocument; const AFilename:
String); overload;
while if I use
2. procedure ReadXMLFile(out ADoc: TXMLDocument; var f: Text); overload;
the program crashes.
I attached two files (acetyl.cml and acetyl2.cml). The second one is
always read properly, the first one is read properly only if I use
procedure 1.
In order to reproduce the error just create a new project, put a button
and two tedit on the form.
In the button1 click put this code:
procedure TForm1.Button1Click(Sender: TObject);
var
F: TextFile;
FileName: String;
XMLMolDoc: TXMLDocument;
XMLMols: TDOMNodeList;
begin
FileName:= Edit1.Text;
//AssignFile(F, FileName);
//Reset(F);
//ReadXMLFile(XMLMolDoc, F);
ReadXMLFile(XMLMolDoc, FileName);
XMLMols:= XMLMolDoc.GetElementsByTagName('molecule');
edit2.text:= IntToStr(XMLMols.Count);
//ClosefILE(F);
end;
With this code it works.
While if I put this:
procedure TForm1.Button1Click(Sender: TObject);
var
F: TextFile;
FileName: String;
XMLMolDoc: TXMLDocument;
XMLMols: TDOMNodeList;
begin
FileName:= Edit1.Text;
AssignFile(F, FileName);
Reset(F);
ReadXMLFile(XMLMolDoc, F);
XMLMols:= XMLMolDoc.GetElementsByTagName('molecule');
edit2.text:= IntToStr(XMLMols.Count);
ClosefILE(F);
end;
It crashes raising: exception class 'EXMLreaderror' with message:
In 'file:///e:/temp/acetyl.cml' (line 1 pos 21): expected "?>"
Why?
Andrea
-------------- next part --------------
A non-text attachment was scrubbed...
Name: acetyl2.cml
Type: text/xml
Size: 1498 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100215/c355e9e1/attachment-0008.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: acetyl.cml
Type: text/xml
Size: 1937 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100215/c355e9e1/attachment-0009.xml>
More information about the Lazarus
mailing list