Problems with the SpellChecker Sample code and more...
Problems with the SpellChecker Sample code and more...
- Subject: Problems with the SpellChecker Sample code and more...
- From: Andrew Taylor <email@hidden>
- Date: Thu, 7 Nov 2002 17:12:45 -0500
Hello,
I would like to use several Cocoa services from a Carbon CFM
application (I do have some Mach-o frameworks that I access from that
application, so I can access from those frameworks as well if
necessary).
I am using CodeWarrior 8.2 on Mac OS X 10.2.1 on a Powerbook G4
500mhz, 512MB RAM and ProjectBuilder 2.0.1.
I went to the Sample code and pulled down the SpellChecker sample
application, read up on connecting Carbon to Cocoa from the Apple Web
site pages, read the O'Reilly Cocoa books and then tried to use the
sample code.
First - The sample code as is, building with Project Builder
generates warnings about memory leaks in the Project Builder
debugger. Lots of messages like the following message are generated:
2002-11-06 15:16:43.816 SpellingChecker[1197] ***
_NSAutoreleaseNoPool(): Object 0x114c5c0 of class
NSCarbonWindowContentView autoreleased with no pool in place - just
leaking
How do I stop that?
Second: the functionality that I really need right now is the ability
to open and read a RTF file and get the text out of it - no
formatting information, just the text.
So I wrote the following function but it always returns nil when
attempting to read the rtf file from the function readRTFDFromFile
because that function always returns false.
Originally I just created a NSText object and tried to read the file
with that - it failed - the readRTFDFromFile returns false. So then I
created a window and a NSTextView simply because I don't know Cocoa
and I assumed that I was missing something crucial. I don't ever want
to display this text, even in my application, I need to do some
analysis on it.
(And I know that the rtf file that I am attempting to read is fine
because TextEdit created it and can still open it.)
I also took the guts of this function, copied it into the -
(void)windowControllerDidLoadNib:(NSWindowController *) aController
method created by the Cocoa Document application that Project Builder
supplies and I still get the same error. (That is when I stopped
using the path passed in and hard coded it with the CFString). So I
believe I am missing something in this code or it is just completely
wrong.
Help please!
Thanks.
CFStringRef GetRTFText( CFStringRef path )
{
NSString* results = nil;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
CFStringRef thePath =
CFStringCreateWithFormat(nil,nil,CFSTR("Jaguar:Users:andrewtaylor:Desktop:rtf
file.rtf"));
CFShow(thePath);
NSRect wFrame = NSMakeRect(0, 0, 100, 100);
NSWindow* aWindow = [[NSWindow alloc]
initWithContentRect:(NSRect)wFrame styleMask:NSTitledWindowMask
backing:(NSBackingStoreType)NSBackingStoreBuffered defer:(BOOL)YES];
/* determine the size for the NSTextView */
NSRect cFrame =[[aWindow contentView] frame];
/* create the NSTextView and add it to the window */
NSTextView *theTextView = [[NSTextView alloc] initWithFrame:cFrame];
[aWindow setContentView:theTextView];
CFShow(path);
// NSText* theText = [[NSText alloc] init];
CFShow(theTextView);
if ( [theTextView readRTFDFromFile:(NSString *)thePath ] ) {
results = [[theTextView string] retain];
CFShow(results);
}
else
CFShow(CFSTR("readRTFDFromFile failed to read the file.\n"));
[theTextView release];
[pool release];
return (CFStringRef)results;
}
_______________________________________________
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.