[SOLVED] LAMW : how to save setting lazarus / 43-Android ---------------------------------------------------------------------- majid.ebru · 2017-01-28 13:56 hi evry body i want to save setting my program?? for example in my program,i have 10 button and 4 edit.text and ..... at first time i pressed 3 button and in 2 edit.text i write my name and ladt name. when i closed program i want to save all changed?!? at second time,i open program: 3 button should pressd and my name and my last name should be in edit.text i want like ini file!?! an other example ,my program is like soduko when player write number in house, when player cloesd program,i should save these numbers. and at second time,i should restore these numbers?!? excuseme my english language is weak. ---------------------------------------------------------------------- Handoko · 2017-01-28 14:06 You can use TIniFile: http://www.freepascal.org/docs-html/fcl/inifiles/tinifile.html And here is the tutorial: http://wiki.freepascal.org/Using_INI_Files ---------------------------------------------------------------------- molly · 2017-01-28 14:46 .. and in case you favour point-and-click adventures, you could also try XMLPropStorage. ---------------------------------------------------------------------- majid.ebru · 2017-01-28 15:25 can i use inifile in LAMW??? where is inifile save?!? ---------------------------------------------------------------------- Handoko · 2017-01-28 16:04 Oh, I'm sorry I didn't see you post this question under Android section. I'm not sure, but I don't think you can use TIniFile in Android programming. After some inspection on LAMW toolbars, I found you may use JPreferences (under Android Bridges Extra tab). Here is the class structure of jPreferences: 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 jPreferences = class(jControl) private    FIsShared: boolean; protected public    constructor Create(AOwner: TComponent); override;    destructor  Destroy; override;    procedure Init(refApp: jApp); override;    function jCreate( _IsShared: boolean): jObject;  procedure jFree();    function GetIntData(_key: string; _defaultValue: integer): integer;    procedure SetIntData(_key: string; _value: integer);    function GetStringData(_key: string; _defaultValue: string): string;    procedure SetStringData(_key: string; _value: string);    function GetBoolData(_key: string; _defaultValue: boolean): boolean;    procedure SetBoolData(_key: string; _value: boolean);published    property IsShared: boolean read FIsShared write FIsShared;end; So it is clear that you can use: - GetIntData / SetIntData - GetStringData / SetStringData - GetBoolData / SetBoolData Where is inifile save? The location is handled automatically by the OS. ---------------------------------------------------------------------- majid.ebru · 2017-01-29 03:41 how can i use these codes?? ---------------------------------------------------------------------- jmpessoa · 2017-01-29 04:10 Hi, Put a  jPreferences component  (under Android Bridges Extra tab) in form designer and use the methods  "Set..." to save [Onclose?] and "Get..." to read  [onJNIPrompt?]  Please, edit/add "LAMW"  to subject... ---------------------------------------------------------------------- majid.ebru · 2017-02-06 08:36 hi can you more explain about " jPreferences" or show me an example  ? i don't know how to use it? ---------------------------------------------------------------------- majid.ebru · 2017-02-10 07:53 please help me ---------------------------------------------------------------------- jmpessoa · 2017-02-11 01:03 Save string data: 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.AndroidModule1Close(Sender: TObject);begin  jPreferences1.SetStringData('myStrData', 'Hello World!');end;  Read string data: 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.AndroidModule1JNIPrompt(Sender: TObject);var   strData: string;begin    strData := jPreferences1.GetStringData('myStrData', '');    ShowMessage(strData);end; ---------------------------------------------------------------------- majid.ebru · 2017-02-12 12:46 in windows i save my setting into Text file.(like setting.txt). when my program opened , at first time i read this file. this file is at my program folder . this file is an address.( like "c:\myprogram\setting.txt") when i use 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 jPreferences1.SetStringData('myStrData', 'Hello World!'); where this data saved? i should read data where folder(where address)? what is this file address? you just say 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 jPreferences1.SetStringData('myStrData', 'Hello World!');  this is ok,but i want to save my setting in myprogram folder(/mnt/extSdCard/myprogram) like windows so sorry ,my English language is weak . thank you ---------------------------------------------------------------------- jmpessoa · 2017-02-12 20:31 First:  You need add unit "inifiles" to "uses" section ... Reading ... 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.AndroidModule1JNIPrompt(Sender: TObject);var  strData: string;  iniconfig: TInifile;begin  strData := jPreferences1.GetStringData('myStrData', '');  ShowMessage('From Preferences = '+ strData);   //USING INI File  iniconfig:= TInifile.Create(Self.GetEnvironmentDirectoryPath(dirSdCard)+ '/' + 'AppConfig.txt');  strData:= iniconfig.ReadString('CONFIG', 'IniStrData', '');  ShowMessage('From INI file = ' +strData);  iniconfig.Free;end;  Writing .... 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.AndroidModule1Close(Sender: TObject);var  iniconfig: TInifile;begin  jPreferences1.SetStringData('myStrData', 'Hello World!');   //USING INI File  iniconfig:= TInifile.Create(Self.GetEnvironmentDirectoryPath(dirSdCard)+ '/' + 'AppConfig.txt');  iniconfig.WriteString('CONFIG', 'IniStrData', 'Hello INI World!');  iniconfig.Free;end; ---------------------------------------------------------------------- majid.ebru · 2017-02-12 22:50 finally it get my answer  thank you very much ---------------------------------------------------------------------- neuro · 2022-07-15 14:42 Quote from: jmpessoa on February 11, 2017, 02:03:15 amSave string data: 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.AndroidModule1Close(Sender: TObject);begin  jPreferences1.SetStringData('myStrData', 'Hello World!');end;  In Target SDK version 33 jPreferences are not saved in AndroidModule1Close event. I guess maybe AndroidModule1Close is not invoked in Target SDK 33 when app is closed. ---------------------------------------------------------------------- rsu333 · 2022-07-16 13:37 I may be wrong ,But you can save your text data adding to listview followed by save to txt. On next attempt you can load it into edittext via listview ---------------------------------------------------------------------- jluixjurado · 2022-09-21 13:03 Hi! As stated before by neuro, It seems that preferences are not saved when tried in OnClose nor in OnCloseQuery but they're saved if you put them in OnActivityPause or in OnActivityStop. Even there I've got no luck when trying something like preferences.SetStringData('IdMovil',etIdMovil.Text); , (perhaps because etIdMovil doesn't exists anymore when those methods are called) The only way I've found so far for that is updating that preference in OnChanged for etIdMovil component, but that, in my opinion, is not the clearest way to do that.