On May 28, 2004, at 11:27 PM, GAmoore at aol dot com wrote:
This is sort of related to my last question. I want to make a
"Settings"
folder in the same locale as the application - if it doesn't exist
create, if it
does exist, then put files into it. I'm a little confused as to the
create/connection distinction in this case. Similarly, with databases
.... I read the
examples for creating a new database or opening an existing one.
However, how can
you open it if it exists, create it if it does not exist? Here is my
attempt
Creating a Settings folder is very simple. Here's what I would do. I'd
define a function SettingsFolder() as FolderItem, probably as a
function of the Application class, as follows.
Function SettingsFolder() as FolderItem
dim appFolder as FolderItem
dim theSettingsFolder as FolderItem
appFolder = GetFolderItem("")
If appFolder Is Nil or NOT appFolder.Exists then //something really
odd has happened
Return Nil
End if
theSettingsFolder = appFolder.Child("Settings")
If theSettingsFolder Is Nil then //you may have a permissions problem
Return Nil
End if
If theSettingsFolder.Exists then
If theSettingsFolder.Directory then
Return theSettingsFolder
Else //you could handle this case differently; for instance, you
might want to alert the user
Return Nil
End if
Else //try to create it
theSettingsFolder.CreateAsFolder
Return theSettingsFolder
End if
End Function
Of course you'll still need to check the return value of this function
when you call it, because it can fail, as the code above suggests.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|