[Lazarus] GetAppConfigDir problem

Lee Jenkins lee at datatrakpos.com
Tue May 6 02:58:06 CEST 2008


Lee Jenkins wrote:
> Lee Jenkins wrote:
>> On Windows, this method returns the application's directory.  IMO, this is wrong 
>> since its customary to install applications in the Program Files directory and 
>> with tighter locked down XP/2000 and DEFINITELY Vista, this is a problem since 
>> you are not usually given permission to write in these destinations now.
>>
>> I think the GetSpecialDir method should be called (as it is with when the 
>> "Global" flag is false) with parameter CSIDL_COMMON_DOCUMENTS.
>>
>> Reported:
>> http://bugs.freepascal.org/view.php?id=11257
>>
> 
> As a follow up, can anyone suggest how I could access the GetSpecialDir from 
> outside sysutils.pas?  I've tried it and it seems that its not in the interface 
> section or I think think this is the case.  I get a little confused with the 
> includes.
> 

I just went ahead and accessed the shfolder unit like so in case anyone else has 
a need to do this before the issue is addressed:

uses
  shfolder
;

// .. etc, etc.

function GetSpecialFolderPath(folder : integer) : string;
const
   SHGFP_TYPE_CURRENT = 0;
var
   path: array [0..MAX_PATH] of char;
begin
   if SUCCEEDED(SHGetFolderPath(0,folder,0,SHGFP_TYPE_CURRENT, at path[0])) then
     Result := path
   else
     Result := '';
end;

procedure SaveMyFile(AStringList: TStringList);
var
   lPath: string;
begin
   lPath := GetSpecialFolderPath(CSIDL_COMMON_DOCUMENTS);
   lPath := lPath + PathDelim + 'AFile.txt'
   AStringList.SaveToFile(lPath);
end;

Of course, in my actual code its IFDEF'd to use GetAppConfigDir when linux/unix 
instead of the above function.

-- 

Warm Regards,

Lee

"When my company started out, we were really, really, really, really small. 
Now...we're just really small."



More information about the Lazarus mailing list