Forum > Cocoa

handler EventKit can't get it to work

(1/2) > >>

BVale:
hi everyone,

here is my code, its just a simple form with a button.
I tried already several things but it just dont work out. The way I want to.
The following code works kinda. the system asks me if I want to access the calendar. But I can't handle the event. 


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode delphi}{$H+}{$modeswitch objectivec1}{$modeswitch cblocks}{$linkframework EventKit}interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  CocoaAll, MacOSAll, EventKit; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    public    end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 }////procedure CompletionHandler(granted: boolean; error: NSError)cdecl;//begin//  if granted then//    ShowMessage('Zugriff gewährt')//  else//    ShowMessage('Zugriff verweigert oder Fehler aufgetreten: ' +//      error.localizedDescription.utf8string);//end; procedure TForm1.Button1Click(Sender: TObject);var  handler: EKEventStoreRequestAccessCompletionHandler;  store: EKEventStore;begin  store := EKEventStore.alloc.init;  store.requestAccessToEntityType_completion(EKEntityTypeEvent, handler); end; end. 

this one crashes
when I press the button



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode delphi}{$H+}{$modeswitch objectivec1}{$modeswitch cblocks}{$linkframework EventKit}interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  CocoaAll, MacOSAll, EventKit; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    public    end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure CompletionHandler(granted: boolean; error: NSError)cdecl;begin  if granted then    ShowMessage('Zugriff gewährt')  else    ShowMessage('Zugriff verweigert oder Fehler aufgetreten: ' +      error.localizedDescription.utf8string);end; procedure TForm1.Button1Click(Sender: TObject);var // handler: EKEventStoreRequestAccessCompletionHandler;  store: EKEventStore;begin  store := EKEventStore.alloc.init;  store.requestAccessToEntityType_completion(EKEntityTypeEvent, @CompletionHandler); end; end.  
does anyone knows how "to handle" this?

Jonas Maebe:
The first example doesn't make any sense. You're not assigning anything handler, so you're passing a random pointer value there. Additionally, the "boolean" parameter of the completion handler needs to be "ObjCBOOL".

The second one won't work because the Cocoa header parser has not been adjusted since FPC got support for C-blocks, so it defines all "block" parameters as a plain pointer.

If you fix the completion handler's booleanm parameter and assign its address to "handler", then I think the first example will work.

BVale:
thank you for the answer.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- unit Unit1; {$mode delphi}{$H+}{$modeswitch objectivec1}{$modeswitch cblocks}{$linkframework EventKit}interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  CocoaAll, MacOSAll, EventKit; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    public    end; var  Form1: TForm1;  implementation {$R *.lfm} { TForm1 } procedure CompletionHandler(granted: ObjCBOOL; error: NSError);begin  if granted then    ShowMessage('Zugriff gewährt')  else    ShowMessage('Zugriff verweigert oder Fehler aufgetreten: ' +      error.localizedDescription.utf8string);end; procedure TForm1.Button1Click(Sender: TObject);var  store: EKEventStore;  myAccessHandler: EKEventStoreRequestAccessCompletionHandler;begin   myAccessHandler:=@CompletionHandler;  store := EKEventStore.alloc.init;  store.requestAccessToEntityType_completion(EKEntityTypeEvent, myAccessHandler); end; end. probably u mean something like this. it won't work either.

all I get is allways this error. like in the picture

its so frustrating... u have no idea how I long I am already trying to get this to work the only chance for me to get no crash is to send the handler to nirvana. maybe u have or someone else has an other idea, or maybe is trying for a second to get this to work too... dont know. 

KodeZwerg:
I have no MacOS but from my Windows experience Handlers or Callbacks must be outside of methods that need them, so I would modify your code into this:
(added OnCreate() event for Form1)

--- Quote from: BVale on February 20, 2024, 12:38:46 am ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode delphi}{$H+}{$modeswitch objectivec1}{$modeswitch cblocks}{$linkframework EventKit}interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  CocoaAll, MacOSAll, EventKit; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure FormCreate(Sender: TObject);      procedure Button1Click(Sender: TObject);  strict private    FHandler: EKEventStoreRequestAccessCompletionHandler;    FStore: EKEventStore;  protected    procedure CompletionHandler(granted: ObjCBOOL; error: NSError);  private  public  end; var  Form1: TForm1;  implementation {$R *.lfm} { TForm1 } procedure TForm1.CompletionHandler(granted: ObjCBOOL; error: NSError);begin  if granted then    ShowMessage('Zugriff gewährt')  else    ShowMessage('Zugriff verweigert oder Fehler aufgetreten: ' +      error.localizedDescription.utf8string);end; procedure TForm1.Button1Click(Sender: TObject);begin  if FHandler = nil then    FHandler := @CompletionHandler;  if FStore = nil then    FStore := EKEventStore.alloc.init;  FStore.requestAccessToEntityType_completion(EKEntityTypeEvent, FHandler);end; procedure TForm1.FormCreate(Sender: TObject);  begin  FHandler := nil;  FStore := nil;end; end.
--- End quote ---
Additional, set in line "if granted then" a breakpoint, run app, do something that the event has a chance to get fired, will it stop in the CompletionHandler?

BVale:
hi kodezwerg, that don't work either.

Navigation

[0] Message Index

[#] Next page

Go to full version