Obtain source filename?

The code below will obtain the filename of the application executable file.
Is there any way to obtain the filename of the source file that is being compiled?

	#if DebugBuild then 
			Dim f as FolderItem
			Dim appIDEFileName as String
			f = App.ExecutableFile
			appIDEFileName = f.NativePath

No, since if the project is a binary one or XML there is only one giant file. You’re probably better off using CurrentMethodName:

http://developer.xojo.com/compiler-constants

Yes, one big SomeNameHere.xojo_binary_project file … which is what I’d like to find a way to retrieve the name of. I’m aware of CurrentMethodName.

You could create a constant that gets updated when you build using a build step.

Let’s say you have a string or text constant in the App class named ProjectName. The script might look like this on Mac:

Dim sa() as String = Split(ProjecShellPath, “/“) ConstantValue(“App.ProjectName”) = sa(ubound(sa))

Excellent. This is exactly the kind of thing I was looking for. Now the problem is getting it to work right.

If in the script I have checked the OS X box and set the contained script for Applies to “Both” ( Debug and Release ). I then have in the build script:

ConstantValue( "App.someConstant" ) = "some text" 

and if App.someConstant has no default value, then apparently when the script is run at build time, the empty default value is changed to “some text” and all is well. However if I change “some text” to “different text” in the script and run the build again, then the previous non-empty default value of “some text” remains the value of App.someConstant.

Any suggestions?

I’ve also tried the following script, but it does not help:

ConstantValue( "App.someConstant" ) = "" ConstantValue( "App.someConstant" ) = "different text"

You need to do an “IDE Communicator” script. There should be an example in the example folder. The following code is part of a script that builds a couple of applications:

openfile(basePath + "code\\ current/max\\ scheduler.rbp") ConstantValue("App.kMaxVersion") = theVersion if ConstantValue("App.kMaxVersion") = "0" then PropertyValue("App.Application Identifier") = "com.mothsoftware.mailarchiverx" PropertyValue("App.MacOSXAppName") = "Mail Archiver X " elseif ConstantValue("App.kMaxVersion") = "1" then PropertyValue("App.Application Identifier") = "com.mothsoftware.mailarchiverpro" PropertyValue("App.MacOSXAppName") = "Mail Archiver X Pro " else print ConstantValue("App.kMaxVersion") end if Call BuildApp(16) DoCommand "SaveFile" DoCommand("CloseWindow")

[quote=394716:@Ed Kleban]Excellent. This is exactly the kind of thing I was looking for. Now the problem is getting it to work right.

If in the script I have checked the OS X box and set the contained script for Applies to “Both” ( Debug and Release ). I then have in the build script:

ConstantValue( "App.someConstant" ) = "some text" 

and if App.someConstant has no default value, then apparently when the script is run at build time, the empty default value is changed to “some text” and all is well. However if I change “some text” to “different text” in the script and run the build again, then the previous non-empty default value of “some text” remains the value of App.someConstant.

Any suggestions?[/quote]
I can’t confirm that. No matter what I set it to, when I run or build, the constant gets set. How are you checking the new value?

Small test app with a pushbutton and a text field. When you push the button it reads value of the App constant and shoves it into the text field:

taDisplay.text = "" taDisplay.AppendText "ProjectShellPath: " + App.buildSourcePath

in the script:

Dim sa as String = ProjectShellPath ConstantValue("App.buildSourcePath") = sa

It’s possible that it’s a Xojo version difference. I just started coding again and my Xojo version is 2016 Release 4.1

ProjectShellPath has been there since 2015 at least. Have you saved your test project though? If not, it returns an empty string.

Saving the project might very well be the tripwire I was stumbling over… so let’s say sure; it works now.

However there is another bizarre behavior that does affect it. The whole intent here is to get the name of the source file. So things are working well; I quit my running debug app; and I save the project under a new filename. It’s saved. But if I now run my project in debug, it does not get the current project filename, but rather the last. Running it causes the project to become “unsaved”. So I then do an explicit save… and then all works as expected.

A little non-intuitive, but I can live with that; especially since I most care about the correctness in the compiled build.

Thanks so much for your help.

Make sure this step is before the “build” step, not after.

Yep. That seems to fix it all. Thanks for the great advice.