Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Is Objective-C wrapper "ObjectForKey" broken?



Permlink Replies: 1 - Last Post: Jan 23, 2018 3:34 AM Last Post By: Hans Jakobsen
Hans Jakobsen

Posts: 103
Registered: 9/10/01
Is Objective-C wrapper "ObjectForKey" broken?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 3:23 AM
I was trying to get the Country code on Mac, but get an AV in "objectForKey":

class function osxNSLocale.currentLocale_CountryCode: string;
var lNSLocale: NSLocale;
    lPointer: Pointer;
begin
  lNSLocale := TNSLocale.Wrap(TNSLocale.OCClass.currentLocale);
  lPointer := lNSLocale.objectForKey(NSLocaleCountryCode); //<- AV here
  result := NSStrToStr(TNSString.Wrap(lPointer) );
end;

lNSLocal is not nil and the NSLocaleCountryCode returns a valid key as NSString.

In my search for a solution I found my own question on Stack Overflow where I also get an AV in "objectForKey", just in another context:
[https://stackoverflow.com/questions/44239569]

I wonder if anyone have been able to use "objectForKey" without errors?
Am I doing something wrong, or is this a bug in Delphi?

I am on Tokyo 10.2.1 / macOS 10.12.6
Hans Jakobsen

Posts: 103
Registered: 9/10/01
Re: Is Objective-C wrapper "ObjectForKey" broken?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 3:34 AM   in response to: Hans Jakobsen in response to: Hans Jakobsen
Hans Jakobsen wrote:
Am I doing something wrong, or is this a bug in Delphi?

Yes, I was doing something wrong (and I wish I could delete this thread again, but that does not seem to be possible?):

The solution was to use ILocalObject:

lNSLocale.objectForKey((NSLocaleCountryCode as ILocalObject).GetObjectID)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02