passing TInt type variable from one form to another form
| Thu, 2007-08-02 10:40 | |
|
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 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 |
|






Forum posts: 285
One way is to use TLS. Check out Dll::Tls()
Cheers,
Sri
Forum posts: 732
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.
Forum posts: 24
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
Forum posts: 24
Hi,
I done with this problem.
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 )
Forum posts: 732
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.
Forum posts: 3
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
Forum posts: 603
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.