On Jan 23, 2007, at 09:31 UTC, Carlo Rubini wrote:
> Does this approch hold true also for textInputStream and
> binaryStream?
Yes. I never call .Close on anything in REALbasic; better to let the
framework do it when the object goes out of scope.
Note that if I really need a stream to be closed within a method --
perhaps because I'm about to reopen it with a different object -- I
might do something like this:
do
Dim inp As TextInputStream = file.OpenAsTextFile
...
loop until True
Dim bs As BinaryStream = file.OpenAsBinaryFile( True )
...
The do-loop executes only once, since when it gets to the check at the
bottom, it will of course see that True is true and so stop looping.
But it also defines a code block; any variables defined within it (such
as "inp" in this example) get torn down at the end of the block. So
this both makes sure that the stream is closed, and makes sure that I
don't accidentally try to use "inp" further down in the method (which
would be invalid after it was closed anyway).
Often a better approach is to refactor your code so that one method
only does one thing, and the above trick isn't needed. But sometimes
it's worthwhile, so I thought I'd point it out.
Best,
- Joe
--
Joe Strout -- [EMAIL PROTECTED]
Verified Express, LLC "Making the Internet a Better Place"
http://www.verex.com/
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>