realnug@the-gamesters.co.uk wrote:
Having created classes to extend things like the TCPsocket
with no problem, I thought do the same when I wanted to add
functions to a BinaryStream.
Basically I have a class (eg myStream) which has a
superclass of Binarystream.
That's fine, as long as you're going to instantiate myStream yourself
somehow -- for example, by giving it a constructor that takes a string,
and having that call through to the BinaryStream constructor that takes
a string.
I then define a stream using MyStream, but when I try to
open a file with OpenAsBinaryFile, I get a Type mismatch
error. Saying expected MyStream but got BinaryStream.
And it's quite right. OpenAsBinaryFile returns a BinaryStream, not a
MyStream. You can't change what type some framework function returns.
The only difference I could see is that TCPsocket needs to
be added to the form (initially), as it is a superclass of
SocketCore.
No, the difference is that you're instantiating the socket yourself, not
calling some function that returns a TCPSocket. If you did, you'd find
that it still returns a TCPSocket, not some subclass you may be thinking of.
Yes, I could just write the additional functions I need
separately, but this seemed the neatest solution. Any
thoughts?
Probably a module of Extends methods are the best solution in practice.
Best,
- Joe
--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|