idptr is a pointer to a variable whose type is "id". If you just declare a variable of this type and don't initialise it, it will point to random memory. When the called routine tries to write to this memory, crashing is indeed the most likely consequence. Try passing the address of a variable of the type "id".
Unfortunately, I'm neither an expert in pointers nor in macOS coding.
According to your suggestions, I have tried the following:
function MacGetFileAttributeHidden(AFileName: string): boolean;
var
ANSFileURL: NSURL;
ANSFile: NSString;
AValue: id;
begin
ANSFile := NSSTR(pchar(AFileName));
ANSFileURL := NSURL.fileURLWithPath(ANSFile);
// AValue := 0; AValue := nil; AValue := NSNumber.alloc.init; AValue := id.init; AValue := id.alloc.init; <- not working
if ANSFileURL.getResourceValue_forKey_error(Pointer(AValue), NSURLIsHiddenKey, nil) then begin // <- exception here
// result := NSNumber(XXX).integerValue = 1;
end else begin
result := false;
end;
ANSFile.release;
end;
When passing Pointer(AValue) it is compiling but throwing an exception at run-time.
I have tried to init AValue using different methods that can be seen above. Unfortunately, none of them is working. The first 2 can be compiled but are throwing an exception at run-time, the others are not possible to be compiled.
I have also tried to declare AValue as NSNumber which is also compiling, but it also results in an exception at run-time.
Any idea what can be done here?