[fpc-pascal] Re: Fpc Access Violation if AppConfigDir doesn't exist.

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Feb 11 00:37:45 CET 2013


On Mon, 11 Feb 2013 00:13:00 +0100
Giuliano Colla <giuliano.colla at fastwebnet.it> wrote:

>[...]
> 3) But if also the *path* to the file doesn't yet exist, it just crashes 
> without rising an exception that the user application can handle somehow.

I get an exception in this case:
  inifile:=TIniFile.Create('/does/not/exist/bla.ini');
  inifile.WriteString('Sec','First','1');
  inifile.UpdateFile;

 
> This is rather unpleasant, because the path provided by GetAppConfigXx 
> does usually exist, so you have an application which 99% of the times 
> works just fine, and 1% of the times crashes without telling why.

Even if the directory exists the write may fail. So you must use a
try..except anyway.

 
> This was perhaps tolerable when GetAppPathConfigXx did not exist, and it 
> was developer responsibility to provide a reasonable path, taking into 
> account different target system, but today I'd expect TIniFile to take 
> care also of forcing the appropriate path, and to raise an exception if 
> it fails.


Mattias



More information about the fpc-pascal mailing list