How to make persistent copy of dataset for offline or later viewing?

In the attached zip, I added a TWebIndexedClientDataSet and the below code to the TMS dataset samples project. The added code does work to enable continued viewing of the downloaded data after the connection is broken. I anticipated that it would also be possible for the data to persist in subsequent runs via the IndexedDB, but the browser dev panel says there is no IDB created. What am I doing wrong?

A related question: Couldn't the TWebClientDataSet be written to TWebLocalStorage as JSON in a string to be fetched back on a subsequent run of the app? How to do that?

      ***
    WebButton1.Tag := 1;
    WebButton1.Caption := 'Disconnect';

// Make a clone of the downloaded dataset to view offline

// The following line succeeds in transferring the DS to the IDBCDS, but only in memory
    WebIndexedDbClientDataset1 := TWebIndexedDbClientDataset(WebClientDataSet1.GetClonedDataSet(False));

// The following seems to have no effect in writing to the actual IDB according to the browser console
    WebIndexedDbClientDataset1.First;
    while not WebIndexedDbClientDataset1.Eof do
    begin
      WebIndexedDbClientDataset1.Edit;
      TAwait.ExecP<Boolean>(WebIndexedDbClientDataset1.PostAsync);
      WebIndexedDbClientDataset1.Next;
    end;

    WebDataSource1.DataSet := WebIndexedDbClientDataset1; // View IDBCDS in browser app after closing connection
    ***

TWCDS_Demo.zip (6.7 KB)

GetClonedDataSet creates a clone dataset of the same class type, i.e. when you call this method for TWebClientDataSet, it will create a clone of the type TWebClientDataSet.

So, you're saying that casting the dataset from TWebClientDataset to TWebIndexedDbClientDataset does not allow the cloned data to populate the IndexedDb even though the data may be accessed via the TWIDBCDS object. Is that correct? That's too bad.

What about the related question of saving the TWCDS object to TWebLocalStorage? Is that possible?

Internal storage of a TWebIndexedDBClientDataSet is completely different from storage in TWebClientDataSet. Hence, simply casting and expecting it will somehow convert internal storage won't work.
For storing a TWebClientDataSet to local storage, you'd need to programmatically serialize the data of the TWebClientDataSet you want to persist to text and save this as text (and vice versa)

Thanks, I understand now that the cast only works properly in the direction from TWIDBCDS to TWCDS even though it appears to succeed in the other direction.

Regarding TWLS, I understand the process you mean. I was hoping that there were some methods implementing that. :face_with_diagonal_mouth: