Board index » delphi » Problem with Stream.Get in BPW

Problem with Stream.Get in BPW

The code PSomeObject := SomeStream.Get always gives me a type mismatch

despite PSomeobject being descended from TObject.  What am I doing
wrong?
--------------------------------------------------------------
Alan Rubin      aru...@cix.compulink.co.uk
                a...@rubin.compulink.co.uk
                http://www.compulink.co.uk/~rubin/welcome.html
---------------------------------------------------------------

 

Re:Problem with Stream.Get in BPW


Quote
dmurd...@mast.queensu.ca (Duncan Murdoch) wrote:
>On Fri, 17 Nov 1995 00:17:21 GMT, a...@rubin.compulink.co.uk (Alan
>Rubin) wrote:

>>The code PSomeObject := SomeStream.Get always gives me a type mismatch

>>despite PSomeobject being descended from TObject.  What am I doing
>>wrong?

>Get is declared to return a value of type PObject; that's not
>assignment compatible with a pointer to a descendant type.  (If you
>made the assignment and it turned out that the object wasn't a
>TSomeobject, you'd get chaos.)  If you happen to know the type of the
>thing that you're getting is a TSomeobject, then use a typecast.  If
>you're not sure what type will show up, assign it to a PObject
>variable.

Thanks.  I thought that the manual as saying that Get was compatible
with pointers to descendants.

Do you think this stream business is worthwile for random access
files?
--------------------------------------------------------------
Alan Rubin      aru...@cix.compulink.co.uk
                a...@rubin.compulink.co.uk
                http://www.compulink.co.uk/~rubin/welcome.html
---------------------------------------------------------------

Re:Problem with Stream.Get in BPW


On Wed, 22 Nov 1995 15:26:32, b...@winston.riccarton.school.nz (Will

Quote
Bryant) wrote:
>Streams are really only good if everything else is OOP (using TCollections
>etc.), in which case they're very useful, otherwise they're a waste of time.

This is nonsense.  Streams are a good general purpose interface to
binary files.  Any place you might be tempted to use an untyped file
or a file of byte, a stream is preferable:

 - Untyped files aren't buffered.  If buffering would help your
application, you can use a buffered stream, or copy the whole file
into EMS for more speed.

 - Untyped files lead to a number of FAQ-style errors, because of
their bad design.  How many times have you seen the question about
reads and filesizes not working, because the user didn't know that
untyped file default to a record size of 128 bytes?  How many programs
using untyped files are unable to read a read-only file, because by
default reset() tries to open them in read/write mode?

There are two main problems with streams:

 - The documentation on them is wildly misleading.  It makes it look
as though Put and Get are important methods; in actual fact, they're
very specialized methods, and I hardly ever use them.  Use the general
purpose Read and Write methods instead.

 - Borland really mangled the design of them in Delphi, so they are
something of a dead end.  Delphi still has those untyped files, still
with all the ancient problems, but it has come up with a more or less
undocumented different implementation of Streams.  

Duncan Murdoch

Re:Problem with Stream.Get in BPW


Quote

>>Get is declared to return a value of type PObject; that's not
>>assignment compatible with a pointer to a descendant type.  (If you
>>made the assignment and it turned out that the object wasn't a
>>TSomeobject, you'd get chaos.)  If you happen to know the type of the
>>thing that you're getting is a TSomeobject, then use a typecast.  If
>>you're not sure what type will show up, assign it to a PObject
>>variable.

I was under the impression that you were supposed to register new classes so
that it loads them in properly.  Or is that just for PCollections?

Quote
>Thanks.  I thought that the manual as saying that Get was compatible
>with pointers to descendants.
>Do you think this stream business is worthwile for random access
>files?

Streams are really only good if everything else is OOP (using TCollections
etc.), in which case they're very useful, otherwise they're a waste of time.
Will Bryant
brya...@winston.riccarton.school.nz
Quote
>--------------------------------------------------------------
>Alan Rubin      aru...@cix.compulink.co.uk
>                a...@rubin.compulink.co.uk
>                http://www.compulink.co.uk/~rubin/welcome.html
>---------------------------------------------------------------

Other Threads