0

Im trying to read a Xml file but i keep getting a "overflow while converting variant of type (OleStr) into Type Integer" error on Integer or WideString types, ive tried changing the types from VarToStr, IntToStr,VarToWideStr and OleStrToString.

A sample of the xml file

<product product-id="01126400000" product-group-id="10010877">
<name><![CDATA[Love-Positions]]></name>
<selling-price>6.95</selling-price>
<dicount-prohibited>0</dicount-prohibited>
<list-price>4.00</list-price>
<ean-code>4024144112647</ean-code>
<availability>1</availability>
<valid-from-date>19970623</valid-from-date>

procedure TForm1.Button1Click(Sender: TObject);
Var
MyXmlMax,MyXmlMin : integer;
Item: String;

begin

MyXmlMax := xmlDatafeed.Productlist.Count;
//item :=  (xmlDatafeedsub.Attributes['product-id']+','+ xmlDatafeedsub.Attributes['product-group-id'] );


for MyxmlMin := 1 to MyXmlMax-1 do begin
xmlDatafeedsub:=xmlDatafeed.Productlist[MyxmlMin];
memo1.lines.add('------');
memo1.lines.add(VarToStr(xmlDatafeedsub.Productid));  //Integer
memo1.lines.add(VarToStr(xmlDatafeedsub.Productgroupid)); //Integer
Memo1.Lines.Add(xmlDatafeedsub.Name);//WideString
memo1.lines.add((xmlDatafeedsub.Sellingprice)); //Integer
memo1.lines.add(VarToStr(XmlDataFeedSub.Dicountprohibited));//Integer
memo1.lines.add((xmlDatafeedsub.Listprice)); //Widestring
memo1.lines.Add(IntToStr(xmlDatafeedsub.Eancode));//Integer
memo1.lines.add(VarToStr(xmlDatafeedsub.Availability));//Integer
memo1.lines.add(VarToStr(xmlDatafeedsub.Validfromdate));//Integer
Inc(MyXmlMax,1);
memo1.lines.add('------');
end;   //end if
end;


//productdata_v2_01_01.xdb
`
function TXMLProductType.Get_Productid: Integer;
begin
  Result := AttributeNodes['product-id'].NodeValue;
end;

procedure TXMLProductType.Set_Productid(Value: Integer);
begin
  SetAttribute('product-id', Value);
end;

function TXMLProductType.Get_Productgroupid: Integer;
begin
  Result := AttributeNodes['product-group-id'].NodeValue;
end;

procedure TXMLProductType.Set_Productgroupid(Value: Integer);
begin
  SetAttribute('product-group-id', Value);
end;

function TXMLProductType.Get_Name: WideString;
begin
  Result := ChildNodes['name'].Text;
end;

procedure TXMLProductType.Set_Name(Value: WideString);
begin
  ChildNodes['name'].NodeValue := Value;
end;

function TXMLProductType.Get_Sellingprice: WideString;
begin
  Result := ChildNodes['selling-price'].Text;
end;

procedure TXMLProductType.Set_Sellingprice(Value: WideString);
begin
  ChildNodes['selling-price'].NodeValue := Value;
end;

function TXMLProductType.Get_Dicountprohibited: Integer;
begin
  Result := ChildNodes['dicount-prohibited'].NodeValue;
end;

procedure TXMLProductType.Set_Dicountprohibited(Value: Integer);
begin
  ChildNodes['dicount-prohibited'].NodeValue := Value;
end;

function TXMLProductType.Get_Listprice: WideString;
begin
  Result := ChildNodes['list-price'].Text;
end;

procedure TXMLProductType.Set_Listprice(Value: WideString);
begin
  ChildNodes['list-price'].NodeValue := Value;
end;

function TXMLProductType.Get_Eancode: Integer;
begin
  Result := ChildNodes['ean-code'].NodeValue;
end;

procedure TXMLProductType.Set_Eancode(Value: Integer);
begin
  ChildNodes['ean-code'].NodeValue := Value;
end;

function TXMLProductType.Get_Availability: Integer;
begin
  Result := ChildNodes['availability'].NodeValue;
end;

procedure TXMLProductType.Set_Availability(Value: Integer);
begin
  ChildNodes['availability'].NodeValue := Value;
end;

function TXMLProductType.Get_Validfromdate: Integer;
begin
  Result := ChildNodes['valid-from-date'].NodeValue;
end;

procedure TXMLProductType.Set_Validfromdate(Value: Integer);
begin
  ChildNodes['valid-from-date'].NodeValue := Value;
end;
Gis
  • 31
  • 2
  • 5
  • 2
    Please do some debugging. Find the line of code which fails. Let us know what the values of the variables used by that line of code. – David Heffernan Apr 16 '13 at 07:30
  • the error skips to the next variable if i comment out the first error, and only the integers are effected by it ' function TXMLProductType.Get_Productid: Integer; begin ' Result := AttributeNodes['product-id'].NodeValue; end;`code` – Gis Apr 16 '13 at 07:36
  • @Gis what is the value of "AttributeNodes['product-id'].NodeValue"? –  Apr 16 '13 at 07:43
  • "AttributeNodes['product-id'].NodeValue" = 01126400000 – Gis Apr 16 '13 at 07:53
  • I've still no idea which line of code has the error, or indeed what type any of the variables have. Please supply that information. – David Heffernan Apr 16 '13 at 07:58
  • Right. Are you saying the error occurs in the function you mention in the comment, not in the procedure in your question? – Mr Lister Apr 16 '13 at 08:09
  • 3
    Hi the actual error occurs when the xml lib tries to cast Attributenode[xx].nodevalue to an integer, the error does not occur in the code you provided here. Please provide the xml unit and the acutal xml file you are trying to read. – whosrdaddy Apr 16 '13 at 08:12
  • @Gis: I see you edited your question but we need some actual data on which it fails. Try to minimize your XML file so you can reproduce the error. Chances are great that you have "integer" values that do not fit into a 32 bit integer. – whosrdaddy Apr 16 '13 at 08:52
  • 1
    @Gis The solution to your problem can be found here: http://sscce.org/ – David Heffernan Apr 16 '13 at 08:55

1 Answers1

2

Your product-id attribte andEAN Codes are not integers, but you're trying to treat them as such. They're string values. (They're too large to fit in an integer.) They're not numbers that you would do math or arithmetic operations on, so don't try and treat them as such. Change the definition to a WideString instead, and you should be fine.

// You'll need to change these in the `interface` as well. Here are the EANCode
// conversions for you.
function TXMLProductType.Get_Eancode: WideString;
begin
  Result := ChildNodes['ean-code'].NodeValue;
end;

procedure TXMLProductType.Set_Eancode(Value: WideString);
begin
  ChildNodes['ean-code'].NodeValue := Value;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444