-4

For a program I really need your help.

I found a cross platform Delphi script to save and load INI files on devices, which was made for an earlier Delphi version.

Now, here's my problem: It works perfectly fine on my Windows computer, but won't work on Android. The main problem is that it doesn't know the unit reference on Line 61 (FMX.Inifiles.Android) and, missing this unit, it can't proceed.

Any ideas how I could fix that?

  • 2
    Have a closer look in that repository and you will find it: https://github.com/freeonterminate/delphi/tree/master/FMX.IniFile – dummzeuch Dec 15 '18 at 14:54
  • 1
    "Any ideas how I could fix that?" By making sure the file that is missing is present, either in the same folder as your project, or in the search path of the project, or of the IDE. – Dave Nottage Dec 15 '18 at 19:27
  • Yes, i did that, the issue is that the files are outdated and wont work in Rad Studio 10 at all. The FMX.IniFile.Android.pas uses old vommands, which arent supported anymore, which Delphi will give out as an error too. –  Dec 26 '18 at 00:51

1 Answers1

4

You can use the IniFiles unit. I have used it on android, windows and linux and it seems to work fine. For the file path on android you would use something like: System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'config.ini'

Code example on saving ini on adnroid:

procedure SaveSettingString(Section, Name, Value: string);
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'config.ini');
  try
    ini.WriteString(Section, Name, Value);
  finally
    ini.Free;
  end;
end;

Example on loading a string:

function LoadSettingString(Section, Name, Value: string): string;
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'config.ini');
  try
    Result := ini.ReadString(Section, Name, Value);
  finally
    ini.Free;
  end;
end;

When loading what ever you set as the value will be returned if that Name/Key does not exist.

Adriaan
  • 806
  • 7
  • 24
  • Thanks, but if i use these commands, which units am i expected to use in uses? Just Ioutils for the android version as well as for the Windows version? Or do you mean i should hse the github code and just adjust the lines for the android part? Thanks anyways –  Dec 26 '18 at 00:59
  • In your uses add `IniFiles`. This works for all platforms. Then you can use the code I provided. – Adriaan Dec 26 '18 at 09:11
  • Edited: It works, thank you again @Adriaan Boshoff , but i got one problem left: If i want to open the file on my phone to just edit some values in the ini-file or just watch the structure of it, my phone doesnt find the file on my phone. Is there any way to do that –  Dec 28 '18 at 21:09
  • People are not supposed to be able to view or edit the file. I would suggest making a debug message to check where the file path is. Create a button and use the following code on the on click: `Showmessage(System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'config.ini');` – Adriaan Dec 29 '18 at 10:03
  • Thanks, but i think that isn't exactly what i need, i need to open the file itself, no matter what the path of it is. It would be very helpful if i could open it on my phone, but sounds like there isn't a way to do that, right? –  Dec 29 '18 at 15:29
  • Change the file extension to .txt, so that the standard "Files" app can open it. – Freddie Bell Jun 22 '22 at 07:52