The AddProperty method adds a property to the Application object. This is useful if you need to store a custom value for use within Stonefield Query and retrieve it for any purpose.
Syntax
AddProperty(PropertyName as String [, Value as Variant])
Parameters
PropertyName
The name of the property. This must be a unique name, must start with a letter, and can only contain letters, digits, or underscores.
Value
The value to store in the property. This parameter is optional; if it isn't specified, the property is set to False.
Return Value
None.
Example
Suppose the Select script a table uses needs to know if the user is filtering on the CUSTOMERS.TYPEID field (perhaps it has to look up values in another table). The DataEngine.FilterChanged script could store the value the user is filtering on in a property of the Application object the Select script uses.
Visual FoxPro
lparameters toApplication as SQApplication
local loFilters, lnI, loCondition, liType
loFilters = toApplication.DataEngine.FilterConditions
for lnI = 1 to loFilters.Count
loCondition = loFilters.Item(lnI)
if loCondition.FieldName = 'CUSTOMERS.TYPEID'
liType = loCondition.Values.Item(1)
toApplication.AddProperty('CustomerTypeFilter', ;
liType)
endif
next
VBScript
function Main(Application)
dim Filters, Condition
set Filters = Application.DataEngine.FilterConditions
for I = 1 to Filters.Count
set Condition = Filters.Item(lnI)
if Condition.FieldName = "CUSTOMERS.TYPEID"
TypeID = Condition.Values.Item(1)
Application.AddProperty("CustomerTypeFilter", _
TypeID)
end if
next
end function
JavaScript
function Main(Application, SelectStatement) {
var Filters, I, Condition, TypeID ;
Filters = Application.DataEngine.FilterConditions ;
for (I = 1; I <= Filters.Count; I++) {
Condition = Filters.Item(lnI) ;
if (Condition.FieldName = 'CUSTOMERS.TYPEID') {
TypeID = Condition.Values.Item(1) ;
Application.AddProperty('CustomerTypeFilter',
TypeID) ;
}
}
}
C#
public static void DataEngine_FilterChanged(SFQApplication sfqApplication)
{
FilterConditions filters = sfqApplication.DataEngine.FilterConditions;
for (int i = 1; i < filters.Count; i++)
{
FilterCondition condition = filters.Item(i);
if (condition.FieldName == "CUSTOMERS.TYPEID")
{
string typeID = (string)condition.Values.Item(0).Value;
SQApplication.AddProperty("CustomerTypeFilter", typeID);
}
}
}
VB.NET
public shared function DataEngine_FilterChanged(sfqApplication as SFQApplication)
as Boolean
Dim filters as FilterConditions = sfqApplication.DataEngine.FilterConditions
for i As Integer = 1 To filters.Count
Dim condition as FilterCondition = filters.Item(i)
if condition.FieldName = "CUSTOMERS.TYPEID"
Dim typeID as string = condition.Values.Item(0).Value
SQApplication.AddProperty("CustomerTypeFilter", typeID)
End If
Next
return True
end function
Special note on custom SFQApplication properties when using C# or VB.NET
When using C# or VB.NET as your scripting language, you can retrieve custom SFQApplication properties (that you added via SFQApplication.AddProperty()) using the SFQApplication.GetProperty() method. You can set the value of a custom property using SFQApplication.SetProperty().
If your custom property is an object (COM or .NET), you can call methods of it using ReflectionService.CallMethod(), set properties of it using ReflectionService.SetProperty(), and get properties from it using ReflectionService.GetProperty().
See the COMScriptTest script below as an example of using these methods.
public static object COMScriptTest(string param1, bool param2)
{
// Retrieve custom SFQApplication Property
object oCOMObject = SQApplication.GetProperty("oCOMObject");
// Call method of custom SFQApplication Property
string result = (string)ReflectionService.CallMethod(oCOMObject, "MethodName",
param1, param2);
MessageBox.Show(result);
// Get property of custom SFQApplication Property
bool boolProperty = (bool)ReflectionService.GetProperty(oCOMObject, "BoolProperty");
// Set property of custom SFQApplication Property
ReflectionService.SetProperty(oCOMObject, "BoolProperty", false);
// Set value of custom SFQApplication Property
SQApplication.SetProperty("oCOMObject", null);
return boolProperty;
}
The same script in VB.NET would be:
public shared function COMScriptTest(param1 as String, param2 as Boolean) as object
' Retrieve custom SFQApplication Property
Dim oCOMObject as Object = SQApplication.GetProperty("oCOMObject")
' Call method of custom SFQApplication Property
Dim result as String = ReflectionService.CallMethod(oCOMObject, "MethodName",
param1, param2)
MessageBox.Show(result)
' Get property of custom SFQApplication Property
Dim boolProperty as Boolean = ReflectionService.GetProperty(oCOMObject,
"BoolProperty")
' Set property of custom SFQApplication Property
ReflectionService.SetProperty(oCOMObject, "BoolProperty", false)
' Set value of custom SFQApplication Property
SQApplication.SetProperty("oCOMObject", Nothing)
return boolProperty
End Function
See also
Application Object© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic