Share My Creation Device Basic language IDE

Unfortunately without a Device IDE it is no longer possible to whip up quick and dirty programs on an Android device like we could with Basic4ppc on Windows Mobile.

I realised that my BasicLib script interpreter library only lacked one thing that stopped it being used as the basis for an interpreter for a device IDE and that was that it didn't support any means of responding to external events so all it could do was run linear code then exit. Fine for scripts but not for a user driven application that spends most of its time suspended waiting for events to happen. So I added it!

As well as being able to respond to events a program needs to be able to interact with the platform to add controls and access the GUI, file system and other OS services. Unlike previous versions of BasicIDE, which used the normal BasicLib library and relied upon the "Sys" function to call methods, version 2.2, and future, versions use a new BasicLibIDE library that "knows" about the methods in Script.bas so the platform functions are now embedded in the script language. It is important that the version of Script.bas matches that of the BasicLibIDE library as both need to be modified in parallel to add new functions to the language.

The previous Sys and CallHostSub functionality is of course still available.

The demo program here supports the most important views, and their events, for small programs and has graphics and file handling support. Look at Readme.txt for instructions and the comments in the Script module to see what is implemented there.

EDIT :- See post #7 for a suggestion to add Invalidate to the Script module

EDIT :- Version 2.0 posted. See post #8 for details.

EDIT :- Version 2.1 posted. See post #9 for details.

EDIT :- Version 2.2 posted. See post #15 for details.

EDIT :- Version 2.2a posted with the BasicLibIDE library included. See post #17 for details.

EDIT :- Version 2.3 posted. See post #18 for details.

EDIT :- Version 2.4 posted. See post #20 for details.

EDIT :- Version 2.5 posted. See post #23 for details.

EDIT :- JesseW has posted his improved version of the IDE itself, see post #32 for details. You will still need the BasicLibIDE jar and xml from the archive in this post.

EDIT :- Version 2.6 posted. See post #47 for details.

EDIT :- Version 2.7 posted. See post #51 for details.

EDIT :- Version 2.8 posted. See post #52 for details.

EDIT :- Version 2.9 posted. See post #79 for details.

EDIT :- Version 2.91 posted. See post #87 for details.

EDIT :- Version 2.92 posted. See post #92 for details.

EDIT :- Version 2.93 posted. See post #95 for details.

EDIT :- Version 2.94 posted. See post #100 for details.

EDIT :- Version 2.95 posted. See post #118 for details.

EDIT :- Version 2.96 posted. See post #138 for details.

EDIT :- Version 2.97 posted. See post #140 for details.

EDIT :- Version 1.98 of BasicLibIDE is posted below. Use this instead of the version in BasicIDE2.97.zip. It fixes a problem with Call and CallSub.
 

Attachments

  • BasicLibIDE.jpg
    BasicLibIDE.jpg
    12 KB · Views: 31,055
  • BasicIDE2.97.zip
    118 KB · Views: 2,487
  • BasicLibIDE_1.98.zip
    44.1 KB · Views: 1,345
Last edited:

JesseW

Active Member
Licensed User
Longtime User
Andrew, I'm afraid you've caught me up to my elbows in unraveled code. I have installed the new lib files, but won't be able to test them for probably a week or two, as I can only code for an hour, maybe two, at a time, a few times a week. But I will try it as soon as I can and let you know...

I can't think of any "small" changes. The # works well for remarks and directives. Thanks for asking :)
 

JesseW

Active Member
Licensed User
Longtime User
Andrew, come to think of it, would you add StrJoin to compliment StrSplit? Thx...
 

JesseW

Active Member
Licensed User
Longtime User
Andrew, I re-read the 1.52 post that you posted a few days ago, and I got a headache too! :D I tested it best I could with my limited knowledge of its internal workings, and I can't break it. A simple script I tried was this:

B4X:
addbutton("b", 0, 0, 200, 40, "")
addcheckbox("c", 0, 50, 60, 40, "")

sub button_click(who)
  setchecked("c", not(getchecked("c")))
end sub

sub check_changed(who)
end sub

There was no menu reorganizing in this update. That got real hairy real quick. So here's what I've done.

added - you can now use: sys("setactivitytitle", "title text")
added - and: sys("setactivitytitlecolor", color)
added - menu option Auto Save, which automatically saves the source on the editor's Activity_Pause event
added - all settings are now saved and restored
added - thanks to Andrew, we can now use the pound sign # for remarks :sign0188: - it will later be used for inline directives, like #INCLUDE

I'm not sure what's next. I want to stress, I use BasicIDE a LOT! That's why I'm customizing it. But the customization's are for the look and feel that I like. If anyone has any requests for editor changes, please say so! I'm thinking I may like to change the background color from white to something else, configurable of course :D

Andrew, I'm concerned that all these changes I'm making may make it hard(er) for you to incorporate changes of your own. You've not even commented if these changes to your project are welcome or not. I'm also concerned that if these changes are not incorporated into any new releases from you, it may be difficult for me to incorporate them back in. If you don't mind, let me know where I stand in this. I certainly don't want to offend you in any way. You're a major credit to this community. I'm just trying to polish up a bit. Thanks...
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
Im sorry... I forgot to add a feature I really wanted.

added - the editor's scroll window (when Fling is enabled) and cursor position now stay when flipping out and back from the editor to other apps or to run a script, in both landscape and portrait orientations. But... If the orientation changes, the scroll window doesn't want to go back to where it was. Maybe because it now has different dimensions? But the cursor stays, however it may no longer be in the window...
 

Attachments

  • BasicIDE.zip
    51.4 KB · Views: 421
Last edited:

JesseW

Active Member
Licensed User
Longtime User
Andrew, my attempts to create a custom dialog in script.bas are not working. Here is what I have

B4X:
Sub InputCustom(name As String, title As String, positive As String, cancel As String, negative As String)
   Dim v As View
   v = viewmap.Get(name)
   If Not(v.IsInitialized) Then Return DialogResponse.CANCEL
   Dim vis As Boolean
   vis = v.Visible      'if panel hidden, unhide to show then hide again
   If Not(vis) Then v.Visible = True
   Dim cd As CustomDialog2
   cd.AddView(v, v.Width, v.Height)
   ret = cd.Show(title, positive, cancel, negative, Null)
   If Not(vis) Then v.Visible = False
   Return ret
End Sub

When called with this B4Script code

B4X:
addpanel("p", 0, 0, windowwidth / 2, windowheight / 2, "")
addcheckbox("c", (getwidth("p") / 2 - 30), (getheight("p") / 2 - 20), 60, 40, "p")
setvisible("p", false)

sys("inputcustom", "p", "test", "yes", "cancel", "no")

the screen slowly dims, stays dimmed a second or two, then errors saying

B4X:
Ended with error

Error at line 5
Code - sys("inputcustom", "p", "test", "yes", "cancel", "no")
Error - CallHostSub : inputcustom returned Null

Got the same error by not setting the panel's visibility to false. Any ideas?
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Allways check the unfiltered logs when you can't see the cause of any error. In this case you will see
B4X:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
   at android.view.ViewGroup.addViewInner(ViewGroup.java:3337)
   at android.view.ViewGroup.addView(ViewGroup.java:3208)
   at android.view.ViewGroup.addView(ViewGroup.java:3165)
   at android.view.ViewGroup.addView(ViewGroup.java:3145)
   at anywheresoftware.b4a.agraham.dialogs.InputDialog$CustomDialog2.Show(InputDialog.java:2090)
   at anywheresoftware.b4a.agraham.basicide.script._inputcustom(script.java:1888)
   ...
The solution is
B4X:
v = viewmap.Get(name)
v.RemoveView ' remove it from the Activity or Panel that is its current parent

As to your other points. I am more than happy for you to do whatever you want with the library and Script.bas and post it for others to use if they wish. I would assume that any changes you will make to Script.bas will be additions rather than modifications so keeping them in a separate area at the bottom of the code would make it easy to paste it into any new Script.bas version. However as I don't anticipate making any further changes myself to Script.bas you will probably just be able to use your own existing one with any future version of the library.

I've implemented "StrJoin(Array, Delimiter)" for the next version which I'll post later today.
 

JesseW

Active Member
Licensed User
Longtime User
Andrew,

1) I don't believe strsplit is working correctly. it seems to not be dimensioning the target array to the new array length. in the example, only the first word is displayed.

B4X:
Dim words(0)
Nma= "$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M,,,,0000*18"
StrSplit(words(),Nma,",")
for i = 0 to ArrayLen(words())-1
  msgbox(words(i))
next
#

2) it complains if there are no statements after a Next or Loop. I know java doesn't like infinite, and perhaps empty, loops, but not having statements after next/loop? remove the # in the example above to demonstrate.

thanks for all your help :D
 

agraham

Expert
Licensed User
Longtime User
1) Hmm! SptrSplit is actually working OK as you will see if you use some literal numeric indeces, however it is failing to register the new array length in the variable descriptor so ArrayLen is returning 0. If you Dim the array with a number other than zero you will see that ArrayLen returns the original array length after StrSplit instead of the new length. I'll look at it.

2) is expected behaviour, though I might have forgotten to document it. :( A For and a Do statement both exit their loop by jumping to the statement after the Next. For efficiency the interpreter tokenises the code and pre-computes the jump destinations within the token stream when it tokenizes the source before running it. When there is no statement after the Next to jump to I deliberately throw that error. I guess I could fix it but it's easier just to detect and error it.
 

JesseW

Active Member
Licensed User
Longtime User
1. understood. I was using it to count items in a string, so if it were updated, that'd be great.

2. personally, now that I see what you're doing, I think its fine the way it is. I like the idea of optimization.
 

agraham

Expert
Licensed User
Longtime User
Version 2.8 now posted lets your scripts call your own Subs in Script.bas as normal functions without using Sys(...) by specifying them with the new BasicLibIDE.AddSysCalls method.

While I had this on my desk I thought I might as well add the ability requested in post #28 to add your own new functions to the BasicLibIDE internal Sys call table so that you can call them in the same way as the ones compiled into the library. In retrospect I should probably have done it this way from the start rather than having the library know what is implemented in Script.bas.
 

JesseW

Active Member
Licensed User
Longtime User
Andrew, that is H. O. T. HOT!! Thank you!!!

:sign0188:

I have found an issue that I bet you can correct very easily. I have exceeded the stack depth, and the error stated to increase the stackDepth property, but when I did so and tried to compile, B4A reported that the stackDepth property is readonly. :(

The popup help said the default value was 5. I thought about increasing it to 16 or 32. Is there a reason not to go that much?
 

agraham

Expert
Licensed User
Longtime User
Sorry, it got lost in the conversion from C# to Java as, unlike C#, Java doesn't have properties so you need to implement both set and get as individual methods.

I can't be bothered to do a full release so I've patched the archive. Download it again and it should be OK. You can set StackDepth to whatever you want as it doesn't occupy a lot of memory. It is set low more as a quick catch for a recursive runaway than to save memory.
 

JesseW

Active Member
Licensed User
Longtime User
Andrew, tried the new addsyscalls function, and this happened:

added to Process_Globals
B4X:
Dim subnames(0) As String

added to Activity_Create
B4X:
If FirstTime Then
   'Blib.StackDepth = 32      'Added by JesseW
   subnames = Array As String("SetActivityTitle", _
      "SetActivityTitleColor", "RemoveFromParent", _
      "InputCustom", "cARGB", "DialogResponse_Positive", _
      "DialogResponse_Cancel", "DialogResponse_Negative", _
      "FileDirInternal")
   Blib.AddSysCalls(subnames)
End If

In BasicIDE I tried
B4X:
sys("setactivitytitle", "Title")

and it worked fine. but when I tried
B4X:
setactivitytitle("Title")

it gave this error
B4X:
Ended with error

Erorr at line 1
Code - setactivitytitle("Title")
Error - Run : java.lang.NumberFormatException: Title - Title

I looked at the logs, and it appears it is expecting a number??? Did I do it wrong???

Edit: If I try
B4X:
setactivitytitlecolor(corange)

I get this

B4X:
Ended with error

Error at line 1
Code - setactivitytitlecolor(corange)
Error - Assign : expected EQ, found CR

Here is the B4A code for these two functions


B4X:
''Sets the activity title text in the activity's title label
''Usage:
'' Sys("SetActivityTitle", title)
Sub SetActivityTitle(title As String)
   Activity.title = title
End Sub

''Sets the activity title text color
''Usage:
'' Sys("SetActivityTitleColor", color)
'' ex. Sys("SetActivityTitleColor", cWhite)
Sub SetActivityTitleColor(color As String)
   Dim icolor As Int
   icolor = color
   Activity.TitleColor = icolor
End Sub
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
That's the error I would expect if "setactivitytitle" was misspelt in either the array passed to AddSysCalls or in the call in the script as the interpreter would then think it is an array access.

Actually, I had cut and pasted all the sub names straight from the code to the array statement, so it wasn't a spelling issue...

Also you might have ignored line 1987 in Script.bas. If you do it before Initialize it will forget the new functions.

I didn't see that you had put that section of code in. :sign0012:

That's weird, because I had placed the addsyscalls statement at the very end of activity_create, well below the blib.initialize statement.

That said... I added my code to the custom functions region in the script.bas provided in the 2.8 archive, and cut and pasted the list of sub names into the array statement in line 1989 and everything works now. Exact same list of names, just passed in a raw array statement instead of being assigned to an array variable. I wonder why didn't it like using an array called subnames?

But that's not important. Whats important is it works. And its a fantastic addition to BasicIDE. Thanks again Andrew. Your the man!
 

JesseW

Active Member
Licensed User
Longtime User
I suspect a positioning problem, not the array name. Your code snippet above shows it inside a FirstTime conditional which is wrong. It needs to be done after any Initialize.

The firsttime conditional block was in fact several lines after the blib.initilaize, at the very end of activity_create, immediately above the End Sub. So blib was initialized already. But no mind, it works, and it works very well.

One thing tho, that I did wrong, was placing it in a FirstTime condition. If the device was rotated, a new Blib object would have been created, and the new statements would not have been installed.

I've patched the archive. Download it again and it should be OK.

I've re-downloaded the archive. Twice. Replaced the jar and xml files, replaced my files in the files dir, and replaced basicide.b4a and script.bas. recompiled. Still getting the error :(

I will wait till you've had a chance to correct it.

Thanks again.
 
Top