NG ConnectionPack Guide


Your First Application (Google Drive)


This topic describes creation of a very simple application, which will show Google Drive user's file tree in TMemo control. The topic is written for new NG ConnectionPack users, and the application is simplified as much as possible. For more advanced, real-world apps, please refer to NG ConnectionPack demos.

 

1. General Google Drive access

 

First of all, please make sure that you have Google account, and can access Google Drive via its primary web interface:

 

https://drive.google.com

 

clip0013

 

For testing purposes please make sure, that some files are available in your Google Drive. We uploaded NG ConnectionPack sources, for example.

 

2. Registering your application

 

Please follow the procedure, described in Google Registration topic. Don't forget to enable Google Drive API:

 

clip0015

 

3. Creating VCL forms application

 

The next step will be to create new VCL application in Delphi. Run Delphi IDE, create new VCL application, as usual, and place TLabel, TMemo, TButton and TNGGDrive components, like shown below:

 

clip0014

 

We will use the memo to show downloaded files tree, and the label to show downloading progress. As a result of application registration, performed in the previous step, you received ClientID and Secret string values. Please copy-paste them to the corresponding properties of NGGDrive1 component using Delphi's Object Inspector:

 

clip0016

 

Double click the button on the form to create its OnClick event handler and write the following code in it:

 

procedure TForm3.Button1Click(Sender: TObject);
var
  lst: TNGFileList;
  fl:  TNGFile;
  i:   Integer;
begin
  FFileCount := 0;
 
  Label1.Caption := 'Working...';
  Label1.Refresh;
 
  lst := NGGDrive1.Files_List
                  .Q('trashed=false')
                  .Execute;
 
  for i := 0 to lst.Files.High do
  begin
    fl := lst.Files[i];
    Memo1.Lines.Add(fl.Name);
  end;
 
  Label1.Caption := 'Done.';
end;

 

4. Running the application

 

Thats all! You can run the application. Since the authentication state is not saved/loaded for simplicity, the application will ask to authenticate the user at every run. Use your own Google Account credentials to grant the application rights to your Google Drive data. The application, then will retrieve full file list of your Google Drive files:

 

clip0017

 

Congratulations! You've created your first application, which interacts with web based REST service via Internet, using LMD NG ConnectionPack components.