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_; Index: VerpakkingsDefinitie/WS/SelectService.pas =================================================================== diff -u -r556 -r560 --- VerpakkingsDefinitie/WS/SelectService.pas (.../SelectService.pas) (revision 556) +++ VerpakkingsDefinitie/WS/SelectService.pas (.../SelectService.pas) (revision 560) @@ -48,15 +48,15 @@ SelectResponse = class(TRemotable) private FSelectResult: pxStatus; - FvarDataSet: anyType; + FvarDataSet: string; FvarDataSet_Specified: boolean; - procedure SetvarDataSet(Index: Integer; const AanyType: anyType); + procedure SetvarDataSet(Index: Integer; const AanyType: string); function varDataSet_Specified(Index: Integer): boolean; public destructor Destroy; override; published property SelectResult: pxStatus read FSelectResult write FSelectResult; - property varDataSet: anyType Index (IS_OPTN) read FvarDataSet write SetvarDataSet stored varDataSet_Specified; + property varDataSet: string Index (IS_OPTN) read FvarDataSet write SetvarDataSet stored varDataSet_Specified; end; @@ -71,20 +71,20 @@ FSessionKey_Specified: boolean; FCriteria: pxSelectCriteria; FCriteria_Specified: boolean; - FvarDataSet: anyType; + FvarDataSet: string; FvarDataSet_Specified: boolean; procedure SetSessionKey(Index: Integer; const Astring: string); function SessionKey_Specified(Index: Integer): boolean; procedure SetCriteria(Index: Integer; const ApxSelectCriteria: pxSelectCriteria); function Criteria_Specified(Index: Integer): boolean; - procedure SetvarDataSet(Index: Integer; const AanyType: anyType); + procedure SetvarDataSet(Index: Integer; const AanyType: string); function varDataSet_Specified(Index: Integer): boolean; public destructor Destroy; override; published property SessionKey: string Index (IS_OPTN) read FSessionKey write SetSessionKey stored SessionKey_Specified; property Criteria: pxSelectCriteria Index (IS_OPTN) read FCriteria write SetCriteria stored Criteria_Specified; - property varDataSet: anyType Index (IS_OPTN) read FvarDataSet write SetvarDataSet stored varDataSet_Specified; + property varDataSet: string Index (IS_OPTN) read FvarDataSet write SetvarDataSet stored varDataSet_Specified; end; @@ -257,7 +257,7 @@ inherited Destroy; end; -procedure SelectResponse.SetvarDataSet(Index: Integer; const AanyType: anyType); +procedure SelectResponse.SetvarDataSet(Index: Integer; const AanyType: string); begin FvarDataSet := AanyType; FvarDataSet_Specified := True; @@ -297,7 +297,7 @@ Result := FCriteria_Specified; end; -procedure Select.SetvarDataSet(Index: Integer; const AanyType: anyType); +procedure Select.SetvarDataSet(Index: Integer; const AanyType: string); begin FvarDataSet := AanyType; FvarDataSet_Specified := True; Index: VerpakkingsDefinitie/ApplicationContext.pas =================================================================== diff -u -r556 -r560 --- VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 556) +++ VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 560) @@ -8,7 +8,8 @@ interface uses - ObserverPattern; + ObserverPattern, + System.Generics.Collections; // SUB CONTEXTS: klassen die overeenkomen met bepaalde sub-context (bv. alles gerelateerd met authenticatie). @@ -31,17 +32,35 @@ property InternalErrorMessage: string read FInternalErrorMessage write FInternalErrorMessage; end; + TProductInformatie = class + private + FProductNr: Integer; + FTekst: string; + FKol1: string; + FKol2: string; + FKol3: string; + FKol4: string; + public + property ProductNr: Integer read FProductNr write FProductNr; + property Tekst: string read FTekst write FTekst; + property Kol1: string read FKol1 write FKol1; + property Kol2: string read FKol2 write FKol2; + property Kol3: string read FKol3 write FKol3; + property Kol4: string read FKol4 write FKol4; + end; + TProductsContext = class(TSubject) private FSessionKey: string; - FDataSet: TObject; + FProducten: TList; FIsOK: Boolean; FErrorMessage: string; FInternalErrorMessage: string; public + constructor Create(); procedure NotifyChanged(); - property DataSet: TObject read FDataSet write FDataSet; + property Producten: TList read FProducten write FProducten; property IsOK: Boolean read FIsOK write FIsOK; property ErrorMessage: string read FErrorMessage write FErrorMessage; @@ -67,6 +86,12 @@ self.Change(); end; +constructor TProductsContext.Create(); +begin + inherited Create(); + FProducten := TList.Create(); +end; + procedure TProductsContext.NotifyChanged(); begin self.Change();