Index: VerpakkingsDefinitie/WS/ProductsAgent.pas =================================================================== diff -u -r557 -r560 --- VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 557) +++ VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 560) @@ -16,7 +16,7 @@ TProductsAgent = class private FProdSelectServerSoap: SelectService.ProdSelectServerSoap; - procedure RegistreerZoekresultaten(ProductsContext: TProductsContext; DataSet: anyType); + procedure RegistreerZoekresultaten(ProductsContext: TProductsContext; DataSet: string); procedure RegistreerMislukteOpzoeking(ProductsContext: TProductsContext; pxStatusObj: pxStatus); public Constructor Create(); @@ -26,6 +26,9 @@ implementation +uses + StrUtils, System.Classes, Xml.XMLIntf, Xml.XMLDoc; + constructor TProductsAgent.Create(); begin FProdSelectServerSoap := SelectService.GetProdSelectServerSoap(false, PROD_SERVER_URL, nil); @@ -39,7 +42,6 @@ SelectResponseObj: SelectService.SelectResponse; begin ZoekData := nil; - SelectResponseObj := nil; try // Request ZoekData := SelectService.Select.Create(); @@ -67,26 +69,77 @@ end; finally ZoekData.Free(); - SelectResponseObj.Free(); end; end; -procedure TProductsAgent.RegistreerZoekresultaten(ProductsContext: TProductsContext; DataSet: anyType); +procedure TProductsAgent.RegistreerZoekresultaten(ProductsContext: TProductsContext; DataSet: string); +var + TempStr: string; + Lijn: string; + Lijnen: tstringlist; + LijnenProduct: tstringlist; + BeginOpslaan: Boolean; + XMLDoc: IXMLDocument; + NieuwProduct: TProductInformatie; begin // Andere velden juist zetten ProductsContext.IsOK := True; ProductsContext.ErrorMessage := ''; ProductsContext.InternalErrorMessage := ''; - ProductsContext.DataSet := DataSet; + // Producten inladen + Lijnen := tstringlist.Create; + LijnenProduct := tstringlist.Create; + + // Elke lijn overlopen (skip lege lijnen), maar pas beginnen opslaan vanaf dat we voorbij het schema zitten + // Dus alle 'Select' elementen + BeginOpslaan := false; + for Lijn in SplitString(DataSet, sLineBreak) do + begin + if Lijn = '' then + continue; + if BeginOpslaan then + Lijnen.Add(Lijn); + if (BeginOpslaan = false) and (ContainsStr(Lijn, '')) then + begin + // De tekst is nu '') then + begin + TempStr := LijnenProduct.Text; + XMLDoc := LoadXMLData(TempStr); // XML document van maken + // Elementen uit XML laden, toewijzen en instantie toevoegen aan lijst. + NieuwProduct := TProductInformatie.Create(); + NieuwProduct.ProductNr := XMLDoc.DocumentElement.ChildValues['ProductNr']; + NieuwProduct.Tekst := XMLDoc.DocumentElement.ChildValues['Tekst']; + NieuwProduct.Kol1 := XMLDoc.DocumentElement.ChildValues['Kol1']; + NieuwProduct.Kol2 := XMLDoc.DocumentElement.ChildValues['Kol2']; + NieuwProduct.Kol3 := XMLDoc.DocumentElement.ChildValues['Kol3']; + NieuwProduct.Kol4 := XMLDoc.DocumentElement.ChildValues['Kol4']; + ProductsContext.Producten.Add(NieuwProduct); + end; + end; + + Lijnen.Free(); + LijnenProduct.Free(); + ProductsContext.NotifyChanged(); end; procedure TProductsAgent.RegistreerMislukteOpzoeking(ProductsContext: TProductsContext; pxStatusObj: pxStatus); begin // Ander velden leegmaken - ProductsContext.DataSet := nil; + ProductsContext.Producten.Clear(); ProductsContext.IsOK := pxStatusObj.IsOK; ProductsContext.ErrorMessage := pxStatusObj.Message_;