Wish Include/Use

Roger Taylor

Member
Licensed User
Longtime User
I can't find any threads on the subject of "include" or "use" so I'm assuming, even knowing I'll be told I shouldn't ask questions here but to just search for what I need, I'm looking for the common feature of almost all languages, the ability to include another file inline with my main source. Subroutines common to my projects could be kept in a .b4a file without having to build a library of it each time I make changes. That's not the only reason to #include another file, though.

In my humble opinion, B4A is severely lacking. However, in the very early days I was surprised that it even worked to compile a simple Android app. So we've come a long way, or perhaps not so much? Is this why it's free and I should just be glad for what it Does Do?
 

Roger Taylor

Member
Licensed User
Longtime User
I already do this, but the problem is that when I try to have a thread sub in a class instance. Not to change the subject because I think if I was able to just "include" my subroutines as inline code my wish would work. Including inline code, and calling on class or code module subs is far from being the same thing.

For example my "cpu" object has been created using my hd6809 class module using: dim cpu as hd6809. I can call my cpu.execute sub directly from the main module just fine as expected even from within a thread created by and for the Main module. Using a forever loop inside the thread sub I am successfully stepping my cpu.execute sub and it works great. However, that's not what I want to do. I want to have the cpu.execute sub as the thread sub.

Trial and error seems to lead to the same results.
From Main module:
Thread1.Start(cpu, execute, args) sub not found
Thread1.Start(null, cpu.execute, args) sub not found
Thread1.Start(cpu, cpu.execute) sub not found

I've also tried creating the thread from within my hd6809 class which also fails.
 

Roger Taylor

Member
Licensed User
Longtime User
I already do this, but the problem is that when I try to have a thread sub in a class instance. Not to change the subject because I think if I was able to just "include" my subroutines as inline code my wish would work. Including inline code, and calling on class or code module subs is far from being the same thing.

For example my "cpu" object has been created using my hd6809 class module using: dim cpu as hd6809. I can call my cpu.execute sub directly from the main module just fine as expected even from within a thread created by and for the Main module. Using a forever loop inside the thread sub I am successfully stepping my cpu.execute sub and it works great. However, that's not what I want to do. I want to have the cpu.execute sub as the thread sub.

Trial and error seems to lead to the same results.
From Main module:
Thread1.Start(cpu, execute, args) sub not found
Thread1.Start(null, cpu.execute, args) sub not found
Thread1.Start(cpu, cpu.execute) sub not found

I've also tried creating the thread from within my hd6809 class which also fails.

I feel like a putz... I actually keep struggling at hyper speed right after some of my questions, so I now have my cpu thread running which is initialized and started from within my cpu instance. I removed all references to threading from my main module and it seems to be working, but I'll give updates later.
 

Roger Taylor

Member
Licensed User
Longtime User
I still would like to see what's available from all other languages, an include/use directive. This would be terribly simple to implement if the designers are willing.
 

kimstudio

Active Member
Licensed User
Longtime User
I think in B4X each file can only have one class, as file/module name is the class name, so "include" will need huge design change and at least I am totally fine with current design.

Thread1.Start(cpu, execute, args) sub not found
Thread1.Start(null, cpu.execute, args) sub not found
Thread1.Start(cpu, cpu.execute) sub not found

I tried this also in B4J and it doesn't work. It seems the sub name in string format here will be only searched in current module to see if the sub exists, even the first parameter is set to the object of a class instance. It will not search the sub in the class module. It should be supported as mentioned in the threading lib help?

However, as alternative I am fine to make a sub in current module to be called by thread.start and call another module.sub in this sub.
 

agraham

Expert
Licensed User
Longtime User
It should be supported as mentioned in the threading lib help?
The Threading library far predates the availability of class modules and Erel now deprecates its use as he has built asynchronism into most libraries that would benefit from it.

Thread.Start searches for Subs in the ProcessBA that is passed to it by the IDE in a hidden parameter in Initialize and can do nothing other than that. I haven't tested it but if you call Initialize in the class instance then it might search the class for Subs but it depends upon which ProcessBA is passed to it.
 

Roger Taylor

Member
Licensed User
Longtime User
"Include" wouldn't be meant to insert other classes but rather code that is hard to maintain as the main code grows. For example you should be able to cut out all your subs that deal with sound and place them in a sounds.bas file then use Include Sound.bas somewhere in your main code. Maybe Include is the wrong directive to use but the name doesn't matter. It would not require a major design change since the source code file reader just needs to break away to another file temporarily then resume loading the parent file.
 

kimstudio

Active Member
Licensed User
Longtime User
Thread.Start searches for Subs in the ProcessBA that is passed to it by the IDE in a hidden parameter
That's far beyond my understanding of internal mechanism of B4X. I am totally fine to call local subs using the threading lib, which I used to exploit for most of my B4J apps. Now I found "sleep(0)" works also very well and sometimes can be a replacement.
 
Top