Go through Tutorial 3 first.

In this tutorial, we would build a Yellow Pages Application. We will continue it from the last tutorial and extend it to have one more form and another dialog, the MessageQueryDialog to display the required data. We will also look into Symbian File Handling to retrieve the data about businesses.

First, add another form in the resource file in a similar fashion as the earlier form(define a resource in resource file and class to handle the form events) to provide for selection of category. Go through the previous tutorial if you have any problems in adding another form. Once the form is added, we need to execute the form after the city is successfuly selected in the first form. To do this, we make a new form object in the SaveFormDataL() method of the first form(just like we did in HandleCommand for the first form). Once, we have extracted the city and categories, we will now extract the corresponding information about the businesses in the city for the category from te file that we have stored in the phone's memory.(You need to make those files(or copy them from the YPages folder) and place them in the memory) For running the application on the emulator, just place the folder YPages from the current directory to the SDK's winscw folder-

Default Path: C:S60devicesS60_5th_Edition_SDK_v1.0epoc32winscwd

File Handling in Symbian:

First, you need to obtain a handle to File Server session and connect to it. You can do this by:

RFs fileServer; User :: LeaveIfError (fileServer.Connect());

Now, we will use the RFile class to read data. Open the file for reading. The EFileStreamText flag denotes that the file opened is a text file. The EOF is indicated by the return value of TTextFile::Read(), which is KErrEof.

RFile file; User::LeaveIfError(file.Open(fileServer, KMyTextFile, EFileRead|EFileStreamText));

The class to read a text file is TFileText. It is declared in f32file.h header file and a library named efsrv.lib(add this to the mmp file). Before using TFileText, we have to open a file using RFile because TFileText does not have an Open method. TTextFile has Read() method which requires a 16 bit descriptor parameter because Symbian OS stores text files in unicode format. Do not use TFileText to open a file other than unicode. we will get garbage characters if trying to access non Unicode files, such as ASCII files. Go through the source code to understand clearly.

Close the file server session after the reading is completed.

After successfuly reading data from the file, we will now print the read data in a MessageQueryDialog. We must first define the resoruce for this dialog. We have defined a raboutheading_pane resource in the resource file. It is similar to previous dialogs, define the flags, cba function, and items. the difference here is that we do not define a for for this dialog. Instead we define 2 items, heading pane, and a CAknMessageQuery to hold the text.

After defining the resource in the resource file, we must execute the resource in the SaveFormDataL() after reading the data from file. For this, create a new object of type CAknMessageQueryDialog and Prepare it with the resource defined in the resource file. Then, set the header text and finally call RunLD() on dialog to display it. The text to be displayed in the dialog was passed alongwith the dialog's constructor while making the new object.

Download Source code for this tutorial here.