Would setting inp to nil work as well?  Without the obtuse code?

dim inp as TextInputStream = file.OpenAsTextFile
...
inp = nil
dim bs as BinaryStream = file.OpenAsBinaryFile( true )

Just curious.  Your code block IS rather clever.
Tim


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> [EMAIL PROTECTED]
> Sent: Tuesday, January 23, 2007 8:34 AM
> To: [email protected]
> Subject: Re: RB TextOutputStream.Close
>
>
> 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>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.17.8/648 - Release Date:
> 1/23/2007 11:04 AM
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.8/648 - Release Date: 1/23/2007
11:04 AM

_______________________________________________
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>

Reply via email to