Can someone give me an example of LoadFromFile and SaveToFile for local/client loading/saving of a rich/text file?
WebRichEdit.Lines.LoadFromFile
WebRichEdit.LInes.SaveToFile
Pas2JS Compiler version 1.4.6 [2019/04/20] for Win32 i386 / TMS WEB Core version v1.2.0.0
[Error] Unit3.pas(30): identifier not found "SaveToFile"
WebRichEdit1.Lines.LoadFromFile('file:///C:/temp/temp.txt'); <- returns an http GET error
WebRichEdit1.Lines.LoadFromFile('C:\temp\temp.txt'); <- tried this as well. Same GET error.
Tested using a blank web form with a web button and a WebRichEdit component.
-Scott
You cannot just access local files this way as this would be a serious security breach if it would be possible.
To get access to local files, use a TWebFilePicker. Implement the OnChange event and from this event get the file as text and get the actual text to load in the TWebRichEdit from the
procedure TForm1.WebFilePicker1Change(Sender: TObject);
begin
WebFilePicker1.Files[0].GetFileAsText;
end;
procedure TForm1.WebFilePicker1GetFileAsText(Sender: TObject;
AFileIndex: Integer; AText: string);
begin
WebRichEdit1.Lines.Text := AText;
end;
To save the file, you can use
Application.DownloadTextFile(AText, AFileName: string);
Thanks Bruno.
Wouldn't it be better to override the SaveToFile and LoadFromFile with something more elegant, in line with with the quality we are used to seeing from TMS? :-)
Override LoadFromFile with FIlePicker and make something a little nicer than DownloadTextFile?
Just tossing that out there ;-)
-Scott
We'll discuss here, taking in account that we'd prefer to have these base classes working on the 3 application types we support so far, web client, PWA and Electron.