Control keyword & Optimized Compile

Scubaticus

Active Member
Licensed User
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

This was not a problem with the 6.5
 

agraham

Expert
Licensed User
Longtime User
"Control(lblName, Label)" fixes it although according to the Help->MainHelp->Keyword->Runtime control manipultion->Control it should not be necessary

As of version 6.00, the compiler may ask you to specify the control's or object's type.

The following properties does not require you to specify the type:

Text, Left, Top, Width, Height, Visible, Enabled, Focus, BringToFront, Color, FontColor, FontSize, Refresh, Dispose, Name, Image, Checked, IgnoreKey, SelectionLength, SelectionStart, ScrollToCaret, Multiline and LoadPicture.
Looks like a little bugette crept into 6.80!
 

Scubaticus

Active Member
Licensed User
I tried to fix this problem internally because I use the Control keyword a lot:

B4X:
Sub App_Start
   lblName = "Mod1.Mod1Label1"
   cType   = ControlType(lblName)
   Control(lblName, cType).Text = "Hello World"
   Mod1.Mod1Form.Show
   
End Sub

But it won't compile this way as 'cType' is not a controltype.
Now i have to recode it into Select Case statements ....
 

Scubaticus

Active Member
Licensed User
Ok, I thought I could solve this like:

B4X:
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
 

agraham

Expert
Licensed User
Longtime User

Scubaticus

Active Member
Licensed User
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?
 

agraham

Expert
Licensed User
Longtime User
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?
Sorry , I don't understand this. Can you give an example of what used to work and now doesn't?
 
Top