Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to store and restore text


Storing text and its formatting

theFs represents a session with the file server.

RFs theFs;
CFileStore* theStore;
TParse fileStoreName;
TBufC<28> name(_L("C:\\Documents\\richtxt.dat"));
TStreamId streamId;

A session with the file server must be opened before file-related operations are carried out. Use RFs::Connect() to open a session with the file server.

Use CRichText::StoreL() to externalise the text object to a CFileStore. The stream in which the text is stored is identified by its ID. This will later be used to restore the rich text.

Use RFs::Close() to close the file as well as the file server session.

// Store text to a file store
theFs.Connect();
theFs.Parse(name,fileStoreName);
theStore=CDirectFileStore::ReplaceLC
    (theFs,fileStoreName.FullName(),EFileRead|EFileWrite);
theStore->SetTypeL(KDirectFileStoreLayout);
// externalize the rich text
streamId=iRichText->StoreL(*theStore); // Store and get ID
CleanupStack::PopAndDestroy(); // pop and destroy store
theFs.Close();

[Top]


Restoring rich text

The following example restores the text object using CRichText::RestoreL(), specifying the file store and the ID of the stream in which the rich text is stored.

The file is opened for reading only.

// Restore text from file store
theFs.Connect();
theFs.Parse(name,fileStoreName);theStore=CDirectFileStore::OpenLC
    (theFs,fileStoreName.FullName(),EFileRead|EFileShareReadersOnly);
if (theStore->Type()[0]!=KDirectFileStoreLayout)
    User::Leave(KErrUnknown);
 // internalize from the store
RichText->RestoreL(*theStore,streamId);
CleanupStack::PopAndDestroy(); // pop and destroy store
theFs.Close();