diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/PDK/Source/GUID-52151070-626D-5F14-B53F-7B46BCBD633E.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/PDK/Source/GUID-52151070-626D-5F14-B53F-7B46BCBD633E.dita Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,34 @@ + + + + + +Using +TAutoCloseExample code showing how TAutoClose can be used +to clean up when an object goes out of scope. +

A simple example shows how this class can be used.

+TInt ReadFile(const TDesC& aFile) +// +// Read a file +// + { + TAutoClose<RFile> file; + TInt r=file.iObj.Open(aFile,KFileStreamText|EFileExclusive); + if (r!=KErrNone) + return(r); + TBuf<100> b; + if ((r=file.iObj.Read(b))!=KErrNone) + return(r); + ... + } +

The object file goes out of scope when the function completes, +and the compiler automatically destroys it, calling the TAutoClose destructor +in the process. The destructor calls Close() on the RFile member +of TAutoClose.

+
\ No newline at end of file