[SOLVED] initWithURL() - wrong number of parameters :( lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- trev · 2019-12-31 06:14 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit2; {$mode objfpc}{$H+}{$modeswitch objectivec1}{$linkframework AVFoundation} interface uses  Classes, Dialogs, CocoaAll, MacOSAll; type  AVAudioRecorder = objcclass external(NSObject)  ...  end; var  MyAudioRecorder : AVAudioRecorder = Nil; implementation...procedure RecordAudio(audioFileName : NSString);var  path : NSString;  url : NSURL;  settings: NSDictionary;  err : NSError;begin  ...  MyAudioRecorder := AVAudioRecorder.alloc.initWithURL(url, settings, @err);  Code: [Select]Compile Project, Target: MyApp: Exit code 1, Errors: 2 unit2.pas(50,76) Error: Wrong number of parameters specified for call to "initWithURL" NSBundle.inc(38,14) Error: Found declaration: initWithURL(NSURL):^objc_object; Where am I going wrong? ---------------------------------------------------------------------- skalogryz · 2019-12-31 06:42 try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MyAudioRecorder := AVAudioRecorder(AVAudioRecorder.alloc).initWithURL(url, settings, @err);or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MyAudioRecorder := AVAudioRecorder.alloc.initWithURL_settings_error(url, settings, @err) method alloc() returns id type. FPC compiler allows to call of ANY ObjC declared method to be called for "id" type. initWithURL: exists at NSURLRequest class. And it seems that the compiler is trying to use this particular type (as it only accepts 1 parameter). AVAudioRecorder doesn't have "initWithURL:" instead it has two methods "initWithURL:settings:error:" and "initWithURL:format:error:". Those are typically converted as: initWithURL_settings_error() and initWithURL_format_error() respectivly ---------------------------------------------------------------------- trev · 2019-12-31 14:06 1. Yields: unit1.pas(311,61) Error: Identifier idents no member "initWithURL" 2. Yields: unit1.pas(312,44) Error: Method identifier expected               unit1.pas(312,70) Fatal: Syntax error, ";" expected but "(" found ---------------------------------------------------------------------- skalogryz · 2019-12-31 14:12 then Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MyAudioRecorder := AVAudioRecorder.alloc.initWithURL_settings_error(url, settings, @err);? what's the full declaration of Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AVAudioRecorder = objcclass external(NSObject)  ...end;? ---------------------------------------------------------------------- trev · 2020-01-01 04:11 Quote from: skalogryz on December 31, 2019, 03:12:14 pmthen Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MyAudioRecorder := AVAudioRecorder.alloc.initWithURL_settings_error(url, settings, @err);? As above: unit1.pas(312,44) Error: Method identifier expected                unit1.pas(312,70) Fatal: Syntax error, ";" expected but "(" found Quotewhat's the full declaration of Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AVAudioRecorder = objcclass external(NSObject)  ...end;? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AVAudioRecorder = objcclass external(NSObject)  public    function avrecord: Boolean; message 'record';    function prepareToRecord: Boolean; message 'prepareToRecord';    procedure pause; message 'pause';    procedure stop; message 'stop';    function deleteRecording: Boolean; message 'deleteRecording';    function isRecording: Boolean; message 'isRecording';  end; ---------------------------------------------------------------------- skalogryz · 2020-01-01 20:59 let's add a missing method then Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   AVAudioRecorder = objcclass external(NSObject)  public    function avrecord: Boolean; message 'record';    function prepareToRecord: Boolean; message 'prepareToRecord';    procedure pause; message 'pause';    procedure stop; message 'stop';    function deleteRecording: Boolean; message 'deleteRecording';    function isRecording: Boolean; message 'isRecording';    function initWithURL_settings_error(url: NSURL; settings: NSDictionary; error: Pointer): id; message 'initWithURL:settings:error:';    //function initWithURL_format_error(url: NSURL; format: AVAudioFormat; error: Pointer): id; message 'initWithURL:format:error:';  end;  Notes: * I commented out initWithURL_format_error, because it requires AVAudioFormat to be declared as well. * it's better to have error parameter to be declared as PNSError (where PNSError = ^NSError). But PNSError is not declared in CocoaAll, so we go just by a raw pointer ---------------------------------------------------------------------- trev · 2020-01-02 00:46 Thanks Dmitry - I eventually figured out that I needed to add the missing method in a moment of realising the blinding obvious after you asked for the class methods! I added this method which I found hiding away in /usr/local/share/fpcs rc/fpc-3.3.1/packages/cocoaint/src/avfoundation/AVAudioRecorder.inc: {Edit: I replaced InstanceType with id} Code: [Select]function initWithURL_settings_error (url: NSURL; settings: NSDictionary; outError:   NSErrorPtr):id; message 'initWithURL:settings:error:'; and it compiles ... now I just need to buy a microphone to test whether it will record ---------------------------------------------------------------------- trev · 2020-01-09 01:45 Reporting a happy ending: having now acquired a USB microphone for my Mac mini, I can now report that the code not only compiles but actually works. Full details now in the Wiki at: https://wiki.freepascal.org/macOS_Audio_Recorder