Skip to content

TWebLocalBinaryFile

TWebLocalBinaryFile is a non-visual component that allows to read/write text files on the local file system. Note that this uses the web standards local file system access APIs not yet implemented on all browsers. Any browser based on the Google Chromium engine supports it.

Local file access is performed asynchronously. TWebLocalBinaryFile offers 3 variations of methods to open and save files. There are async methods that can use await() for sequentially written code, there are methods that perform the local file operation and trigger an event when finished and there are methods using an anonymous method parameter and calling this anonymouse method when finished.

Example:

// loading an image as binary file with an anonymous method
procedure TForm1.WebButton11Click(Sender: TObject);
var
 base64String: string;
begin
 ABinaryFile.Filter.Add('Text files','image/jpeg','*.jpg');
 ABinaryFile.OpenFile(procedure(AValue: TJSArrayBuffer)
 begin
 base64string := ArrayBufferToBase64(AValue);
 base64string := 'data:image/jpeg;base64,'+base64String;
 WebImageControl1.URL := base64string;
 end);
end;

Properties for TWebLocalBinaryFile

Property Description
Filter: TFileFilter Sets the filter for selecting the local file system
FileName: string Gets the filename of the opened local file
Data: TJSArrayBuffer Gets or sets the content of the binary file as array buffer

Methods for TWebLocalBinaryFile

Method Description
Open: TJSPromise Async method to open a binary file
Save: TJSPromise Async method to save a binary file
SaveAs: TJSPromise Async method to save a binary file under a new name
OpenFile Method opening a binary file. Triggers the OnFileOpen event when the file is asynchronously opened
OpenFile(AOpenFile: TOpenTextFileProc) Method opening a binary file with anonymous method parameter.
SaveFile Method saving a binary file. Triggers the OnFileSave event when the file is asynchronously saved
SaveFile(ASaveFile: TSaveFileProc Method saving a binary file with anonymous method parameter.
SaveAsFile Method saving a binary file under a different name. Triggers the OnFileSave event when the file is asynchronously saved
SaveFileAs(ASaveFile: TSaveFileProc Method saving a binary file under a different name with anonymous method parameter.

Events for TWebLocalBinaryFile

Event Description
OnFileOpen Event triggered when the browser retrieved the data from the binary file to be opened
OnFileSave Event triggered when the browser performed the saving of the binary file on the local file system