Wish Designer Script Extension accept hexadecimal values for colors

klaus

Expert
Licensed User
Longtime User
I have begun to play with the Designer Script Extension.
I wanted to set colors, but this code in the Designer Scripts, with hexadecimal values, does not work:
B4X: Copy
MyStandardClass.SetColorTextSizeColor(Button1, 0xff000000, "New", 20, 0xffff0000)
It throughs this error:
Waiting for debugger to connect...
Program started.
Error occurred on line: 16 (MyStandardClass)
java.lang.NumberFormatException: For input string: "0xff000000"
at java.base/jdk.internal.math.FloatingDecimal.parseHexString(FloatingDecimal.java:2082)
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1870)
at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.base/java.lang.Double.parseDouble(Double.java:543)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:434)
at b4j.DESFirstStep.mystandardclass._setcolortextsizecolor(mystandardclass.java:82)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4j.objects.DesignerArgs.callsub(DesignerArgs.java:143)
at b4j.DESFirstStep.designerscripts.LS_mainpage.LS_general(LS_mainpage.java:13)

This code with Int values does work:
B4X: Copy
MyStandardClass.SetColorTextSizeColor(Button1, 0xff000000, "New", 20, 0xffff0000)


It seems that uppercase characters are not allowed in class names.
This code does nothing:
Designer Script
B4X: Copy
DDD.AddClass("ToolBar", pnlToolBar)
B4XMainPage code.
B4X: Copy
    For Each p As B4XView In DU.GetViewsByClass("ToolBar")
        'loads the layout in each view, only one in our case
        p.LoadLayout("ToolBar")
    Next
But this ones works:
B4X: Copy
DDD.AddClass("toolbar", pnlToolBar)
B4XMainPage code.
B4X: Copy
    For Each p As B4XView In DU.GetViewsByClass("toolbar")
        'loads the layout in each view, only one in our case
        p.LoadLayout("ToolBar")
    Next


Attached my test project.
 

Attachments

Until hex literals are supported, you can pass the hex values as strings and add this sub to your class:
Code: Copy
Private Sub GetIntFromString (n As String) As Int
    If n.StartsWith("0x") Then
        Return Bit.ParseLong(n.SubString(2), 16)
    End If
    Return n
End Sub

Private Sub SetColorTextSizeColor(DesignerArgs As DesignerArgs)
 Dim clr As Int = GetIntFromString(DesignerArgs.Arguments.Get(1))

It seems that uppercase characters are not allowed in class names.
Looks like a bug. I'll check it.
 
Back
Top