2013-04-16 69 views
0

我試着去讀取XML文件,但我不斷收到一個「溢出而轉換型(OLESTR)的變體進入類型整型」錯誤的整數或WideString的類型,香港專業教育學院嘗試從VarToStr,IntToStr,VarToWideStr和OleStrToString中更改類型。溢出而轉換型(OLESTR)的變體進入類型整數德爾福

XML文件

<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; 
+2

請做一些調試。找到失敗的代碼行。讓我們知道該行代碼所使用的變量的值。 –

+0

錯誤跳到下一個變量,如果我註釋掉第一誤差,並且僅整數由它實現 ' 功能TXMLProductType.Get_Productid:整數; 開始 ' 結果:= AttributeNodes [' PRODUCT-ID']的nodeValue。 end;'code' – Gis

+0

@Gis「AttributeNodes ['product-id']。NodeValue」的值是什麼? – ComputerSaysNo

回答

2

您的產品ID attribte和EAN Codes的樣本不是整數,但你要這樣對待他們。他們是字符串值。 (它們太大而不適合整數)。它們不是你要做數學或算術運算的數字,所以不要嘗試和對待它們。改爲將定義更改爲WideString,您應該沒問題。

// 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;