Recent

Author Topic: [SOLVED] LAMW : how to save setting  (Read 5966 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
[SOLVED] LAMW : how to save setting
« on: January 28, 2017, 02:56:58 pm »
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. :'(
« Last Edit: February 12, 2017, 11:51:37 pm by majid.ebru »

Handoko

  • Hero Member
  • *****
  • Posts: 3851
  • My goal: build my own game engine using Lazarus
Re: how to save setting?!?
« Reply #1 on: January 28, 2017, 03:06:08 pm »

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: how to save setting?!?
« Reply #2 on: January 28, 2017, 03:46:03 pm »
.. and in case you favour point-and-click adventures, you could also try XMLPropStorage.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: how to save setting?!?
« Reply #3 on: January 28, 2017, 04:25:42 pm »
can i use inifile in LAMW???
where is inifile save?!?

Handoko

  • Hero Member
  • *****
  • Posts: 3851
  • My goal: build my own game engine using Lazarus
Re: how to save setting?!?
« Reply #4 on: January 28, 2017, 05:04:42 pm »
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][+][-]
  1. jPreferences = class(jControl)
  2.  private
  3.     FIsShared: boolean;
  4.  protected
  5.  public
  6.     constructor Create(AOwner: TComponent); override;
  7.     destructor  Destroy; override;
  8.     procedure Init(refApp: jApp); override;
  9.     function jCreate( _IsShared: boolean): jObject;
  10.     procedure jFree();
  11.     function GetIntData(_key: string; _defaultValue: integer): integer;
  12.     procedure SetIntData(_key: string; _value: integer);
  13.     function GetStringData(_key: string; _defaultValue: string): string;
  14.     procedure SetStringData(_key: string; _value: string);
  15.     function GetBoolData(_key: string; _defaultValue: boolean): boolean;
  16.     procedure SetBoolData(_key: string; _value: boolean);
  17. published
  18.     property IsShared: boolean read FIsShared write FIsShared;
  19. 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.
« Last Edit: January 28, 2017, 05:06:46 pm by Handoko »

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: how to save setting?!?
« Reply #5 on: January 29, 2017, 04:41:17 am »
how can i use these codes??

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: how to save setting?!?
« Reply #6 on: January 29, 2017, 05:10:52 am »

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...
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: how to save setting in LAMW?!?
« Reply #7 on: February 06, 2017, 09:36:25 am »
hi
can you more explain about " jPreferences" or show me an example  ?
i don't know how to use it? %) %) %) %)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: how to save setting in LAMW?!?
« Reply #8 on: February 10, 2017, 08:53:46 am »
please help me
 :( :( :( :( :(
 :-X :-X :-X
 :'( :'( :'( :'(

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW : how to save setting
« Reply #9 on: February 11, 2017, 02:03:15 am »

Save string data:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1Close(Sender: TObject);
  2. begin
  3.   jPreferences1.SetStringData('myStrData', 'Hello World!');
  4. end;
  5.  

Read string data:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2. var
  3.    strData: string;
  4. begin
  5.     strData := jPreferences1.GetStringData('myStrData', '');
  6.     ShowMessage(strData);
  7. end;
  8.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: LAMW : how to save setting
« Reply #10 on: February 12, 2017, 01:46:33 pm »
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][+][-]
  1. 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][+][-]
  1. 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

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW : how to save setting
« Reply #11 on: February 12, 2017, 09:31:53 pm »
First:  You need add unit "inifiles" to "uses" section ...

Reading ...
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2. var
  3.   strData: string;
  4.   iniconfig: TInifile;
  5. begin
  6.   strData := jPreferences1.GetStringData('myStrData', '');
  7.   ShowMessage('From Preferences = '+ strData);
  8.  
  9.   //USING INI File
  10.   iniconfig:= TInifile.Create(Self.GetEnvironmentDirectoryPath(dirSdCard)+ '/' + 'AppConfig.txt');
  11.   strData:= iniconfig.ReadString('CONFIG', 'IniStrData', '');
  12.   ShowMessage('From INI file = ' +strData);
  13.   iniconfig.Free;
  14. end;
  15.  

Writing ....
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1Close(Sender: TObject);
  2. var
  3.   iniconfig: TInifile;
  4. begin
  5.   jPreferences1.SetStringData('myStrData', 'Hello World!');
  6.  
  7.   //USING INI File
  8.   iniconfig:= TInifile.Create(Self.GetEnvironmentDirectoryPath(dirSdCard)+ '/' + 'AppConfig.txt');
  9.   iniconfig.WriteString('CONFIG', 'IniStrData', 'Hello INI World!');
  10.   iniconfig.Free;
  11. end;
  12.  
« Last Edit: February 12, 2017, 09:38:38 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: LAMW : how to save setting
« Reply #12 on: February 12, 2017, 11:50:24 pm »
finally it get my answer  :o :o

thank you very much
 :) ;) ;D O:-) 8-)

 

TinyPortal © 2005-2018