Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by John W. Wooten
Thu, 07 Jan 1993 21:30
RTFD, copying to Objects and Archiving
Author: John W. Wooten
Date: Thu, 07 Jan 1993 21:30
Date: Thu, 07 Jan 1993 21:30
55 lines
1770 bytes
1770 bytes
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.
I know most of this works with ascii text (I tried this all out using
char *buffer;
first)
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 used a * when it was a char * and it worked.
What do I put for a typed stream?
- - - - - - - - -
J. W. Wooten
Re: RTFD, copying to Objects and Archiving
Author: 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
Re: RTFD, copying to Objects and Archiving
Author: John Jay Feiler
Date: Mon, 11 Jan 1993 06:24
Date: Mon, 11 Jan 1993 06:24
68 lines
2295 bytes
2295 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.
>
> I know most of this works with ascii text (I tried this all out using
> char *buffer;
> first)
>
> 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 used a * when it was a char * and it worked.
>
> What do I put for a typed stream?
>
>
> - - - - - - - - -
> J. W. Wooten
Just a guess, but are you doing a NXSeek(buffer, 0L, NX_FROMSTART) before
trying to access data in the stream?
John
--
John Feiler jjfeiler@relief.com
4926 152nd St. SW NeXTmail Welcome!!!
Edmonds, WA 98026-3344 Independent NeXTSTEP Developer
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads