String Issues

0 views
Skip to first unread message

dbertouille

unread,
Jan 16, 2008, 12:57:10 PM1/16/08
to cocoa-sharp-dev
I can set string values in text fields, views, and data structures
fine but as soon as i try to retrieve a value i get the following
error. (Im running in the terminal so thats where it appers)

*** -[NCSFString cStringUsingEncoding:]: selector not recognized.

Any ideas?

dbertouille

unread,
Jan 17, 2008, 4:10:46 PM1/17/08
to cocoa-sharp-dev
Some example code.

[Connect]
public Cocoa.TextField textField1;
.
.
.
.
public void Test()
{
string s;
s="Test";
textField1.Value=s; ///All work fine up to here
s=textField1.Value; //This is what line generates the error
}

Chuck Esterbrook

unread,
Jan 17, 2008, 4:48:32 PM1/17/08
to cocoa-s...@googlegroups.com
Even Objective-C people have gotten this, although I don't see
anything wrong with your code. The NSTextField should -retain the
string. Is there something about the Cocoa# implementation that might
cause it to be freed?

See: http://lists.apple.com/archives/cocoa-dev/2001/May/msg00865.html
where it says "The error you're getting is the classic
object-gets-freed-and-the-memory-is-replaced-by-some-other-object
problem..."

Leauki

unread,
Jan 17, 2008, 5:01:12 PM1/17/08
to cocoa-sharp-dev
Hi,

This doesn't happen to me.

Can you post an entire source file?

I just modified a program to do the below thing with a string s and a
textfield and it works.

dbertouille

unread,
Jan 17, 2008, 5:19:39 PM1/17/08
to cocoa-sharp-dev
Alright, I think the rest is good. Would the XCode version have
anything to do with it, i only have 1.5. Or even the cocoa framework
(if it has changed, not sure which i got)

Here is the ApplicationController.cs

using System;
using Cocoa;

namespace TestApp
{
[Register("ApplicationController")]
class ApplicationController : Cocoa.Object
{
[Connect]
public Cocoa.Window mainWindow;

[Connect]
public Cocoa.TextField textField1;


public ApplicationController(System.IntPtr a) : base(a)
{
}

//Form.Load Event
[Export("applicationWillFinishLaunching:")]
public void FinishLoading(Cocoa.Notification notification)
{
Console.WriteLine("Form Loaded");
}

[Export("addButtonClick:")]
public void addButtonClick(Cocoa.Object sender)
{
Test();
}

public void Test()
{
string s;
s="Test";
textField1.Value=s;
s=textField1.Value;

}
}
}



Message has been deleted

dbertouille

unread,
Jan 21, 2008, 4:05:35 PM1/21/08
to cocoa-sharp-dev
Alright this seems to work if i edit the Cocoa.String.ToString fuction
to call cString instead of cStringUsingEncoding. Apparently my
library does not have that method. Will this be a problem for other
places as well?
Reply all
Reply to author
Forward
0 new messages