Print Page | Close Window

Populate Treeview with a specific folder content ?

Printed From: TMS Software
Category: FMX Components
Forum Name: FMX Cloud Pack
Forum Discription:
URL: http://www.tmssoftware.com/site/forum/forum_posts.asp?TID=13163
Printed Date: 16 Oct 2019 at 4:18am


Topic: Populate Treeview with a specific folder content ?
Posted By: Gabriel Cristea
Subject: Populate Treeview with a specific folder content ?
Date Posted: 19 Mar 2019 at 3:58pm
Hi,

How can i populate content of a specific folder in a Treeview with TMSFMXCloudSkyDrive1 ?

Thank you !



Replies:
Posted By: Bart Holvoet
Date Posted: 19 Mar 2019 at 4:38pm
Hi,

You can use the GetFolderList call to retrieve contents of a specific folder.

Example:
  TMSFMXCloudSkyDrive1.GetFolderList(Folder: TCloudItem);


Posted By: Gabriel Cristea
Date Posted: 19 Mar 2019 at 4:51pm
Hi Bart,
Sorry for my begginer questions.

Can you be more specific please ?

How can i declare 'test folder' as TCloudItem, without selected it in Treeview ?

TMSFMXCloudSkyDrive1.GetFolderList('test folder');






Posted By: Bart Holvoet
Date Posted: 19 Mar 2019 at 5:18pm
No problem.
Here's a more elaborate sample.
Note that you need to know the ID of the folder to be able to retrieve it's contents.

Example:
var
  si: TSkyDriveItem;
begin
  ReportMemoryLeaksOnShutdown := true;
  CloudTreeViewAdapter1.TreeView := TreeView1;

  si := TSkyDriveItem.Create(nil);
  si.ID := 'ABC123';
  AdvSkyDrive1.GetFolderList(si);
  si.Free;

You can use the TAdvTreeViewAdapter as well:
var
  si: TSkyDriveItem;
begin
  ReportMemoryLeaksOnShutdown := true;
  CloudTreeViewAdapter1.TreeView := TreeView1;

  si := TSkyDriveItem.Create(nil);
  si.ID := 'ABC123';

  CloudTreeViewAdapter1.InitFolder(si);
  si.Free;


Posted By: Gabriel Cristea
Date Posted: 19 Mar 2019 at 6:07pm
Didn't work
I do not have AdvSkyDrive1 and TAdvTreeViewAdapter and tests with TMSFMXCloudSkyDrive1 and TMSFMXCloudTreeViewAdapter1 didn't work.

With TMSFMXCloudDropBox1, TMSFMXCloudGDrive1, and TMSFMXCloudYandexDisk1 all work ok

Here a sample of my code:
 // DropBox
  if (Sender as TTMSFMXCloudStorageFMX).ClassNameIs('TTMSFMXCloudDropBox') then
  begin
    xDrop := TDropBoxItem.Create(nil);
    xDrop.ItemType := ciFolder;
    xDrop.Path := '/' + xAppNamePublic;
    //
    TMSFMXCloudTreeViewAdapter1.Folder := xDrop;
    TMSFMXCloudTreeViewAdapter1.InitMethod := TCloudAdapterInitMethod.cmFolder;
  end;

  // GDrive
  if (Sender as TTMSFMXCloudStorageFMX).ClassNameIs('TTMSFMXCloudGDrive') then
  begin
    xGDrive := TGDriveItem.Create(nil);
    xGDrive.ItemType := ciFolder;
    if TMSFMXCloudGDrive1.SearchFolder(xAppNamePublic, true) then
      xGDrive := TGDriveItem(TMSFMXCloudGDrive1.Drive.Items[0]);
    //
    TMSFMXCloudTreeViewAdapter1.Folder := xGDrive;
    TMSFMXCloudTreeViewAdapter1.InitMethod := TCloudAdapterInitMethod.cmFolder;
  end;

  // SkyDrive
  if (Sender as TTMSFMXCloudStorageFMX).ClassNameIs('TTMSFMXCloudSkyDrive') then
  begin
    xSky := TSkyDriveItem.Create(nil);
    xSky.ItemType := ciFolder;
//    xSky.Path := '/' + xAppNamePublic;
    xSky.ID := '/' + xAppNamePublic;
    //
    TMSFMXCloudTreeViewAdapter1.Folder := xSky;
    TMSFMXCloudTreeViewAdapter1.InitMethod := TCloudAdapterInitMethod.cmFolder;
  end;

  // YandexDisk
  if (Sender as TTMSFMXCloudStorageFMX).ClassNameIs('TTMSFMXCloudYandexDisk') then
  begin
    xYandex := TYandexDiskItem.Create(nil);
    xYandex.ItemType := ciFolder;
    xYandex.Path := '/' + xAppNamePublic;
    //
    TMSFMXCloudTreeViewAdapter1.Folder := xYandex;
    TMSFMXCloudTreeViewAdapter1.InitMethod := TCloudAdapterInitMethod.cmFolder;
  end;

  //
  TMSFMXCloudTreeViewAdapter1.CloudStorage := zgCloudStorage;


Posted By: Bart Holvoet
Date Posted: 20 Mar 2019 at 9:23am
Please note that the OneDrive API expects a folder ID instead of a name or path.
You can use the same technique as with Google Drive by using the search function to find out a Folder's ID.

Example:
  xSky := TSkyDriveItem.Create(nil);
  TMSFMXCloudSkyDrive1.SearchList(xAppNamePublic, True, nil);
  if TMSFMXCloudSkyDrive1.Drive.Count > 0 then
    xSky := TSkyDriveItem(TMSFMXCloudSkyDrive1.Drive.Items[0]);
  TMSFMXCloudTreeViewAdapter1.Folder := xSky;

  TMSFMXCloudTreeViewAdapter1.InitMethod := TCloudAdapterInitMethod.cmFolder;
  TMSFMXCloudTreeViewAdapter1.CloudStorage := Storage;
  TMSFMXCloudTreeViewAdapter1.InitFolder(TMSFMXCloudTreeViewAdapter1.Folder);


Posted By: Gabriel Cristea
Date Posted: 20 Mar 2019 at 1:34pm
Problem solved

Many thank's !



Print Page | Close Window