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