Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Retrieving path to Application Support


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Aug 3, 2017 3:10 PM Last Post By: Ivan Johansen Threads: [ Previous | Next ]
Ivan Johansen

Posts: 27
Registered: 3/17/00
Retrieving path to Application Support  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 3, 2017 1:34 AM
I am trying to retrieve the path to the Application Support foder for the current user on MacOS with C++ Builder XE6.

I have tried porting the code from the TPath.InternalGetMACOSPath Delphi function in System.IOUtils.pas:
String GetProgramDataPath()
{
  NSFileManager *FileManager = TNSFileManager::Wrap(TNSFileManager::OCClass->defaultManager());
  NSURL *Url = FileManager->URLForDirectory(NSApplicationSupportDirectory, NSUserDomainMask, NULL, true, NULL);
  if(Url != NULL)
    return UTF8ToString(Url->path()->UTF8String());
  return "";
}

I am using NSApplicationSupportDirectory as SearchedPath and NSUserDomainMask as SearchMask.

Unfortunately the call to URLForDirectory() crashes the application with a SIGSEGV and I cannot figure out why.
Any help resolving this is appreciated.

Ivan Johansen
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Retrieving path to Application Support  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 3, 2017 10:32 AM   in response to: Ivan Johansen in response to: Ivan Johansen
Ivan Johansen wrote:

NSFileManager *FileManager =
TNSFileManager::Wrap(TNSFileManager::OCClass->defaultManager());
NSURL *Url =
FileManager->URLForDirectory(NSApplicationSupportDirectory,
NSUserDomainMask, NULL, true, NULL);

Don't use raw object pointers for iOS types, use the RTL's Delphi-style
interface wrappers instead, eg:

String GetProgramDataPath()
{
    _di_NSFileManager FileManager =
TNSFileManager::Wrap(TNSFileManager::OCClass->defaultManager());
    if (FileManager)
    {
        _di_NSURL Url =
FileManager->URLForDirectory(NSApplicationSupportDirectory,
NSUserDomainMask, NULL, true, NULL);
        if (Url)
            return NSStrToStr(Url->path());
    }
    return String();
}


--
Remy Lebeau (TeamB)
Ivan Johansen

Posts: 27
Registered: 3/17/00
Re: Retrieving path to Application Support  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 3, 2017 3:10 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Don't use raw object pointers for iOS types, use the RTL's Delphi-style
interface wrappers instead, eg:

Thanks. That was exactly what I was missing. I now realise that the MacOS functions actually returned a smart pointer, which was implicit converted to a real pointer and then freed. Storing the smart pointer as you suggested of course solved it. I hate these implicit conversion to pointers. They always trick me.

Ivan Johansen
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02