-5

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?

4

1 回答 1

4

您可以使用本IniFiles机。我已经在 android、windows 和 linux 上使用过它,它似乎工作正常。对于 android 上的文件路径,您可以使用以下内容: System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'config.ini'

在adnroid上保存ini的代码示例:

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;

加载字符串的示例:

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;

加载您设置的值时,如果该名称/密钥不存在,则将返回该值。

于 2018-12-16T07:15:50.777 回答