REALBasic Child FolderItem Should Be a Directory Also
I have a bunch of Realbasic code that was written on a Mac that I'm supposed to port to Windows. Right now let's just try to get the program running from within REAL Studio. GetFolderItem("") returns the folder the application is in. Child("A") returns another FolderItem how I would开发者_如何转开发 expect. But when I call Child("B") on A it returns a FolderItem with False set for the Directory property. But B is a folder on my Windows! So now it won't let me get a Child of B, it just returns nil. This code worked fine on MacOSX. Any suggestions?
Thanks in advance, Me
I suspect you're not in the directory that you think you are. Try looking at the path in the debugger to see if the debugger is looking in the same place you are.
It's a common issue when dealing with Mac vs Windows in RB. On the Mac, many things are placed in the bundle folder so that there are no external files/directories and since Windows has no equivalent, people get confused as to what path they're in.
BTW, you don't need to use GetFolderItem("") first. You can simply use GetFolderItem("A") because you're it defaults to the directory the App is in.
Often I prefer to use this code. It is much self explaining and avoids that common mistake.
dim base as folderitem = App.ExecutableFile.Parent
#if DebugBuild = true then
base = App.ExecutableFile.Parent.Parent
#endif
dim target as folderitem = base.Child("A").Child("B")
You can also put it in a function to reuse.
精彩评论