Variants sample (Delphi)

Purpose

This sample shows how the RemObjects SDK can transfer values of the Delphi variant type and arrays of variants from the client to the server using binary and SOAP messages.

Getting Started

  • Compile and launch the server.
  • Compile and run the client.
  • Click Test Variants and see the variants received from the server .

Examine the Code

See how the service is defined in the service library: Make the server the selected project and use the menu command: Tools -> Remoting SDK -> Edit Service Library. Note: If you don't see this menu option, but the Service Builder instead, you still have the client set as the current project. Pay attention to the Variant type used in the RODL. It maps to the native Delphi Variant type as shown in the service implementation code:

procedure TVariantsService.EchoVariant(const InputVariant: Variant; out OutputVariant: Variant);
begin
  OutputVariant := InputVariant;
end;

procedure TVariantsService.EchoComplexObject(const InComplexObject: TComplexObject; out OutComplexObject: TComplexObject);
begin
  OutComplexObject := InComplexObject;
end;

procedure TVariantsService.EchoVariantArray(const InArray: TVariantArray; out OutArray: TVariantArray);
begin
  OutArray := InArray;
end;

Examine the simple code needed to invoke the methods in VariantsClientMain.pas, for example:

// Complex object
  incomplex := TComplexObject.Create;
  incomplex.IntegerId := 101;
  incomplex.VariantValue := 'My Variant';
  fVariantsService.EchoComplexObject(incomplex, outcomplex);
  Memo.Lines.Add('Received ' + IntToStr(outcomplex.IntegerId) + ', ' + outcomplex.VariantValue);
  Application.ProcessMessages;
  incomplex.Free;
  outcomplex.Free;