passing TInt type variable from one form to another form

Login to reply to this topic.
Thu, 2007-08-02 10:40
Joined: 2007-07-24
Forum posts: 24

Hello all,

I have two forms in my application.

When I select any item from listbox (list on 1st form), i want to pass that item index to
another form (where i want to use that TInt variable)

I can get "Selected item" from ListBox like.......

TInt itemIndex = iListBox->CurrentItemIndex();

Now i want to use this itemIndex on another form.

So please tell me how i do this?

Thanks


Thu, 2007-08-02 11:15
Joined: 2004-05-21
Forum posts: 285
Re: passing TInt type variable from one form to another form

One way is to use TLS. Check out Dll::Tls()

Cheers,
Sri

Thu, 2007-08-02 12:22
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: passing TInt type variable from one form to another form

I hope you can create a member variable in your AppUi and a set/get function. You can access the AppUi reference from any where in your project. You may refer this thread: get access to AppUI members.


Fri, 2007-08-03 06:14
Joined: 2007-07-24
Forum posts: 24
Re: passing TInt type variable from one form to another form

Thanks for your suggestions.

But please let me know how i can use AppUi() for this. CAn you please give me code for that?

Thanks

Fri, 2007-08-03 07:13
Joined: 2007-07-24
Forum posts: 24
Re: passing TInt type variable from one form to another form


Hi,

I done with this problem. Smiling Smiling

Adding code for other people...........

         //          Declare  variable in your "project_nameAppUi.h" as public

       TInt aNum;   //public in appui

      //             Then set value for this 'aNum'  in your current form as follows  (Add project_name.h file in your current CPP file)

                     Cproject_nameAppUi* iAppui;

        iAppui=(CbomPassbookAppUi*)(CEikonEnv::Static()->AppUi());

        iAppui->aNum = 10;

                 //That's it in current form

                // Go to your next form  (.cpp file)        Add project_name.h

                //    Add following in function where you want to access previous form's value as

                     CbomPassbookAppUi* iAppui;
       
                     iAppui=(CbomPassbookAppUi*)(CEikonEnv::Static()->AppUi());

                  TInt selectedNumber = iAppui->aNum;

Regards

Sameer

( iWork Technologies, Pune, india )

Mon, 2007-08-06 05:59
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: passing TInt type variable from one form to another form

Making public member variables is not recommended, so probably you may create the variables as a private one and create a public getter and setter functions to get/set the value of that member variables.


Wed, 2007-11-14 10:21
Joined: 2007-10-23
Forum posts: 3
Re: passing TInt type variable from one form to another form

thanks a lot sameer for that small piece of code.. was stuck with this for the last 2 days.. it actually helped me in solving out my problem Smiling

Wed, 2007-11-14 13:10
Joined: 2003-12-05
Forum posts: 603
Re: passing TInt type variable from one form to another form

The recommended way of handling data in Symbian apps is to create a Model class (or several of them with a single interface) and let the Document class own that Model (to create and destroy it). Since the doc handles the storage, it is then easy to implement also saving the model from within the Document class.

View then displays the content, getting a pointer to Model from the Document. Usually the pointer to Model in View is initialized in the creation of the view.

AppUi handles commands and forwards them to the Model (by calling Model's methods), Model then updates itself based on the commands. As model then is updated it can notify the views of the state changes by using an interface class (M class) the view(s) implement (Observer design pattern).

This way your applications will become easily portable, it's logic being implemented in the Model, as AppUi and View "only" receiving commands from the user and handling the state changes of the Model by updating the View.

In this case the selection of the list box in other view would tell the model that a specific object in a container would now be "active"; in use. When the view is then switched to the detail view, it would get the selected object in use from the model and display it.

  • Login to reply to this topic.