Article View: comp.sys.next.programmer
Article #2292Re: RTFD, copying to Objects and Archiving
From: Dwight Everhart
Date: Mon, 11 Jan 1993 03:42
Date: Mon, 11 Jan 1993 03:42
73 lines
2975 bytes
2975 bytes
In article <1993Jan7.213019.7023@ornl.gov> woo@ornl.gov (John W. Wooten)
writes:
> I am working on an application where I compose questions
> that will contain rich text (including diagrams). I have a simple
> subclass of Object called QuestionObj that I create an instance of for
> each question and then maintain the questions in a List Object.
>
> The text is in a text field with id "text".
>
> I try to do the following:
> NXStream *buffer;
>
> count = [questions count];
> newQuestion = [[QuestionObj alloc] init];
> buffer = NXOpenMemory(NULL,0,NX_WRITEONLY);
^^^^^^^^^^^^
> [text writeRTFDTo:buffer];
> [newQuestion setText:buffer];
>
> Now in the QuestionObj, I have:
> - setText:(NXStream *)str
> {
> buffer = str;
> return self;
> }
> - (NXStream *)text
> {
> return buffer;
> }
> with interface of:
> @interface QuestionObj:Object
> {
> int num;
> NXStream *buffer;
> }
>
> - setNum:(int)val;
> - (int)num;
> - setText:(NXStream *)str;
> - (NXStream *)text;
>
> Now, first it appears that I'm not getting the Rich Text because I
> can't get it back out of the object with text method.
You're opening the stream as write-only. Either open it as as read-write, or
close the stream and have your setText method store the address of the
buffer, rather than the stream. To do the latter, after writing the stream,
use NXGetMemoryBuffer() to get the address of the memory buffer that was
created. Use NXClose() (or NXCloseMemory() with the NX_TRUNCATEBUFFER
option) to close the stream. Give setText: the address of the buffer. Then,
when you want to read from the buffer, you can use NXOpenMemory() with the
address of the buffer as returned by your text method.
> Also, if this even works, in the -read -write methods of the
> QuestionObj class, what do I put for the descriptor when I use
> NXWriteTypedStreamToFile ?
I don't know if you can archive a NXStream, but, if you use the second option
I suggested, you can archive the memory buffer with NXWriteArray() with a
type of "c".
> I used a * when it was a char * and it worked.
The "*" type is meant for strings. It probably won't work right with memory
buffers.
--
Dwight Everhart "Technology turned out to be less important than
Houston, Texas sales and distribution methods ... we consistently
biff@biff.gbdata.com outsold people who had better technology."
NeXTMail and MIME OK -- Thomas J. Watson Jr., on the success of IBM
Technical Details
Message-ID:
<C0o7n2.8Ct@biff.gbdata.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!psinntp!sugar!tghost!unkaphaed!biff!biffReferences:
<1993Jan7.213019.7023@ornl.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!sugar!tghost!unkaphaed!biff!biff From: biff@biff.gbdata.com (Dwight Everhart) Newsgroups: comp.sys.next.programmer Subject: Re: RTFD, copying to Objects and Archiving Message-ID: <C0o7n2.8Ct@biff.gbdata.com> Date: Mon, 11 Jan 1993 03:42:37 GMT References: <1993Jan7.213019.7023@ornl.gov> Sender: biff@biff.gbdata.com (Dwight Everhart) Lines: 73