Google Drive: getting in the OnSearch second time will set to NIL a previously set TTMSFNCCloudItem

Hello,

I have the following code. When connected to Google drive I search for the folder "MyFolder1" and I store the folder in the CloudItemFolder1 variable (using the OnSearch event).
It goes on the 1.st option. This works properly:

var
CloudItemFolder1 : TTMSFNCCloudItem;
CloudItemFolder2 : TTMSFNCCloudItem;
...

...
Class Procedure TTMSFNCCloudGoogleDriveService.EOnConnected(Sender: TObject);
begin
HowToSearch := 1;
f_CloudGoogleDrive.SearchFolder('MyFolder1',True) ;
end;

Class Procedure TTMSFNCCloudGoogleDriveService.EOnSearch(Sender: TObject;const ASearchResults: TTMSFNCCloudGoogleDriveItems;const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
case HowToSearch of
1:
Begin
CloudItemFolder1 :=ASearchResults.Items[0] ;
End;

2: 
 Begin
    If ASearchResults.Count=0 Then //
     Begin
       CloudItemFolder2 :=ASearchResults.Items[0] ; 
     End;
 End;

end;

end;

After the OnSearch the CloudItemFolder1 variable is set properly, pointing at the respective folder.
However when I click on a button and I call this, to search for MyFolder2:

Class Procedure TTMSFNCCloudGoogleDriveService.SecondFolder;
Begin
HowToSearch := 2;
f_CloudGoogleDrive.SearchFolder('MyFolder2',True) ;
End;

... and this calls the EOnSearch again:

Class Procedure TTMSFNCCloudGoogleDriveService.EOnSearch(Sender: TObject;const ASearchResults: TTMSFNCCloudGoogleDriveItems;const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
case HowToSearch of <- HERE ALREADY CloudItemFolder1 became NIL
...

How can it be that getting in the OnSearch the second time causes the previously set TTMSFNCCloudItem to become NIL?
My goal is to keep the most important folders "ready" in variables for the program user, so when he chooses to upload a file, I can immediately do so.

The code above would run only once, when the app starts.

Thank you for your help!

Hi,

Please note that there is no built-in functionality available to persist search results. This means that with every search action the data of the previous search action is no longer available in the component.
You'll have to manually persist the data you need for your application.

Hi Bart,

You'll have to manually persist the data you need for your application

But this is what I did by issuing "CloudItemFolder1 :=ASearchResults.Items[0] ;" didn't I?
I put the search result in a global TTMSFNCCloudItem variable.

Then how would you save two folders in two TTMSFNCCloudItem variables, so as the would persist?

Thank you!

Can you please try using Assign instead? (Note that you'll have to manually create and free the TTMSFNCCloudItem objects as well)

CloudItemFolder1.Assign(ASearchResults.Items[0]);

Thank you very much, Bart. This seems to work!

Happy to help!

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.