Running Descriptive Statistics in Delphi

This example will open Statistica from a main dialog. You then can select a spreadsheet from an Open File dialog and Statistica will run descriptive statistics on the data set.

unit MainForm;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComObj;

type

TIDD_MAIN_FORM = class(TForm) IDC_DISPLAY_SPREADSHEET: TButton; OpenDialog: TOpenDialog; IDC_BASIC_STATS: TButton; procedure IDC_DISPLAY_SPREADSHEETClick(Sender: TObject); procedure IDC_BASIC_STATSClick(Sender: TObject); procedure FormActivate(Sender: TObject);

private

{ Private declarations } m_StatApp: Variant; m_Dataset: Variant;

public

{ Public declarations }

end;

var IDD_MAIN_FORM: TIDD_MAIN_FORM;

implementation

{$R *.dfm}

{make running instance of Statistica visible}

procedure TIDD_MAIN_FORM.IDC_DISPLAY_SPREADSHEETClick(Sender: TObject);

begin

m_StatApp.Visible := true; {Create a new spreadsheet} m_Dataset := m_StatApp.Spreadsheets.New(''); m_Dataset.Visible := true;

end;

procedure TIDD_MAIN_FORM.IDC_BASIC_STATSClick(Sender: TObject);

var FilePath: AnsiString; var newanalysis: Variant;

begin

{Prompt user for a dataset to open} OpenDialog.Title := 'Open Dataset';

if OpenDialog.Execute then FilePath := OpenDialog.FileName;

{display Statistica} m_StatApp.Visible := true;

{Open spreadsheet} m_DataSet := m_StatApp.Spreadsheets.Open(FilePath,true);

{create a basic stats dialog} newanalysis := m_StatApp.Analysis($00000515,m_DataSet);

newanalysis.Run; newanalysis.Dialog.Variables := '1'; newanalysis.Dialog.Mode := true; newanalysis.Dialog.Summary[0].Visible := true;

end;

{called when appliation initializes} procedure TIDD_MAIN_FORM.FormActivate(Sender: TObject);

begin

{initialize an instance of Statistica transparently} m_StatApp := CreateOleObject('Statistica.Application');

end;

end.