home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8492 < prev    next >
Encoding:
Text File  |  1993-01-24  |  2.6 KB  |  55 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!utcsri!torn!news.ccs.queensu.ca!slip206.telnet1.QueensU.CA!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Loading from a Stream
  5. Message-ID: <dmurdoch.340.727893936@mast.queensu.ca>
  6. Lines: 43
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <35199@adm.brl.mil>
  10. Date: Sun, 24 Jan 1993 16:45:37 GMT
  11.  
  12. In article <35199@adm.brl.mil> astoner@mcis.messiah.edu writes:
  13. >  This is a question for all you stream experts out there.  I am working
  14. >on a portfolio tracking program that involves four different types of
  15. >transactions (Stock, Bond, Options, Future).  Sounds like these four
  16. >types of transaction should be a descendant of a Transaction type, which
  17. >is the descendant of TObject so it can be streamed.  All of the general
  18. >data is stored in the Transaction type which also defines several virtual
  19. >methods which are overridden in the specific types.  The data unique to
  20. >each specific type of transaction is of course stored in them.
  21. >  Right now I have the specific types LOAD(ing) and STORE(ing) all of the
  22. >fields.  Is it possible to call the ancestors LOAD method to LOAD that part
  23. >of the data then continue with the specific data?
  24.  
  25. Yes, you can indeed do that.
  26.  
  27. >  The more important problem that I am having is that when I store something
  28. >on the stream I am having problems reading it back.  I can't seem to get
  29. >it to call the proper LOAD method for the specific types.  If I have a
  30. >variable that is a pointer to the Transaction type isn't it supposed to
  31. >call the methods of the descendants, or something like that?
  32.  
  33. Load won't.  The way the polymorphism works on streams is that the 
  34. TStream.Get method first reads an ID word from the stream, then looks it up 
  35. in a table and calls the appropriate Load method.  This depends on you
  36. having put the objects on the stream using TStream.Put, and having 
  37. registered the types and the ID codes.
  38.  
  39. You can do it all without using Get or Put or registration, but there isn't 
  40. much to be gained.  Essentially what you'd do is to duplicate the operations
  41. described above.
  42.  
  43. >  One of the methods defined in the base Transaction type is an ID method
  44. >that is to return the type of transaction that is stored in the base
  45. >transaction type.  When I load the data back from the stream shouldn't I
  46. >be able to call this ID method to determine how to type cast the loaded
  47. >data?
  48.  
  49. That's probably a bad way to do it.  The problem is that the call to 
  50. Transaction.Load allocates only the memory for a Transaction; if your 
  51. descendants add fields, then there'll be nowhere to put them.
  52.  
  53. Duncan Murdoch
  54. dmurdoch@mast.queensu.ca
  55.