Having trouble saving and reading text files from a text area in an html page.
Found this:
uses Classes; //Add this to the top of the script
procedure WriteTextToFile(Filename, Contents: String);
var
T: TStringList;
begin
T := TStringList.Create;
// Sets the contents.
T.Text := Contents;
// Saves the file.
T.SaveToFile(Filename);
T.Free;
end;
procedure WriteText;
var
S, S2: String;
begin
// A simple script to test the function.
// Finds a name for our text file.
// a) Gets the path to the folder where to save the file.
S := GetGlobalVar(“HEPubStorageLocation”, “”);
if S = “” then exit;
// b) Appends the filename
S := IncludeTrailingBackslash(S) + “testfile.txt”;
// Then obtains the form contents.
S2 := GetFormContents;
// Calls our procedure to output a text file.
if S2 <> “” then WriteTextToFile(S, S2);
end;
function OnFormSubmit(Action, Method: String): Boolean;
begin
// When a form is submitted by the user (HTML Viewer only)
WriteText;
// Set Result to True if you do not want the viewer to handle the form action itself.
Result := False;
end;
function ReadTextFile(Filename: String): String;
var
T: TStringList;
begin
T := TStringList.Create;
// Loads the text file.
T.LoadFromFile(Filename);
// Gets the contents.
Result := T.Text;
T.Free;
end;
and this i found:
uses Classes; // Add this to the top of the script
procedure SaveFile;
var
SF, S: String;
T: TStringList;
begin
// Retrieves the data saved by the JavaScript.
S := GetGlobalVar(“datatosave”, “”);
if S = “” then exit;
// Asks for filename
SF := SaveFileDialog(“Save Text As”, “.htm", ".htm”, “HTML Files (.htm)|.htm|All files (.)|.”, “”);
if SF = “” then exit; // User cancelled.
// Saves to a file
T:= TStringList.Create;
T.Text := S;
T.SaveToFile(SF);
T.Free;
end;
procedure LoadFile;
var
SF, S: String;
T: TStringList;
begin
// Ask which file to open.
SF := OpenFileDialog(“Open HTML file”, “.htm", ".htm”, “HTML Files (.htm)|.htm|All files (.)|.”, “”);
if SF = “” then exit; // User cancelled.
T:= TStringList.Create;
T.LoadFromFile(SF);
S := T.Text;
T.Free;
// Sets to the new one, that will be used when reloading the page.
SetGlobalVar(“datatoload”, S, false);
end;
Not working correctly with a textarea and an input button in the html page