home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / next / programm / 8064 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  2.8 KB

  1. Path: sparky!uunet!psinntp!sugar!tghost!unkaphaed!biff!biff
  2. From: biff@biff.gbdata.com (Dwight Everhart)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: RTFD, copying to Objects and Archiving
  5. Message-ID: <C0o7n2.8Ct@biff.gbdata.com>
  6. Date: Mon, 11 Jan 1993 03:42:37 GMT
  7. References: <1993Jan7.213019.7023@ornl.gov>
  8. Sender: biff@biff.gbdata.com (Dwight Everhart)
  9. Lines: 73
  10.  
  11. In article <1993Jan7.213019.7023@ornl.gov> woo@ornl.gov (John W. Wooten)  
  12. writes:
  13. > I am working on an application where I compose questions
  14. > that will contain rich text (including diagrams).  I have a simple  
  15. > subclass of Object called QuestionObj that I create an instance of for  
  16. > each question and then maintain the questions in a List Object.
  17. > The text is in a text field with id "text".
  18. > I try to do the following:
  19. >     NXStream *buffer;
  20. >     
  21. >     count = [questions count];
  22. >     newQuestion = [[QuestionObj alloc] init];
  23. >     buffer = NXOpenMemory(NULL,0,NX_WRITEONLY);
  24.                                     ^^^^^^^^^^^^
  25. >     [text writeRTFDTo:buffer];
  26. >     [newQuestion setText:buffer];
  27. > Now in the QuestionObj, I have:
  28. > - setText:(NXStream *)str
  29. > {
  30. >     buffer = str;
  31. >     return self;
  32. > }
  33. > - (NXStream *)text
  34. > {
  35. >     return buffer;
  36. > }
  37. > with interface of:
  38. > @interface QuestionObj:Object
  39. > {
  40. >     int num;
  41. >     NXStream *buffer;
  42. > }
  43. > - setNum:(int)val;
  44. > - (int)num;
  45. > - setText:(NXStream *)str;
  46. > - (NXStream *)text;
  47. > Now, first it appears that I'm not getting the Rich Text because I  
  48. > can't get it back out of the object with text method.
  49.  
  50. You're opening the stream as write-only.  Either open it as as read-write, or  
  51. close the stream and have your setText method store the address of the  
  52. buffer, rather than the stream.  To do the latter, after writing the stream,  
  53. use NXGetMemoryBuffer() to get the address of the memory buffer that was  
  54. created.  Use NXClose() (or NXCloseMemory() with the NX_TRUNCATEBUFFER  
  55. option) to close the stream.  Give setText: the address of the buffer.  Then,  
  56. when you want to read from the buffer, you can use NXOpenMemory() with the  
  57. address of the buffer as returned by your text method.
  58.  
  59.  
  60. > Also, if this even works, in the -read -write methods of the
  61. > QuestionObj class, what do I put for the descriptor when I use
  62. > NXWriteTypedStreamToFile ?
  63.  
  64. I don't know if you can archive a NXStream, but, if you use the second option  
  65. I suggested, you can archive the memory buffer with NXWriteArray() with a  
  66. type of "c".
  67.  
  68.  
  69. > I used a * when it was a char * and it worked.
  70.  
  71. The "*" type is meant for strings.  It probably won't work right with memory  
  72. buffers.
  73.  
  74. --
  75. Dwight Everhart          "Technology turned out to be less important than
  76. Houston, Texas            sales and distribution methods ... we consistently
  77. biff@biff.gbdata.com      outsold people who had better technology."
  78. NeXTMail and MIME OK      -- Thomas J. Watson Jr., on the success of IBM
  79.