Programming STATISTICA From Net
Programming STATISTICA From Net
data mining
quality control
web-based analytics
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com
distributing the application, make sure the correct version of the STATISTICA Interop DLL is deployed
with your .NET application.
For any other STATISTICA libraries, such as STATISTICAGraphics or the various analytical modules, it is
possible to maintain a single Interop DLL generated from the lowest version number of STATISTICA that
you need to support. You can use the TLBIMP.EXE utility to generate the Interop DLL from the older
version number DLL (such as STA_MGRA.DLL in the case of STATISTICAGraphics). The generated
Interop should then be added as a reference to the .NET project (as opposed to the traditional approach
of adding a reference to the COM library and letting VS.NET create the Interop DLL automatically).
Instantiating STATISTICA
Because of its COM architecture, STATISTICA can be incorporated into many different development
environments. When using STATISTICA from an external development environment, it is necessary to
have a top level object called the application object. The application object is the application itself and will
contain other objects (for example, spreadsheets and graphs), but access to these other objects is
restricted unless the application object is running.
Assuming you are using the default namespace STATISTICA, the interface you should declare your
variable as is STATISTICA.Application. To create an instance of STATISTICA, set your variable equal to
a new STATISTICA.ApplicationClass().
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com
Threading
Both the Library and Application versions of STATISTICA use the single threaded apartment model.
Multiple threads accessing an instance of the STATISTICA COM interface will queue until previous
requests are processed. The architecture of STATISTICA is best suited to process requests from one
thread at a time.
Optimum performance of the library version occurs when accessed from an STA. Without it, COM calls
must marshal across threads. This is immaterial for using the Application object where all calls must be
marshaled out of process.
Creating New STATISTICA Documents
When creating a STATISTICA document such as a new Spreadsheet or Workbook object, you should not
instantiate a new instance of that document class. For example, for spreadsheets there is a
STATISTICA.SpreadsheetClass that you can use from .NET as shown in the example below:
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com
This can be problematic when copying recorded analysis macros and adding them to the C# code. The
recommended way to work around this is to define constant integers that represent True and False.
const int True = 1;
const int False = 0;
Default Parameters in C#
Default parameters dont default in C#. When calling a method, you must always specify all parameters.
In C# you can pass the parameter Type.Missing, which is equivalent to omitting the parameter in
languages such as VB/VB.NET.
Garbage Collection in .NET
In languages such as VB 6 and SVB, garbage collection is deterministic. When all references to an object
are released, the object is immediately removed from memory. However, in .NET, garbage collection is
only performed when necessary as part of a garbage collection process. Setting an object equal to
nothing just flags the object for later garbage collection. In situations where you need deterministic
releasing of the object, it is possible to force the objects release by using the ReleaseComObject
method. Calling ReleaseComObject decrements a COM objects reference count directly.
In the example above, the ReleaseComObject method is called in a loop that executes until the value
returned equals 0. This is because the ReleaseComObject method decrements the reference count by
one, so if the reference count was greater than 1 to begin with, you need to call the method multiple times
in order to release all references.
Tulsa, OK 74104
USA
(918) 749-1119
www.statsoft.com