How to store a TFile from a FilePicker for later reference?

Use case: The user needs to pick multiple files. He does this one after the other, not all at once. When he finished selecting files, on button press all files should be uploaded.

To solve this, on every FilePicker.OnChange I store the selected TFile in an "Array of TFile", hoping that magically JS reference counting will keep the TFile object alive. Unfortunately, the FilePicker seems to invalidate the previously selected TFile on next use, so finally my list only contains invalid TFile objects, except for the last one added, because it's still alive in the FilePicker.

Question: How to copy (read: deepclone?) a FilePicker.Files[0] TFile object for storage in a list?

Thanks alot!

Walter

You could push the TFile.FileObject: JSValue in a TJSArray and then work with this array of references to the files selected.

Thank you Bruno, that did the trick!

But would you mind explaing this a little bit? I would like to understand the internals of the memory management!

Why does your suggested

JSArray.push(FilePicker.Files[0].FileObject)

work, -by meas of preserving the file object-, while when using

Var List : Array of TFile;
SetLength(List,1);
List[0] := FilePicker.Files[0]

the List[0].FileObject gets destroyed when using the FilePicker a second time? Is TJSArray.push() doing some JavaScript magic by cloning the object passed to push()?

Thank you very much!

Walter

List[0] := FilePicker.Files[0]
sets in the list item a reference to FilePicker.Files[0] but FilePicker.Files[0] gets replaced when you let it pick a new file.