Hi!
I found the code att the bottom of this post somewhere in this forum. I made an interface with a textField, a textView and a button. It's an example on how to use threads.
When I write in the textField and press a OK button my text should appear in the textView 60 times without locking up the interface.
But all it does is crash all the time with this message:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = blue>2002</font>-<font color = blue>04</font>-<font color = blue>10</font> <font color = blue>00</font>:<font color = blue>07</font>:<font color = blue>29.925</font> ThreadTest[<font color = blue>1872</font>] *** Assertion failure in -[NSMutableRLEArray objectAtIndex:effectiveRange:], String.subproj/NSAttributedString.m:<font color = blue>923</font>
<font color = blue>2002</font>-<font color = blue>04</font>-<font color = blue>10</font> <font color = blue>00</font>:<font color = blue>07</font>:<font color = blue>29.925</font> ThreadTest[<font color = blue>1872</font>] An uncaught exception was raised
<font color = blue>2002</font>-<font color = blue>04</font>-<font color = blue>10</font> <font color = blue>00</font>:<font color = blue>07</font>:<font color = blue>29.926</font> ThreadTest[<font color = blue>1872</font>] Access invalid attribute location <font color = blue>0</font> (length <font color = blue>0</font>)
<font color = blue>2002</font>-<font color = blue>04</font>-<font color = blue>10</font> <font color = blue>00</font>:<font color = blue>07</font>:<font color = blue>29.926</font> ThreadTest[<font color = blue>1872</font>] *** Uncaught exception: <NSInternalInconsistencyException> ; Access invalid attribute location <font color = blue>0</font> (length <font color = blue>0</font>)
</font>[/code]
I'm quite a newbie to this Cocoa thing, so any help would be nice...
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#import <font color = red>"myClass.h"</font>
@implementation myClass
- (IBAction)OKBUTTON

id)sender;
{
[NSApplication detachDrawingThread: @selector (doSomething

toTarget:self withObject:[[input stringValue] retain]];
}
- (void)doSomething

NSString *)inputString
{
NSAutoreleasePool* pool;
NSRange range;
int length, i;
range.location = <font color = blue>0</font>;
range.length = [inputString length];
for(i = <font color = blue>0</font>;i < <font color = blue>60</font>; i++)
{
pool = [[NSAutoreleasePool alloc] init];
[output replaceCharactersInRange:range withString:inputString];
range.location += length;
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:<font color = blue>1</font>]];
[pool release];
}
[inputString release];
}
@end
</font>[/code]
Here's myClass.h:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#import <Cocoa/Cocoa.h>
@interface myClass : NSView
{
IBOutlet id input;
IBOutlet id output;
}
- (IBAction)OKBUTTON

id)sender;
- (void)doSomething

NSString *)inputString;
@end
</font>[/code]
[ 04-09-2002: Message edited by: thanatos ]