Recent

Author Topic: User gets error when running my app  (Read 2247 times)

MISV

  • Hero Member
  • *****
  • Posts: 792
User gets error when running my app
« on: February 15, 2021, 06:14:43 pm »
Quote
Unable to create file "/Users/*username*/.config/MyApp/reg.xml": Permission denied.

Press OK to ignore and risk data corruption.

Press Abort to kill the program.

But researching right now...
« Last Edit: February 15, 2021, 06:21:18 pm by MISV »

MISV

  • Hero Member
  • *****
  • Posts: 792
Re: User gets error when running my app
« Reply #1 on: February 15, 2021, 06:41:57 pm »
Okay, so somehow this gives an error on the users system,.

If it is a Lazarus error (and not MacOS error) maybe this will solve it:

Code: Pascal  [Select][+][-]
  1.     try
  2.       TmpOpen := TmpReg.OpenKey(FRegPath, True);
  3.     except
  4.       TmpOpen := False;
  5.     end;
  6.  


I will try that and hear if that resolves the error. (My software can function without access to .config / registry)


MISV

  • Hero Member
  • *****
  • Posts: 792
Re: User gets error when running my app
« Reply #2 on: February 15, 2021, 07:32:46 pm »
User used 11.2.1

(Never received this error before. Not sure if this maybe apply generally to Lazarus / Big Sur when using TRegistry)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: User gets error when running my app
« Reply #3 on: February 15, 2021, 08:52:49 pm »
One of the problems with your code is that it tries to store preferences in a hidden folder. According to Apple's guidelines, the settings of an application are to be stored in the Preferences folder. See https://wiki.lazarus.freepascal.org/Locating_macOS_app_support,_preferences_folders for a platform-sensitive method how to get the path to the correct folder.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

MISV

  • Hero Member
  • *****
  • Posts: 792
Re: User gets error when running my app
« Reply #4 on: February 16, 2021, 01:29:58 am »
I believe this problem is caused by TRegistry Lazarus/LCL wrapper on Mac.

https://wiki.freepascal.org/fcl-registry

Quote
example, under non-Windows operating systems it creates the per user XML file (HKEY_CURRENT_USER) reg.xml in the /home/[user]/.config/application_name/ directory

More precisely in xregreg.inc in TRegistry.SysRegCreate > GetAppConfigDir

...

Just submitted it:
https://bugs.freepascal.org/view.php?id=38495
« Last Edit: February 16, 2021, 02:12:01 am by MISV »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: User gets error when running my app
« Reply #5 on: February 16, 2021, 02:02:27 am »
The root cause is GetAppConfigDir - see also https://bugs.freepascal.org/view.php?id=20706

MISV

  • Hero Member
  • *****
  • Posts: 792
Re: User gets error when running my app
« Reply #6 on: February 16, 2021, 08:27:37 am »
I wonder how to best work around this until a solution is found. Fix the source (but have it wiped next time an update is made)

I would prefer to keep using the TRegistry since it is a kinda nice workaround enabling me to keep my code portable.

Just asking in case I am missing an obvious solution :)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: User gets error when running my app
« Reply #7 on: February 16, 2021, 12:40:26 pm »
Use the Core Foundation CFPreferences functions which automatically take care of the preference file and its location.

There is also the higher level Cocoa NSUserDefaults class, but it has had a checkered history of intermittent failures starting with iOS 9 and macOS 10.13 over several years of updates, so is best avoided.

MISV

  • Hero Member
  • *****
  • Posts: 792
Re: User gets error when running my app
« Reply #8 on: February 23, 2021, 11:34:52 am »
Creating (forcedirectories) the directories used by TRegistry seems to work. But I have added some extra checks now so even if everything fails program continues to work

 

TinyPortal © 2005-2018