Write to txt file on android LAMW lazarus / 43-Android ---------------------------------------------------------------------- Xander · 2017-06-25 07:27 Im trying to write to a txt file on android. When I used delphi I was able to do this but in Lazarus the same way does not work. Laz4Android does not recognise IOUtils in the uses so I cant use my applications home path. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Classes, SysUtils, AndroidWidget, Laz_And_Controls, textfilemanager,  opendialog, fileprovider, IOUtils ;     public    sFilePath : String;    txtFile : TextFile;     sString : String;     const      AppPath = TPath.GetHomePath; //Write to file   sFilePath := TPath.Combine(AppPath, 'Day 1.txt');  AssignFile(txtFile, sFilePath);   if FileExists(sFilePath) then  begin    ShowMessage('True');    Append(txtFile);    WriteLn(txtFile,sString);    CloseFile(txtFile);  end else  begin    ShowMessage('False');    Rewrite(txtFile);    WriteLn(txtFile,sString);    CloseFile(txtFile);  end; ---------------------------------------------------------------------- jmpessoa · 2017-06-25 17:34 Hi Xander! drop "IOUtils" from you project and try: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.jButton1Click(Sender: TObject);var  txtFile : TextFile;  sFilePath: string;  sString: string;begin  sFilePath:=  self.GetEnvironmentDirectoryPath(dirDownloads) + '/' + 'MyTest.txt';  AssignFile(txtFile, sFilePath);   sString:= 'Hello World!';   if FileExists(sFilePath) then  begin      ShowMessage('True');      Append(txtFile);      WriteLn(txtFile,sString);      CloseFile(txtFile);  end  else  begin      ShowMessage('False');      Rewrite(txtFile);      WriteLn(txtFile,sString);      CloseFile(txtFile);  end;end;  PS. Please, put LAMW in your subject... ---------------------------------------------------------------------- Leledumbo · 2017-06-25 20:07 I think the OP needs TPath.GetHomePath which is documented as: QuoteOn iOS and Android, it points to the device-specific location of the sandbox for the application. which translates to /data/data/, this path is accessible only by root or the application itself. ---------------------------------------------------------------------- jmpessoa · 2017-06-25 20:43 I dont found unit "IOUtils" in "fpc 3.1.1" ... but  LAMW  can handle intern app storage path: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sFilePath:=  self.GetEnvironmentDirectoryPath(dirInternalAppStorage) + '/' + 'MyTest.txt'; ---------------------------------------------------------------------- Xander · 2017-06-26 16:27 Thanks alot ---------------------------------------------------------------------- Xander · 2017-06-26 17:07 I know this is not part of the topic but do any of u maybe know when memos will be available in LAMW? ---------------------------------------------------------------------- jmpessoa · 2017-06-26 20:21 Ok. I will try implement the "jMemo" component! But you can get a memo [like] just now: try  [from AppDemo1  "unit14"]: Quote  object jEditText1: jEditText     LayoutParamWidth = lpMatchParent     LayoutParamHeight = lpOneQuarterOfParent     InputTypeEx = itxMultiLine     MaxTextLength = 3000     MaxLines = 50                                 <<--- max visible lines!     HorScrollBar = False     VerScrollBar = True     WrappingLine = True   end ---------------------------------------------------------------------- Xander · 2017-06-27 04:40 Thanks again for another quick reaponse. The edit works perfectly, now im facing another problem again . How can i load the text from the file into the edit? In delphi I used memo.Lines.LoadFromFile(sFilePath); obviously this does not work now because im not using a memo. LoadFromFile is not an obtion with JEditText.Text. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.btnLoadClick(Sender: TObject);var  sLoaded : String;begin   //Load from file  sFilePath := self.GetEnvironmentDirectoryPath(dirInternalAppStorage)+ '/' +  'MyTest.txt';  AssignFile(txtFile, sFilePath);  if FileExists(sFilePath) then  begin    Read(txtFile,sLoaded);    ShowMessage('Succes');    jEditText1.Text := sLoaded;    //mmo.Lines.LoadFromFile(sFilePath);    CloseFile(txtFile);  end else  begin    ShowMessage('Fail');  end;end; ---------------------------------------------------------------------- jmpessoa · 2017-06-30 23:36 Quote How can i load the text from the file into the edit? Now you can! Added LoadFromFile and SaveToFile to jEditText ! Please, update from github! Thank you! ---------------------------------------------------------------------- Xander · 2017-07-02 09:29 Im not sure if i did something wrong but I get this message even after updating LAMW. I downloaded with TortoiseSVN. I then ran Laz4Android and installed al the packages again. ---------------------------------------------------------------------- Cyrax · 2017-07-02 09:38 Quote from: Xander on July 02, 2017, 11:29:57 amIm not sure if i did something wrong but I get this message even after updating LAMW. I downloaded with TortoiseSVN. I then ran Laz4Android and installed al the packages again. Maybe this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jEditText1.LoadFromFile('yourtextfile.txt'); The type of first parameter of LoadFromFile method is String, not TextFile. ---------------------------------------------------------------------- Xander · 2017-07-02 13:06 Hi im sorry that this is getting such a problem, I really dont know what im doing wrong again. I got an error again. ---------------------------------------------------------------------- Cyrax · 2017-07-02 14:14 You probably need the code from jmpessoa's github page. And you need TortoiseGIT for it. ---------------------------------------------------------------------- jmpessoa · 2017-07-03 01:23 Hello Xander! Try: "Run" ---> "Clean up and Build",  so you can update the [compiled] project files... NOTE: You can use "SaveToFlie/LoadFromFile(_filename: string)" for internal app storage... and  "SaveToFlie/LoadFromFile(_path: string; _filename: string)"  for publics  storage... [dowmload, pictures, ..., etc ...] ---------------------------------------------------------------------- Xander · 2017-07-15 15:14 Today I completely deleted laz4android and LAMW from my laptop and reinstalled laz4android. I then Downloaded the LAMW zip file instead of updating with git repository or tortoise SVN. I then compiled and installed the three package files of LAMW into laz4android and set the paths. I then created i completely new GUI application with LAMW and inserted a jbutton and jeditText and STILL there is no LoadFromFile or SaveToFile method for jEditText. ---------------------------------------------------------------------- jmpessoa · 2017-07-15 17:29 Fixed!  Sorry.... Load/SaveToFile now is "public"   !! Thank you!