Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


Using TAutoClose

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.