rpccli.pp 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. program RPCCli;
  2. uses SysUtils, Classes, fpAsync, xmlrpc;
  3. type
  4. TClientApplication = class
  5. procedure WriteStringCompleted(AParser: TXMLRPCParser);
  6. procedure AddCompleted(AParser: TXMLRPCParser);
  7. public
  8. procedure Run;
  9. end;
  10. procedure TClientApplication.Run;
  11. var
  12. Client: TXMLRPCClient;
  13. begin
  14. Client := TXMLRPCClient.Create(nil);
  15. try
  16. Client.Call(@WriteStringCompleted, 'WriteString', ['A test string']);
  17. Client.Call(@AddCompleted, 'Add', [123, 456]);
  18. finally
  19. Client.Free;
  20. end;
  21. end;
  22. procedure TClientApplication.WriteStringCompleted(AParser: TXMLRPCParser);
  23. begin
  24. WriteLn('"WriteString" call completed');
  25. end;
  26. procedure TClientApplication.AddCompleted(AParser: TXMLRPCParser);
  27. begin
  28. WriteLn('"Add" call completed. Result: ', AParser.GetNextInt);
  29. end;
  30. var
  31. App: TClientApplication;
  32. begin
  33. App := TClientApplication.Create;
  34. try
  35. try
  36. App.Run;
  37. except
  38. on e: Exception do
  39. WriteLn('Error: ', e.Message);
  40. end;
  41. finally
  42. App.Free;
  43. end;
  44. end.