GetAppConfigDir question lazarus / 34-Windows ---------------------------------------------------------------------- IPguy · 2012-03-18 16:08 I'm using GetAppConfigDir(xx), which returns the following string (on a windows system): xx = False: C:\Users\[username]\AppData\Local\PROGRM1 xx = True: C:\ProgramData\PROGRM1 I would like to store the data in the following location: C:\Users\[username]\AppData\Local\COMPANY1\PROGRM1 C:\ProgramData\COMPANY1\PROGRM1 I can deconstruct and rebuild that string to insert the company name, but I was wondering if there is a trivial way to insert the company name in that string for all target OS'? ---------------------------------------------------------------------- BlueIcaro · 2012-03-18 17:56 I did somethig like. I take the full path, remove the last word, it's easy found it, because is the name of your application. May be something like this: (it's a code wrote on the fly, please check the correct works) Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Dir := GetAppConfigDir(false);Pos := Pos (MyappName,Dir);Dir := Copy (Dir,0,Pos-1);Dir:= Dir+MyCompany+PathDelimiter\MyAppCreateFolder (Dir); /BlueIcaro Then create a folder as you want, and store the that in a variable to use in your program. /BlueIcaro ---------------------------------------------------------------------- Bart · 2012-03-18 21:59 Code: [Select]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; Here's afunction to get the root of GetAppConfigDir, so you can easily add 'MyCompany'MyAppName' without having to define the functions that act as OnGetApplication =Name and OnGetVendorName. Code: [Select]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; Bart ---------------------------------------------------------------------- IPguy · 2012-03-19 00:27 This is what I did prior to reading your responses. Code: [Select] // 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); ---------------------------------------------------------------------- WackaMold · 2022-05-09 16:50 This part:Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function AppName: String; // this callback function signature must match the defaultbegin Result := 'MyAppName';end; begin OnGetVendorName := @VendorName; requires:Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$LongStrings On} // strings are ANSI instead of shortThe clue is in the compiler error on the assignment if strings are left as default / short: Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Error: (4001) Incompatible types:got "
"expected "