Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Clear All Multipart Parts

See more REST Examples

Demonstrates Rest.ClearAllParts, which removes all multipart subparts from the request under construction.

Background. Clearing the parts is useful when reusing the same Rest object to build a different multipart request.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Rest;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  rest: TRest;
  bTls: Boolean;
  bAutoReconnect: Boolean;

begin
  success := False;

  rest := TRest.Create;
  bTls := True;
  bAutoReconnect := True;
  success := rest.Connect('example.com',443,bTls,bAutoReconnect);
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  //  Build a part.
  rest.PartSelector := '1';
  success := rest.SetMultipartBodyString('value1');
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  //  Remove all multipart subparts from the request under construction, for example before reusing the
  //  same Rest object for a different multipart request.
  rest.ClearAllParts();

  WriteLn('All multipart parts cleared.');


  rest.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.