Bug? Able To create duplicate Views in same context!?

MrKim

Well-Known Member
Licensed User
Longtime User
I was able to (inadvertently) create two views with the same name. One was created in designer and the other was added later both declared in Class_Globals.
1706145882983.png

program compiled and ran just fine but it was removing the one created in designer that should have been permanent.
Don't know if this should be allowed or not. I believe it is allowed in B4A and B4i as well.
 

LucaMs

Expert
Licensed User
Longtime User
I think it's due to how all global variables work, not just views.

Try it in a B4XPages project.

If you declare a variable in the Class_Globals, let's say:
B4X:
Private MyVar As Int = 10
and one in B4XPage_Created, which theoretically should be private - local, "visible" only within this sub-event:
B4X:
Dim MyVar As Int = 20
this second declaration is as if it were a "redefinition" of the first. Note that if you declared it the second time as Double, the IDE would immediately report the error, you can't change its type.
In the B4XPage_Appear:
B4X:
Log(MyVar)
the log will not be 10, the value of the global variable, but 20 because, as mentioned, in the sub you have "redefined" the same variable (I don't know if it can be defined as "override").
 

MrKim

Well-Known Member
Licensed User
Longtime User
I think it's due to how all global variables work, not just views.
Should have clarified. It IS a B4X project.
As mentioned BOTH are declared in Class_Globals.
ONE of the views was added in designer and declared FROM designer (Right Click/Generate...)
The OTHER was declared manually in the code window and initialized later .. = (xui.CreatePanel("")).
The filter makes it look like they were together but actually they is 20 or 30 declarations between them. That is why I inadvertently duplicated it.
 
Top