Views in code vs designer

oldeast

Active Member
Licensed User
Longtime User
As a newbie I looked at the example for coding views..sweet.
Have had no problem loading webviews, doing db updates and moving between panels thanks to all the great examples.
Then I downloaded 2.2 and it looks like I should use designer to implement designer scripts for scaling
So I rejigged everything but I've lost the plot.
I set up 3 activities, but now I find that objects cannot be made global, so how do I use code in one activity or code module that needs to manipulate views created in another?
Probably a dumb question but its go me beat.:BangHead:
other than that Its been a fun couple of weeks.
 

lagore

Active Member
Licensed User
Longtime User
Views (buttons etc) are 'activity objects' and therefore cannot be declared as 'Process Globals', so one activity cannot reference another activities views. If I remember you would have to do it indirectly (save variables / load variables) I think somebody did a post on it a while back.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As lagore already wrote, views are Activity objects and can be accessed directly only in their activity.
... so how do I use code in one activity or code module that needs to manipulate views created in another?
You cannot manipulate from an activity views created in another activity !
You can manipulate views in a code module but these views must be an the active activity. To access a view in a code module you need to tansmit the view as an object ib the calling routine. Like in this example
What kind of view manipulation do you want to from in another activity?

Best regards.
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
Views in code vs designer thanx ..

OK, say I have pnlMain, and above it pnlMenu with a button btnSetup and a panel pnlSetup
I want btnSetup to hide pnlMain and show pnlSetup,

I define pnlMain, pnlMenu, btnSetup in Main Activity and define pnlSetup in setup activity

Code for btn setup_click causes an exception when I make pnlSetup visible


Thanks for your help, I will also check what you advised.
 

Attachments

  • btnSetup_click.txt
    1.6 KB · Views: 147
Upvote 0

lagore

Active Member
Licensed User
Longtime User
If I understand you correctly you have 2 Activities 'Main' & 'setup', if you are in Main you cannot call "pnlSetup.visible=True" as pnlSetup is in a different Activity and at that point in time does not exist as it is a 'Global' object not a 'process_ Global' object. You would have to call the 'setup' activity
B4X:
StartActivity("setup")
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
thanx for the response

Hi,I am still getting pnlSetup not initilised with StartActivity("Setup")
I thought another answer might be to move the sub to the Setup activity name it LoadSetUp then call it with
CallSubDelayed2(pnlSetup,"LoadSetup",txt) (txt=btnSetup.Text) which I read as starting the activity but pnlSetup is still not initailised.
I think I am missing or not understanding something very simple so I'll start some more reading.
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
Can you 'File -> 'Export as Zip' your sample program as it makes it much easier to see where you are going wrong
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
Fies

Hi,
Attached 2 files the SigGen1 has the views created in code, you can check out the Set up button and Classifications and get an idea on what I'm doing
The views created in designer SigGen2, Set up throws an exception.
Many thanks for taking the time to help.
 

Attachments

  • SigGen1.zip
    19 KB · Views: 135
  • SigGen2.zip
    21.9 KB · Views: 139
Upvote 0

klaus

Expert
Licensed User
Longtime User
I tried to test your programs but can't because there is no database file included in your projects.
From what I have seen is in the SinGen2 project you initialize panels which are already defined in the layout files you shouldn't initialize them once more in the code !

Then you define pnlSetup in the Main module but it's a view in the Setup activity. You cannot acces view in other activities !

In Setup you initialize pnlSetup but you shouldn't because because it's already defined in the layout file and you set it's Visible property to False ?

You should read the tutorial about Activities and their life cycle.

It seems that you are mixing up Panels in the same activity with Panels in other activities.

To show pnlSetup you need to call StartActivity(Setup) as laogore already suggested. This will load the Setup activity.

Best regards.
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
Thanks Klaus

I'll do as you suggest and sort out the duplicate views. I appreciate the assistance and advice from everyone.
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
Sorted..

I get it now, the Set Up and Classification panels working....
I think I was overcomplicating the way activities work and trying to pass variables when there was no need.
Thanks again.
 
Upvote 0
Top