Hello,

It is better to use accessors, as the support for KVC is easier:

private int myField;

public int MyField {
  [ObjectiveCMessage("myField")]
  get {
    return this.myField;
  }
  [ObjectiveCMessage("setMyField:")]
  set {
    this.WillChangeValueForKey("myField");
    this.myField = value;
    this.DidChangeValueForKey("myField");
  }
}

If you use this approach, wherever the changes are made (from
ObjectiveC or from .NET), the bindings will work. I suggest you to
take a look at the CGImageRotation sample code, as it heavily uses
bindings on primitive types.

Regards, Laurent Etiemble.

PS: I think there is a bug with the ivar that are primitive types. The
API is very obscure about the way the storage is done, and my unit
tests are against the official documentation, but the ObjectiveC
runtime is with me. But I have surely missed something...

2009/3/25 Mario De Clippeleir <mari...@sydec.be>
>
> Hi,
>
>
>
> I use just a field, which is an “int iValue”.
>
> How should I use the accessors for my purpose ?
>
>
>
> There is nothing in the class code related to the bindings, other then I am 
> initializing the iValue by using SetValueForKey(initValue,”iValue”), which 
> does the trick…
>
>
>
> Br,
>
>
>
> Mario
>
>
>
> From: laurent.etiem...@gmail.com [mailto:laurent.etiem...@gmail.com] On 
> Behalf Of Laurent Etiemble
> Sent: dinsdag 24 maart 2009 22:08
> To: users@lists.monobjc.net
> Subject: Re: [us...@lists.monobjc.net] PtrToStructure error
>
>
>
> Hello,
>
> Do you use KVC with fields (i.e. using bindings directly with class field) ?
> If yes, have you tried bindings with accessors instead ?
> Can you post the classes code (at least the part related to the bindings) ?
>
> Regards, Laurent Etiemble.
>
> 2009/3/24 Mario De Clippeleir <mari...@sydec.be>
>
> Hi,
>
>
>
> I have a textfield, a slider and a checkbox. The textfield and slider are 
> connected through bindings using Model Key Path. That works fine, but when I 
> change the value (other than the initial one)and then click the checkbox I 
> get the following error :
>
> Unhandled Exception: System.NullReferenceException: Object reference not set 
> to an instance of an object
>
>   at (wrapper unknown) int:PtrToStructure (intptr,object)
>
>   at (wrapper managed-to-native) 
> System.Runtime.InteropServices.Marshal:PtrToStructure(intptr,System.Type)
>
> at 
> Monobjc.Dynamic.Proxies.Test.Mac.ApplicationController.ImportMembers(Test.Mac.ApplicationController
>  instance) [0x00000]
>
>   at 
> Monobjc.Dynamic.Proxies.Test.Mac.ApplicationController.CheckClicked(IntPtr 
> receiver, IntPtr selector) [0x00000]
>
>   at (wrapper 
> native-to-managed)Monobjc.Dynamic.Proxies.Test.Mac.ApplicationController:CheckClicked(intptr,intptr)
>
>   at (wrapper managed-to-native) 503BA7BB:pinvoke (intptr,intptr)
>
>   at 503BA7BB.objc_msgSend (IntPtr receiver, IntPtr selector, System.Object[] 
> parameters) [0x00000]
>
>   at 
> Monobjc.Bridge.Generators.DynamicMessagingGenerator.SendMessage(System.String 
> message, IntPtr receiver, IntPtr selector, System.Object[] parameters) 
> 0x00000]
>
>   at Monobjc.ObjectiveCRuntime.SendMessage (IManagedWrapper receiver, 
> System.String selector, System.Object[] parameters) [0x00000]
>
>   at Monobjc.Cocoa.NSApplication.Run () [0x00000]
>
>   at Monobjc.Cocoa.NSApplication.RunApplication () [0x00000]
>
>   at Test.Mac.Program.Main (System.String[] args) [0x00000]
>
>
>
> What is causing this problem ?
>
>
>
> Br,
>
>
>
> Mario
>
>

Reply via email to