Using Delphi Community Edition

The following basic program was created in Delphi Community Edition 10.2.3 to demonstrate streaming a remote file. This is a console mode application but it could easily be turned into a GUI application of greater sophistication such as one that allows a user to specify the remote and local paths.

This basic program has been extracted from “How To Program Effectively in Delphi For AS/A Level Computer Science by Dr Kevin R Bond” which is currently under preparation. An Early Access PDF Edition will be able from the end of February 2019 .


Program Chapter30Prog5;
{$APPTYPE CONSOLE}
Uses
  System.SysUtils, System.Classes, idHTTP, System.Net.HttpClient;
Var
  MemoryStream1 : TMemoryStream;
  Http1 : THTTPClient; // Delphi 10.2 otherwise use TidHTTP with ssl library
  LocalPath : String = 'C:\Users\drbond\Downloads\';
  RemotePath : String = 'https://filestore.aqa.org.uk/sample-papers-and-mark-schemes/2016/june/';
Begin
  Try
    MemoryStream1 := TMemoryStream.Create;
    Try
      Try
        HTTP1 := THTTPClient.Create;//(Nil) required for TidHTTP;
        HTTP1.Get(RemotePath + 'AQA-75161-QP-JUN16.PDF', MemoryStream1);
        MemoryStream1.SaveToFile(LocalPath + 'AQA-75161-QP-JUN16.PDF');
      Except
        On E: Exception Do Writeln(E.ClassName, ': ', E.Message);
      End;
    Finally
      Http1.Free;
    End;
  Finally
    MemoryStream1.Free;
  End;
  Writeln('Finished downloading - Press Return key to exit.');
  Readln;
End.

Delphi Community Edition 10.2.3

Amazing product that comes with the full FireMonkey and FireUI multi-device development experience, plus a fully working IDE, basic database access, including even IBLite for mobile and it is FREE!