Paste
Pasted as Delphi by Dmitry2994 ( 13 years ago )
function LicenseProduct;
var t:hasp_status_t;
i,j:cardinal;
function GetFeaturesInfo(var Product:TProduct):List; //где List - массив обьектов Product
var scope_f:PChar;
i:cardinal;
t2:hasp_status_t; //для вызова их функции
begin
scope_f:=PChar('<haspscope> <product id="' + IntToStr(Product.ID) + '"/> </haspscope>');
t2:=hasp_get_info(scope_f,format_f,PChar(vendor_code),info2); //тут тоже все нормально, это их функция
XML2:=TXMLDocument.Create(nil); //создали, обьявлены они в другом месте
XML2.LoadFromXML(WideString(info2)); //загрузили строку
XMLInt2:=XML2;
for i:=0 to XMLInt2.ChildNodes.Nodes[1].ChildNodes.Count-1 do
begin
Product.SetCountOfFeatures(i+1);
Product.Features[i].ID:=StrToInt(XMLInt2.ChildNodes.Nodes[1].ChildNodes.Nodes[i].AttributeNodes.Get(0).Text); //бла-бла, тут все работает
Product.Features[i].name:= XMLInt2.ChildNodes.Nodes[1].ChildNodes.Nodes[i].AttributeNodes.Get(1).Text;
Product.Features[i].ProductID:=Product.ID;
end;
XML2.Free; //освободили
hasp_free(info2); // и это тоже
end;
begin
t:=hasp_get_info(scope,format_p,PChar(vendor_code),info); //все по такому же принципу
XML:=TXMLDocument.Create(nil);
XML.LoadFromXML(WideString(info));
XMLInt:=XML; //вот здесь бум на 2-ом такте главного цикла (цикл пущен правильно, он в другом юните и нам неинтересен)
j:=1;
for i:=0 to XMLInt.ChildNodes.Nodes[1].ChildNodes.Count-1 do
begin
SetLength(result,j);
result[j-1]:=TProduct.Create;
result[j-1].ID:=StrToInt(XMLInt.ChildNodes.Nodes[1].ChildNodes.Nodes[i].ChildNodes.Nodes[0].Text);
result[j-1].Name:=XMLInt.ChildNodes.Nodes[1].ChildNodes.Nodes[i].ChildNodes.Nodes[1].Text;
result[j-1].Features:=GetFeaturesInfo(result[j-1]); //вызов вложенной функции в цикле
inc(j);
end;
hasp_free(info); //освободили
//XML.Free;
end;
Revise this Paste