Symbian3/SDK/Source/GUID-52151070-626D-5F14-B53F-7B46BCBD633E.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 11 Mar 2010 15:24:26 +0000
changeset 2 ebc84c812384
parent 0 89d6a7a84779
permissions -rw-r--r--
week 10 bug fix submission: Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-52151070-626D-5F14-B53F-7B46BCBD633E" xml:lang="en"><title>Using
TAutoClose</title><shortdesc>Example code showing how <codeph>TAutoClose</codeph> can be used
to clean up when an object goes out of scope.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>A simple example shows how this class can be used.</p>
<codeblock id="GUID-468EE01A-8EC1-5D8E-845A-710D5BE3BBBC" xml:space="preserve">TInt ReadFile(const TDesC&amp; aFile)
//
// Read a file
//
    {
    TAutoClose&lt;RFile&gt; file;
    TInt r=file.iObj.Open(aFile,KFileStreamText|EFileExclusive);
    if (r!=KErrNone)
        return(r);
    TBuf&lt;100&gt; b;
    if ((r=file.iObj.Read(b))!=KErrNone)
        return(r);
    ...
    }</codeblock>
<p>The object <codeph>file</codeph> goes out of scope when the function completes,
and the compiler automatically destroys it, calling the <xref href="GUID-3377FA4B-FDC8-3B25-8C5F-34675F6BEA12.dita"><apiname>TAutoClose</apiname></xref> destructor
in the process. The destructor calls <codeph>Close()</codeph> on the <codeph>RFile</codeph> member
of <codeph>TAutoClose</codeph>.</p>
</conbody></concept>