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