TWebLocalTextFile
TWebLocalTextFile
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. TWebLocalTextFile
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:
procedure TForm1.WebButton1Click(Sender: TObject);
begin
ATextFile.Filter.Add('All files','application/octet-stream','*.*');
ATextFile.Filter.Add('Text files','text/plain','*.txt');
WebMemo1.Lines.Text := await(string, ATextFile.Open());end;
Properties for TWebLocalTextFile
Property | Description |
---|---|
Filter: TFileFilter | Sets the filter for selecting the local file system |
FileName: string | Gets the filename of the opened local file |
Text: string | Gets or sets the content of the text file as string |
Methods for TWebLocalTextFile
Method | Description |
---|---|
Open: TJSPromise | Async method to open a text file |
Save: TJSPromise | Async method to save a text file |
SaveAs: TJSPromise | Async method to save a text file under a new name |
OpenFile | Method opening a text file. Triggers the OnFileOpen event when the file is asynchronously opened |
OpenFile(AOpenFile: TOpenTextFileProc) | Method opening a text file with anonymous method parameter. |
SaveFile | Method saving a text file. Triggers the OnFileSave event when the file is asynchronously saved |
SaveFile(ASaveFile: TSaveFileProc | Method saving a text file with anonymous method parameter. |
SaveAsFile | Method saving a text file under a different name. Triggers the OnFileSave event when the file is asynchronously saved |
SaveFileAs(ASaveFile: TSaveFileProc | Method saving a text file under a different name with anonymous method parameter. |
Events for TWebLocalTextFile
Property | Description |
---|---|
OnFileOpen | Event triggered when the browser retrieved the data from the text file to be opened |
OnFileSave | Event triggered when the browser performed the saving of the text file on the local file system |