Advertisement
Guest User

DLL function

a guest
Aug 30th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.84 KB | None | 0 0
  1. function GetItem(out JsonResponse, SoapError: WideString): UInt8; stdcall;
  2. var
  3.   RIO: THTTPRIO;
  4.   WS: WebIntegration_Port;
  5.   WsItems: Items;
  6.   RecordsReceived: Integer;
  7.   RecordCount: Integer;
  8.   I: Integer;
  9.   JItems: TItems;
  10. begin
  11.   try
  12.     // *** THTTPRIO will free itself when created with no owner
  13.     // http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Calling_Invokable_Interfaces
  14.     RIO := THTTPRIO.Create(nil);
  15.   except
  16.     on E: Exception do
  17.     begin
  18.       SoapError := E.Message;
  19.       Exit(SOAP_ERROR);
  20.     end;
  21.   end;
  22.   RIO.HTTPWebNode.UserName := FUserName;
  23.   RIO.HTTPWebNode.Password := FPassword;
  24.   RIO.URL := FURL;
  25.   if FUseProxy then
  26.   begin
  27.     RIO.HTTPWebNode.Proxy := FProxy;
  28.   end;
  29.  
  30.   try
  31.     WS := (RIO as WebIntegration_Port);
  32.  
  33.     // We get Total record count with first call to WebService
  34.     WS.Item(WsItems, EmptyStr, False, EmptyStr, 1, 1, RecordCount);
  35.  
  36.     // Now, we know how many records in there. We can get them all
  37.     WS.Item(WsItems, EmptyStr, False, EmptyStr, 1, RecordCount, RecordsReceived);
  38.  
  39.     // Do not depend on RecordsReceived variable returning from WebService. Count it yourself
  40.     SetLength(JItems, Length(WsItems));
  41.     for I := Low(WsItems) to High(WsItems) do
  42.     begin
  43.       JItems[i].FNo          := WsItems[i].No;
  44.       JItems[i].FDescription := WsItems[i].Description;
  45.       JItems[i].FUoM         := WsItems[i].UoM;
  46.       JItems[i].FPrice       := BcdToDouble(WsItems[i].Price.AsBcd);
  47.       JItems[i].FStock       := BcdToDouble(WsItems[i].Stock.AsBcd);
  48.     end;
  49.     WS := nil;
  50.  
  51.     // mORMot json routines used for building json string reply.
  52.     JsonResponse := WideString(RecordSaveJSON(JItems, TypeInfo(TItems)));
  53.   except
  54.     on E: Exception do
  55.     begin
  56.       SoapError := E.Message;
  57.       Exit(SOAP_ERROR);
  58.     end;
  59.   end;
  60.  
  61.   Result := RESPONSE_OK;
  62. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement