Parent.Child problem

Trying to get a folderitem and have same code in a Web and Desktop application. The Web app. works ok in both debug and live.

Both project file are in the same folder. The target file (database) is located in a folder within a folder in the project folder.

f = App.ExecutableFile.Parent.Parent.Child("Databases").Child("rvcare.db")

The desktop app get a nil.

Should not both web and DT work the same?

Not necessarily. Typically I use #if TargetDesktop and targetWeb and have two different paths. I believe the web app is nested another layer deep than the desktop.

You can easily tell what the difference is by putting a breakpoint in after f is defined and then look at the path in the variables pane. I also tend to put some defensive code in to break if something is missing:

if f = nil or f.exists = false then break //bad paths return end

Depending on what I’m doing I may have to make further distinctions between Debug and non-debug with #if DebugBuild.

In this case it is unlikely that you’ll be able to use the same code for web and desktop. I would advise against storing your data next to the .app as this is not acceptable on Mac.

Store the data in your apps resources folder, you can keep it in the databases sub directory if you wish.

I have a module that makes accessing the resources folder easy, crossplatform, and future resistant when using old framework folderitems. Otherwise, the new framework provides access to the resources folder.

remember… any resource stored INSIDE the application (EXE or APP bundle) are READ-ONLY, attempts to write to these will usually break the app in some manner.

I had assumed it was a defaults database. Dave is right, so if it’s your users data then you’ll need to store it in a subfolder in SpecialFolder.ApplicationData to be writable.

Well, if he uses AppData that would not be an issue. Otherwise if Desktop is on Mac and Web on Linux it is definitely not the same.

Instead of

f = App.ExecutableFile.Parent.Parent.Child("Databases").Child("rvcare.db")

Which is Mac only, I would rather recommend using :

f = GetFolderItem("").Child("Databases").Child("rvcare.db")

Which will reliably point next to the .app on Mac and next to the Linux executable.

This isn’t related to the rest of the thread, but it’s a pet peeve. Passing an empty string to GetFolderItem followed by a call to Child is inefficient and an anti-pattern. Just pass the “Databases” string directly to GetFolderItem.

f = GetFolderItem("Databases").Child("rvcare.db")


Thanks all.

Sorry for the slow response, had to attend to an emergency.

Michel solution work like a champ, thanks.

I fail to mention that subject application is a personal app. and more than like only be run in debug mode. So I get to break a few rules/standards.