The first time the user runs Stonefield Query, it prompts them to specify where they want Stonefield Query's data files stored. Stonefield Query doesn't care where these files are located, but you might. For example, one of the Stonefield Query data files is called SECURITY.DBF. If your application also has a file called SECURITY.DBF, you don't want the user to pick your application directory as the location for Stonefield Query's file, since those two files would collide and likely cause errors in Stonefield Query, your application, or both. To ensure the user selects a directory that won't cause such a problem, create some code for the Application.ValidateCommonAppDir script, such as checking for the existence of one of the target application's files. Return False from the script if the selected directory is invalid. You can control the warning message displayed to the user if the directory is invalid by setting the Message for Invalid Directory property.

Parameters
A reference to the Stonefield Query Application object and the directory chosen by the user (terminated with a backslash).

Return Value
True if the directory the user selected is acceptable.

Example
Here's an example that checks if SECURITY.DBF exists in the directory the user selected.

Visual FoxPro

lparameters toApplication as SQApplication, tcDirectory
return not file(tcDirectory + 'security.dbf')

VBScript

function Main(Application, Directory)
dim fso
set fso = CreateObject("Scripting.FileSystemObject")
Main = not (fso.FileExists(Directory & "security.dbf"))
end function

JavaScript

function Main(Application, Directory) {
var fso, Found ;
fso = new ActiveXObject('Scripting.FileSystemObject') ;
Found = ! (fso.FileExists(Directory + 'security.dbf')) ;
return Found ;
}

C#

Please note that the method in this script must be named Application_ValidateCommonDir.

public static bool Application_ValidateCommonDir(SFQApplication sfqApplication, string directory)
{
  return !File.Exists(directory + "security.dbf");
}

VB.NET

Please note that the method in this script must be named Application_ValidateCommonDir.

public shared function Application_ValidateCommonDir(sfqApplication as SFQApplication, directory as string) as Boolean
  return Not File.Exists(directory + "security.dbf")
End Function

See also

Application.ValidateTargetAppDir | Message for Invalid Directory | Scripts

© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic