I have a form called Form1 with a label called Label1
B4X:
Sub Globals
'Declare the global variables here.
End Sub
Sub App_Start
lblName = "Main.Label1"
Control(lblName).Text = "Hello World"
Form1.Show
End Sub
On the desktop it executes normally.
Not optimized compiled (Windows Exe) executes normally
Optimized compiled (Windows Exe) crashes with a message (translated from Dutch so originally it will look a little bit different):
B4X:
An error occurred on sub __main_app_start
Unable to convert object of type Dbasic.EnhancedControls.CEnhancedLabel to type Dbasic.IText
No it won't. It can't be a variable as the compiler needs to know the control type at compile time in order to emit the correct code for the type of control.
Sub App_Start
Name = "Mod1.Mod1Label1"
cType = ControlType(Name)
Trans = "Hello World"
Select cType
Case 'Button'
Control(Name, Button).Text = Trans
Case 'CheckBox'
Control(Name, CheckBox).Text = Trans
Case 'Form'
Control(Name, Form).Text = Trans
Case 'ImageButton'
Control(Name, ImageButton).Text = Trans
Case 'Label'
Control(Name, Label).Text = Trans
Case 'TextBox'
Control(Name, TextBox).Text = Trans
End Select
Mod1.Mod1Form.Show
End Sub
Guess what? It won't compile either. It gives me the error (again translated from dutch):
B4X:
Error compiling program.
Error message: The index is outside of range. The index may not be negative and should be smaller than the size of the collection.
Line number: 11
Line: Select cType
You may have realised this by now but the problem is that your Case statements use single quotes instead of double quotes and so look like comments to the compiler.
Oops...was I sleeping or blinded by the 'Line: Select cType' reference for the error.
Anyway, the names of all my controls with labels comes from a database with the value it should become. This is done for translation purpose.
In 6.5 this wasn't a problem at all. As from 6.8 it seems it's not possible anymore to access a control using a string but I have to use a constant instead?
In 6.5 this wasn't a problem at all. As from 6.8 it seems it's not possible anymore to access a control using a string but I have to use a constant instead?
I see this bug too. Thanks.
It will be fixed in the next version.
You can apply the fix by replacing CEnhancedLabel.cs with the one attached.
This file should be located under Tzor folder. By default it is:
C:\Program Files\Anywhere Software\Basic4ppc Desktop\Tzor