Wish - shared code between projects

francoisg

Active Member
Licensed User
Longtime User
Hi,
is it possible to share code (code modules?) between projects WITHOUT each project having it's own copy of the code (maybe a shared code library of some kind).

The reason is that with code modules you can do quite a lot (generic / utility functions etc) but if you want to use the code again (in another project), B4A makes a copy of the file to the new project.

If you now need to change anything in the original code module (bug fix / additional subs etc), it has to change in both files!

Does anyone have an available solution to this problem (other than creating a java lib)?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I was thinking the same thing actually!

The easiest way to do this would be to have a shared directory of BAS files, and it just copies references BAS files from it when the project loads, and copies it back when it saves.
 

francoisg

Active Member
Licensed User
Longtime User
Would be easier if we were able to "include" files located in another directory (only 1 copy per file, NOT multiple copies all over the show), NOT in the project directory (kind-of link "units" in Delphi) ...

So what do you think Erel, possible ???
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Well the program might be set up to only accept things all in one folder to work with eclipse. My method would result in many copies, but they'd all be identical cause they'd sync with the ones in the library folder. It would be the easiest method if there are limitations he has to work with.

He'd just have to make it monitor for changes in case their are multiple instances of the program open.
 

stevel05

Expert
Licensed User
Longtime User
Is it not possible to set up something with SVN to achieve this?
 

francoisg

Active Member
Licensed User
Longtime User
Well, either way - if someone knows of a possible solution it would be great! Getting tired of manually syncing my files every time I update a code module that is used in more than one project!
 

Jost aus Soest

Active Member
Licensed User
Longtime User
Workaround with Hard Links

I've tried to use hard links to make a "referencial copy" of a reused module - and it works! :cool:

Now I can change my Util module in project 1 and when I later continue to work with project 2, my reused Util module shows all my changes.

I've used the WindowsXP shell command fsutil as described in the german Wikipedia:
Harter Link @ Wikipedia

Example: Start the shell and go to the directory with the original module, than enter:
B4X:
fsutil hardlink create "..\NewProject\Utils.bas" "Utils.bas"
OK, it's not very comfortable, because you have to use the shell, so:

@Erel
It would be very helpful (using "Add Existing Module") to let the user choose, if he really wants a copy (like now) or a reference (via hard link).

Please, please, please, ... :)
 

touchsquid

Active Member
Licensed User
Longtime User
This is a badly needed feature. In the meantime one could write a batch file to copy the shared code to all places it is used, and do all your editing on the "Master". Of course you would have to remember to run the batch file after each edit.
 

francoisg

Active Member
Licensed User
Longtime User
Maybe the IDE could provide us with a "build procedure" per project where we can instruct the compiler to 1'st run the batch file automatically etc. before the actual compile starts? Also, we should be able to have some "pre-compiler" options where we can maybe do thing like "include" code by compiler directives maybe (conditional compiling would also be nice?)?
 

rbsoft

Active Member
Licensed User
Longtime User

Woinowski

Active Member
Licensed User
Longtime User
+1

I vote for that, too. Would also make it easier to maintain free/lite/pro versions
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Count me in too. I'd also like to see Process Globals handled better and/or in a manner like shared files- They are Global to the process, but declared and referenced in/by each of the Activities which doesn't seem right. I'd picture globals shown in a split window more like the sections in Designer Scripts where they are in another global file so we don't need activityname.globalvar stuff.
 

stevel05

Expert
Licensed User
Longtime User
I wanted to try out Jost aus Soest idea of hardlinks, which is apparently mklink on Win 7, but I came across this, which provides right click functionality (still a little long-winded but better than command line) that is supposed to work with most Windows OS's. Just in case it's useful to you. It works as far as I've tried it.

It's hosted by softpedia, so should be as safe as freeware/shareware gets.
 

rbsoft

Active Member
Licensed User
Longtime User
@stevel05
I was just gonna write a little wrapper in PB for 'fsutil hardlink create' when I found this tool too. Works exellent.

Rolf
 

JohnC

Expert
Licensed User
Longtime User
+100 for adding a "Reference" to an existing code module instead of copying/fragmentation (current) method.
 
Top