Hello guys

Hello guys,

I am playing with ObjectiveC and Delphi, it is very fun however I am stuck with a problem.

In the ObjectiveC side I have:
NSError *error = nil;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {}

I have already wrapped this method in the following way:
LAContext = interface(NSObject)
['{8F6B7D53-83A8-43D3-B6C2-116068C382CE}']
function canEvaluatePolicy(policy: LAPolicy; error: PNSError): Boolean; cdecl;
end;

PNSError = ^NSError;

I am getting Access Violation all the time I try to extract the content of this pointer.
My code is:
var
Context: LAContext;
canEvaluate: Boolean;
Err: PNSError;
ErrorMessage: string;
begin
Context := TLAContext.Create;

canEvaluate := Context.canEvaluatePolicy(LAPolicyDeviceOwnerAuthenticationWithBiometrics, Err);

ErrorMessage := NSStrToStr(TNSError.Wrap(Err).localizedDescription);

With this code I am not able to see the content of "Err" :(
I don't know how to create the PNSPointer object and pass to the function.
Can you help me? What I am doing wrong?

Thanks in advance :D

Comments

  1. Err isn't the Objective-C object ID, it's a pointer to the ID. As such, you need to dereference the pointer (checking it isn't nil first), and wrap that.

    As a side note, the use of PNSError is fundamentaly wrong in my eyes, and I wish Embarcadero never started doing it (must have been around XE6, I can't remember exactly). NSError on the Delphi side isn't the real NSError, but a wrapper, and a pointer to a wrapper for the real NSError is not the same thing at all as a pointer to a real NSError reference.

    ReplyDelete
  2. Judging by the example on this page:

    tmssoftware.com - TMS Software

    (expand the 3rd item)

    Because they're using PPointer (a pointer to a pointer), you need to pass the address of Err, i.e. use @Err in the call to canEvaluatePolicy.

    ReplyDelete
  3. Chris Rolliston I didn't see your answer until now, and notice it was posted 4 hrs before mine. $%#@ G+ ;-)

    ReplyDelete

Post a Comment