[Lazarus] Unable to rewrite .ini file which exists... error unable to create .ini file. (need to rewrite it).

Sven Barth pascaldragon at googlemail.com
Tue Mar 15 15:44:51 CET 2011


Am 15.03.2011 15:24, schrieb Peter Williams:
> Hi Bart,
>
>  > Date: Tue, 15 Mar 2011 12:45:49 +0100
>  > From: bartjunk64 at gmail.com
>  > To: lazarus at lists.lazarus.freepascal.org
>  > Subject: Re: [Lazarus] Unable to rewrite .ini file which exists...
> error unable to create .ini file. (need to rewrite it).
>  >
>  > On 3/15/11, Peter Williams <pewilliams2010 at live.com> wrote:
>  >
>  > > ConfigIni :=
> TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
>  >
>  > You really should not do that in most OS's, even on Windows it is
>  > deprecated since win9x.
>  > Most times you will not have write permissions there.
>  > Also under *nix this location might not be what you expect it to be...
>  >
>  > Use GetAppConfigDir to determine where to put INI files.
>
> I found the declaration for function GetAppConfigDir in osutilsh.inc but
> I cannot find the actual function (I am looking in the wrong file).
>

If you search the function by clicking on the identifier in Lazarus 
while pressing "Ctrl" you should be able to use "Ctrl + Shift + Down" to 
find the declaration.

Alternatively you can search the directory "%lazarus%\fpc\%version%\rtl" 
to find the implementation (might be some file in the win or win32 
directory).

> Function GetAppConfigDir(Global : Boolean) : String;
> Function GetAppConfigFile(Global : Boolean) : String;
> Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
>
> What is the "Global : Boolean" parameter that it takes? Can someone
> please give me an example as to how it is called?

If global is true the system's configuration directory is returned, if 
false the current user's directory.

E.g.:

Windows 7:
GetAppConfigDir(True):
C:\ProgramData\AppName
GetAppContigDir(False):
C:\Users\Sven\AppData\Local\AppName (or Roaming, I haven't tested, to be 
honest)

Linux:
GetAppConfigDir(True):
/etc/AppName
GetAppConfigDir(False):
/home/sven/.config/AppName

When you use GetAppConfigFile instead, AppName.cfg is returned instead 
of AppName.

See also:
http://www.freepascal.org/docs-html/rtl/sysutils/getappconfigdir.html
http://www.freepascal.org/docs-html/rtl/sysutils/getappconfigfile.html

Regards,
Sven




More information about the Lazarus mailing list