Re: Controls, stringValue, custom NSFormatter and error pointing to 0
Re: Controls, stringValue, custom NSFormatter and error pointing to 0
- Subject: Re: Controls, stringValue, custom NSFormatter and error pointing to 0
- From: Fritz Anderson <email@hidden>
- Date: Fri, 21 Nov 2003 16:44:55 -0600
On 19 Nov 2003, at 8:04 PM, Peter Teeson wrote:
MacOSX 10.2.6 and December 2002 DevTools with August 2003 update.
I have a very simple Cocoa Document app (used basically as a learning
project).
It has
...
[In an NSFormatter subclass:]
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string
errorDescription:(NSString**)error {
if (([string length] == 0) || ([string length] == 17)) {
*object = string;
return YES;
} else if ([string length] < 17) {
if (0 != error) { // kludge because when called from stringValue we
find that error is set to 0
*error = NSLocalizedString(@"MAC address is too short.", @"Presented
when MAC address is too short");
}
return NO;
} else { // this will never be reached because the formatter makes
sure it's never too long
*error = NSLocalizedString(@"MAC address is too long.",
@"Presented when MAC address is too long");
return NO;
}
}
...
The problem: is that this line of code in that action method
tempDelimitedString =[inputMACaddress stringValue];
of the button invokes the formatters' getObjectValue method (as per
the documentation of stringValue) but the value of error is zero which
of course SIG's BAD_ACCESS (or however it's spelt).
Why is that?
All other invocations of getObjectValue that I have traced so far
provide me with a non-zero value for error.
The documentation for getObjectValue:forString:errorDescription: has
always said that the pointer passed in for the error description could
be NULL, in which case the caller is not interested in getting the
error description. You're supposed to check that, and if it is NULL,
don't attempt to set the description; the example code in the
documentation for the method demonstrates this.
-- F
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.