HEScript/Javascript How to Save To And Read From Text from a textarea

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

function OnFormSubmit(Action, Method: String): Boolean; does not exist anymore in HTMLEXE.
You have to use JavaScript to pass the content of the textbox to the WriteTextToFile method you defined. Can you post the HTML code of your existing form?

when I change S := GetGlobalVar(“HEPubStorageLocation”, “”);
to S:= GetGlobalVar(“HEPublicationPath”, “”); also, so it saves where the program is…

I have also changed S2 := GetFormContents; to S2 := GetFormFieldValue; Does Not Work Either from Documentation? would it be GetFormControlValue? instead? I have also tried to write my own delphi script from the links provided in you docs and help files in HTMLEXE. But, cannot get any type of save to text file to work, yet. So far I have managed to open an image from the programs folder in another folder, into my Program built in HTML!

when you call to an hescript what is the correct way?
#javascript:window.external.runHEScriptCom(‘UserMain.WriteText’)?
#javascript:htmlexe.runHEScriptCom(‘UserMain.WriteText’)?

Thanks for your help. :smiley:

Could I still get some help on this, having some trouble with it