Recent

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

MISV

  • Hero Member
  • *****
  • Posts: 722
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: 722
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: 722
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: 1169
    • 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.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

MISV

  • Hero Member
  • *****
  • Posts: 722
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: 1272
  • 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
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64455 3.3.1 r48688  macOS 11.2 aarch64 Xcode 12.4
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

MISV

  • Hero Member
  • *****
  • Posts: 722
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: 1272
  • 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.
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64455 3.3.1 r48688  macOS 11.2 aarch64 Xcode 12.4
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

MISV

  • Hero Member
  • *****
  • Posts: 722
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