This method is not recommended because the Sharedpreference is an Android method. You want to cross-platform, you can not use on iOS. It is recommended to use INI or XML. Android because read and write the two kinds of files more cumbersome, so launch their own simple sharedpreference.
Back to the topic. On the code:
Note the reference unit:
Uses androidapi.helpers;
1 procedureTform_getparas.getparas;2 varprefs:jsharedpreferences;3 Editor:jsharedpreferences_editor;4 I:integer;5 begin6Prefs: =sharedactivity.getpreferences (TJActivity.JavaClass.MODE_PRIVATE);7Fv_usegname: = jstringtostring (Prefs.getstring (stringtojstring ('Username'), Stringtojstring ("')));8FV_PW: = jstringtostring (Prefs.getstring (stringtojstring ('USERPW'), Stringtojstring ("')));9Fv_serverip: = jstringtostring (Prefs.getstring (stringtojstring ('ServerIP'), Stringtojstring ('127.0.0.1')));Ten Try OneFv_serverport: = IntToStr (Prefs.getint (stringtojstring ('ServerPort'),8099)); A except -Fv_serverport: ="'; - End; the End;
Write Parameters:
1 procedureTform_getparas.writerparas;2 varprefs:jsharedpreferences;3 Editor:jsharedpreferences_editor;4 I:integer;5 begin6Prefs: =sharedactivity.getpreferences (TJActivity.JavaClass.MODE_PRIVATE);7Editor: =Prefs.edit;8Editor.putstring (Stringtojstring ('ServerIP'), stringtojstring (Fv_serverip));9Editor.putstring (Stringtojstring ('Username'), stringtojstring (Fv_usegname));TenEditor.putstring (Stringtojstring ('USERPW'), stringtojstring (FV_PW)); One Try AI: =Strtoint (fv_serverport); -Editor.putint (Stringtojstring ('ServerPort'), i); - except theEditor.putstring (Stringtojstring ('ServerPort'), Stringtojstring ('8099')); - End; -Editor.commit;//apply; - End;
Android Data and Access (2)-delphi Xe7 How do I access my app configuration parameters file?