B4J Question B4J detecting standalone situation

jjveloso

Member
Licensed User
Longtime User
Hello.
I would like to know if there's a way my progran knows, while running, if it is running under the IDE environment or under a stand alone situation.
While I try to develop the program,, I feequently test it under those two situations (IDE and standalone) as the paths are not exactly the same I have to move and change things each time (the "temp" folder is created everytime).
Is there anyway to detect the environment (to look for the right folder in the right situation)

Thanks for your help and advise
 

aeric

Expert
Licensed User
Longtime User
Maybe what you are looking for is the Conditional Compilation symbol.
i.e
B4X:
#If Debug
    'Run only during debug in IDE
#End If

#If Release
   'Execute after program compiled as production release
#End If


By the way, you should ask B4J related question in the correct forum.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
And it's good to read that thread, otherwise you might think that you can only use DEBUG and RELEASE, instead you can create your own "symbols" (keywords).
Of course, I also use it for creating beta version (with different package name) or switching between database type.

The above screenshot is from my Support Ticketing System.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
B4X:
i.e.,
#If DEBUG
    log("I am running under IDE")
#End if

#If RELEASE
    xui.MsgboxAsync("I am in release mode!", "B4X")
#end if
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
i.e.,
#If DEBUG
    log("I am running under IDE")
#End if

#If RELEASE
    xui.MsgboxAsync("I am in release mode!", "B4X")
#end if
In his case, DEBUG and RELEASE are not enough.
He wants to know if the compiled version is running with the IDE open or not (stand-alone), that's why he will need custom "symbols".

BTW, you can also write:
B4X:
#IF DEBUG
#ELSE 'IF ...
#END IF
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
or:


By all means the compiled version will ignore DEBUG and vice versa
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Try this
B4X:
Sub AppStart (Args() As String)
    
    If Args.Length>0 Then
        Params=Args(0)
        File.WriteString(File.DirApp,"Test.txt",Args(0))
        
    Else
        File.WriteString(File.DirApp,"Test.txt","Empty")
        Return
    End If

End Sub

And execute your B4J app like this MyApp.Jar YourArgumentsStr
 
Upvote 0

jjveloso

Member
Licensed User
Longtime User
Hello again
I Tryed


Sub AppStart (Form1 As Form, Args() As String)
Dim IDEon As Boolean
IDEon= False

#If DEBUG
Log("I am running under Debug IDE")
IDEon= True
#ELSE
#if RELEASE
Log("I am running under Relelease IDE")
IDEon= True
#End If
#End if

Log("IDEon:"& IDEon)[/CODE]

Unsuccesfully

When in standalone, it detects the environment as RELEASE

I'll continue searching
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Try:
B4X:
Dim r As Reflector
        Dim debugMode As Object = r.GetStaticField("anywheresoftware.b4a.BA", "debugMode")
    Log(debugMode)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
test it under those two situations (IDE and standalone) as the paths are not exactly the same
Can you explain what are the difference in both scenarios?
What are the paths you are trying to change?
I guess that you don't need to make it complicated to do a "detection".
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
#If DEBUG
Log("I am running under Debug IDE")
IDEon= True
#ELSE
#if RELEASE
Log("I am running under Relelease IDE")
IDEon= True
#End If
#End if
This is wrong.

Try:
B4X:
#If DEBUG
  Log("I am running under Debug IDE")
  IDEon = True
#Else
  Log("I am running under Release")
#End If
Log(IDEon)
 
Upvote 0

jjveloso

Member
Licensed User
Longtime User
Heloo Aeric
You're right, the code is quiet redundant

Anayway, I thnk I've found a way to distinguish between IDE status and Standalone status.
Perhaps this is not the more elegant way, but it works.

What I do is to use the simple instruction File.DiRapp

This instruction gives you different values depending the status of the running program.
In case of IDE environment, the last folder of the chain is "Objects"
In case of standalone running the last folder of the chain is "bin"

So based on this difference I added these simple instructions to the sample program generated by the B4J IDE

Sample program modified:
Sub AppStart (Form1 As Form, Args() As String)
    
    text= File.DirApp
    Log ("File.dirapp : "& text)
    
    
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    
    Label2.Text= text
    
    index= File.DirApp.IndexOf("bin")
    Log("index : "& index)
    If index > 0 Then
        Log ("I'm running in standalone condition")
    Else
        Log ("I'm running under IDE environment")
    End If
    
    
End Sub

And it works

I also attach pictures of both situations showing the result

I hope this helps the people, until someboy clever than me ( quite easy), gives another option

Thanks to everybody
 

Attachments

  • code + IDE.jpg
    285.2 KB · Views: 37
  • Standalone.jpg
    282.8 KB · Views: 40
Upvote 0

aeric

Expert
Licensed User
Longtime User
It's a trick but I think not so convenient compared to using conditional compilation.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
For me the question is only where to find certain files (DB) in both situations.

Thanks.
If you are trying to create a package and install to Program Files, the installation folder is not writable without admin permission. It is better to put your db in AppData.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…