2013-10-22 7 views
6

私はiOSプラットフォームの新機能です。私は自分のアプリケーション用のINIファイルを保存しようとしています。問題は、書き込み権限を持つパスを取得できないことです。私は、ファイルを作成できないという例外を取得アプリケーションからiOSにTiniFileを保存します

ini := TIniFile.Create(GetHomePath + '/user.dat'); 
    try 
    ini.WriteString('data','user',edtuser.Text); 
    ini.WriteString('data','descr',edt1.Text); 
    finally 
    ini.Free; 
    end; 

は、ここに私のコードです。 Firemonkeyを使用して書き込み可能なパスを取得するにはどうすればよいですか?

答えて

12

使用TPath.GetDocumentsPath(およびハードコードされた/を削除するには、連結の代わりにTPath.Combineを使用):

透過的にサポートされているすべてのプラットフォーム(Win32の、Win64の、OSX、iOS版、およびAndroidの)間 TPath.GetDocumentsPath作品を使用して
uses 
    Systen,IOUtils; 


ini := TIniFile.Create(TPath.Combine(TPath.GetDocumentsPath, 'user.dat')); 

TPath.Combineを使用すると、自動的にTPath.DirectorySeparatorCharが追加されるため、手動で連結する必要はありません。あなたはしかし、それを自分で行うことを好む場合

var 
    IniName: string; 
begin 
    IniName := TPath.GetDocumentsPath + TPath.DirectorySeparatorChar + 'user.dat'; 
    Ini := TIniFile.Create(IniName); 
    try 
    // Rest of code 
    finally 
    Ini.Free; 
    end; 
end; 
2

thisであってもよいし、thisはあなたに

uses INIFiles; 

function TForm6.MyINIFilePath: string; 
begin 
// Result := GetHomePath + PathDelim + 'Library' + PathDelim+'My.ini'; 
    Result := GetHomePath + PathDelim + 'Documents' + PathDelim+'MyD.ini'; 
end; 
を助けることができます
関連する問題