Menu

#8 Exception with emtpy <width/> and <height/> elements

open
nobody
Bug (6)
5
2009-09-14
2009-09-14
bhe bhe
No

This code crashes converting Null to integer with emtpy <width/> and <height/> elements:

procedure TSimpleParserRSS.Parse;
...
if ChildNodes.Nodes[Counter].ChildNodes.FindNode(reWidth) <> nil then
FSimpleRSS.Channel.Optional.Image.Optional.Width :=
ChildNodes.Nodes[Counter].ChildNodes.FindNode(reWidth).NodeValue;
if ChildNodes.Nodes[Counter].ChildNodes.FindNode(reHeight) <> nil then
FSimpleRSS.Channel.Optional.Image.Optional.Height :=
ChildNodes.Nodes[Counter].ChildNodes.FindNode(reHeight).NodeValue;

My solution:

procedure TSimpleParserRSS.Parse;
var tVar: OleVariant;
...
if ChildNodes.Nodes[Counter].ChildNodes.FindNode(reWidth) <> nil then
begin
tVar := ChildNodes.Nodes[Counter].ChildNodes.FindNode(reWidth).NodeValue;
if not VarIsNull(tVar)then
FSimpleRSS.Channel.Optional.Image.Optional.Width := tVar;
end;
if ChildNodes.Nodes[Counter].ChildNodes.FindNode(reHeight) <> nil then
begin
tVar := ChildNodes.Nodes[Counter].ChildNodes.FindNode(reHeight).NodeValue;
if not VarIsNull(tVar)then
FSimpleRSS.Channel.Optional.Image.Optional.Height := tVar;
end;

Discussion


Log in to post a comment.