Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Problem with ObjcPtr#assign

Help
Kittekat
2010-02-13
2013-05-08
  • Kittekat
    Kittekat
    2010-02-13

    I try to return an errorpointer as shown in http://rubycocoa.sourceforge.net/AssignValueToPointerArgument.
    this is my test code.:
    require 'osx/cocoa'
    class Contr < OSX::NSObject
      include OSX
      ib_action :trigger

      def generateError(errorPtr)
        error = NSError.alloc.initWithDomain_code_userInfo(
                      NSString.stringWithString('myDomainError'),
                      4711, nil)
        errorPtr.assign(error)
      end # generate_error
     
      def trigger(sender)
        errorPtr = ObjcPtr.new(1)
        generateError(errorPtr)
        a = NSAlert.alertWithError(errorPtr)
        a.runModal
      end # trigger
    end # Contr

    Anyway, I get a runtime error when using "errorPtr.assign(error)":
    2010-02-13 19:59:49.816 ErrorTest Contr#trigger: TypeError: can't convert OSX::NSError into Integer

    Looks like i have to somehow tell the instance, what object I want to assign, perhaps when generating it.

    But I did not find any documentation about ObjcPtr.new. It requires one parameter. I tried do find an indication in the objective-C code of this class, but I was not successful.

    Please give me a hint.
    Best regards
    Kittekat