function VendorName: String;
begin
Result := 'MyCompany';
end;
function AppName: String;
begin
Result:= 'MyAppName';
end;
....
begin
...
OnGetVendorName := @VendorName;
OnGetApplicationName := @AppName;
Dir := GetAppConfigDir(false);
//Dir should be something like: C:\Users\[username]\AppData\Local\MyCompany\MyAppName
end;
Take a look at the code for GetAppConfigDir() function to seehow it works:
[code]
Function GetAppConfigDir(Global : Boolean) : String;
begin
...
If (Result<>'') then
begin
if VendorName<>'' then
Result:=IncludeTrailingPathDelimiter(Result+VendorName);
Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
end
...
end;
.....
Function VendorName : String;
begin
If Assigned(OnGetVendorName) then
Result:=OnGetVendorName()
else
Result:='';
end;
Function ApplicationName : String;
begin
If Assigned(OnGetApplicationName) then
Result:=OnGetApplicationName()
else
Result:=ChangeFileExt(ExtractFileName(Paramstr(0)),'');
end;
function GetAppConfigRoot(const Global: Boolean): String;
var
OldGetAppName: TGetAppNameEvent;
OldGetVendor: TGetVendorNameEvent;
begin
OldGetAppName := OnGetApplicationName;
OnGetApplicationName := @GetAppName;
OldGetVendor := OnGetVendorName;
OnGetVendorName := @GetVendor;
try
Result := GetAppConfigDir(Global);
finally
OnGetApplicationName := OldGetAppName;
OnGetVendorName := OldGetVendor;
end;
end;
// gets the name of a dir in which the app should store its conf files on the current OS.
// Also, see if the directory exists; if not, create it.
// C:\Users\[UserName]\AppData\Local\Company\Project1\
CfgDir := GetAppConfigDir(False);
// Now, replace project name with Company name & verify it exists
CfgDir := StringReplace(CfgDir, 'Project1', 'Company',[rfReplaceAll]);
if not DirectoryExists(CfgDir)
then CreateDir(CfgDir);
// Now, append project name & verify it exists
CfgDir := CfgDir + 'Project'+PathDelim;
if not DirectoryExists(CfgDir)
then CreateDir(CfgDir);