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?
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()?
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.