You've already forked lazarus-ccr
LazStats: Make grid-related procedures in DataProcs needed by CrossTabUnit independent of MainForm. Clean-up.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7713 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -67,6 +67,7 @@ uses
|
|||||||
Math, Grids,
|
Math, Grids,
|
||||||
Utils, DictionaryUnit;
|
Utils, DictionaryUnit;
|
||||||
|
|
||||||
|
|
||||||
{ TCrossTabCalculator }
|
{ TCrossTabCalculator }
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -90,10 +91,6 @@ type
|
|||||||
function IndexPosition(x: IntDyneVec): integer;
|
function IndexPosition(x: IntDyneVec): integer;
|
||||||
procedure Tabulate;
|
procedure Tabulate;
|
||||||
|
|
||||||
function GoodRecord(Row, NoVars: integer; const GridPos: IntDyneVec): boolean;
|
|
||||||
function IsFiltered(GridRow: integer): boolean;
|
|
||||||
function ValidValue(row, col: integer): boolean;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
procedure Execute(AReport: TStrings; ADataGrid: TStringGrid;
|
procedure Execute(AReport: TStrings; ADataGrid: TStringGrid;
|
||||||
AVarList, AColNoSelected: IntDyneVec);
|
AVarList, AColNoSelected: IntDyneVec);
|
||||||
@ -235,13 +232,13 @@ begin
|
|||||||
for i := 1 to no_in_list do
|
for i := 1 to no_in_list do
|
||||||
begin
|
begin
|
||||||
j := FVarList[i-1];
|
j := FVarList[i-1];
|
||||||
if not GoodRecord(1, NoSelected, FColNoSelected) then continue;
|
if not GoodRecord(FDataGrid, 1, NoSelected, FColNoSelected) then continue;
|
||||||
value := StrToFloat(FDataGrid.Cells[j, 1]);
|
value := StrToFloat(FDataGrid.Cells[j, 1]);
|
||||||
min_value[i-1] := round(value);
|
min_value[i-1] := round(value);
|
||||||
max_value[i-1] := round(value);
|
max_value[i-1] := round(value);
|
||||||
for k := 2 to NoCases do
|
for k := 2 to NoCases do
|
||||||
begin
|
begin
|
||||||
if not GoodRecord(k, NoSelected, FColNoSelected) then continue;
|
if not GoodRecord(FDataGrid, k, NoSelected, FColNoSelected) then continue;
|
||||||
value := StrToFloat(FDataGrid.Cells[j, k]);
|
value := StrToFloat(FDataGrid.Cells[j, k]);
|
||||||
if value < min_value[i-1] then
|
if value < min_value[i-1] then
|
||||||
min_value[i-1] := round(value);
|
min_value[i-1] := round(value);
|
||||||
@ -267,21 +264,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TCrossTabCalculator.GoodRecord(Row, NoVars: integer;
|
|
||||||
const GridPos: IntDyneVec): boolean;
|
|
||||||
var
|
|
||||||
i, j: integer;
|
|
||||||
begin
|
|
||||||
Result := true;
|
|
||||||
for i := 0 to NoVars-1 do
|
|
||||||
begin
|
|
||||||
j := GridPos[i];
|
|
||||||
if not ValidValue(Row, j) then
|
|
||||||
Result := false;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function TCrossTabCalculator.IndexPosition(x: IntDyneVec): integer;
|
function TCrossTabCalculator.IndexPosition(x: IntDyneVec): integer;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
@ -295,12 +277,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TCrossTabCalculator.IsFiltered(GridRow: integer): boolean;
|
|
||||||
begin
|
|
||||||
Result := FilterOn and (Trim(FDataGrid.Cells[FilterCol,GridRow]) = 'NO');
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TCrossTabCalculator.Tabulate;
|
procedure TCrossTabCalculator.Tabulate;
|
||||||
var
|
var
|
||||||
i, j, k: integer;
|
i, j, k: integer;
|
||||||
@ -337,128 +313,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TCrossTabCalculator.ValidValue(row, col: integer): boolean;
|
|
||||||
var
|
|
||||||
valid: boolean;
|
|
||||||
xvalue: string;
|
|
||||||
cellstring: string;
|
|
||||||
begin
|
|
||||||
valid := true;
|
|
||||||
if FilterOn then
|
|
||||||
begin
|
|
||||||
cellstring := Trim(FDataGrid.Cells[FilterCol, row]);
|
|
||||||
if cellstring = 'NO' then valid := false;
|
|
||||||
Result := valid;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
xvalue := Trim(FDataGrid.Cells[col, row]);
|
|
||||||
if (xvalue = '') and (DictionaryFrm.DictGrid.Cells[4, col] <> 'S') then
|
|
||||||
valid := false;
|
|
||||||
if valid then // check for user-defined missing value
|
|
||||||
begin
|
|
||||||
if Trim(DictionaryFrm.DictGrid.Cells[6, col]) = xvalue then
|
|
||||||
valid := false;
|
|
||||||
end;
|
|
||||||
Result := valid;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ TCrossTabFrm }
|
{ TCrossTabFrm }
|
||||||
(*
|
|
||||||
procedure TCrossTabFrm.BreakDown(AReport: TStrings);
|
|
||||||
label 1,2,3,4, printgrid;
|
|
||||||
var
|
|
||||||
i, j, row, col, bigmax: integer;
|
|
||||||
outline: string;
|
|
||||||
value: string;
|
|
||||||
title: String;
|
|
||||||
begin
|
|
||||||
bigmax := -1;
|
|
||||||
for i := 0 to no_in_list-1 do
|
|
||||||
if Levels[i] > bigmax then bigmax := Levels[i];
|
|
||||||
|
|
||||||
SetLength(colLabels,bigmax);
|
|
||||||
SetLength(outgrid,length_array,bigmax);
|
|
||||||
SetLength(rowlabels,length_array);
|
|
||||||
outline := OS3MainFrm.DataGrid.Cells[var_list[no_in_list-1], 0];
|
|
||||||
for col := 1 to Levels[no_in_list-1] do
|
|
||||||
collabels[col-1] := outline + Format(':%3d', [min_value[no_in_list-1] + col - 1]);
|
|
||||||
for row := 1 to length_array do
|
|
||||||
rowlabels[row-1] := '';
|
|
||||||
ptr1 := no_in_list - 1;
|
|
||||||
ptr2 := no_in_list;
|
|
||||||
for i := 1 to no_in_list do
|
|
||||||
subscript[i-1] := 1;
|
|
||||||
|
|
||||||
AReport.Add('FREQUENCIES BY LEVEL:');
|
|
||||||
sum := 0;
|
|
||||||
col := 1;
|
|
||||||
row := 1;
|
|
||||||
|
|
||||||
1:
|
|
||||||
index := IndexPosition(subscript);
|
|
||||||
outline := 'For cell levels: ';
|
|
||||||
for i := 1 to no_in_list do
|
|
||||||
begin
|
|
||||||
j := var_list[i-1];
|
|
||||||
value := Format('%s:%3d ',[OS3MainFrm.DataGrid.Cells[j,0], min_value[i-1] + subscript[i-1] - 1]);
|
|
||||||
outline := outline + value;
|
|
||||||
end;
|
|
||||||
sum := sum + freq[index];
|
|
||||||
outgrid[row-1,col-1] := freq[index];
|
|
||||||
outline := outline + Format(' Frequency = %3d', [freq[index]]);
|
|
||||||
AReport.Add(outline);
|
|
||||||
|
|
||||||
subscript[ptr2-1] := subscript[ptr2-1] + 1;
|
|
||||||
col := col + 1;
|
|
||||||
if subscript[ptr2-1] <= levels[ptr2-1] then
|
|
||||||
goto 1;
|
|
||||||
|
|
||||||
AReport.Add('Sum across levels = %3d', [sum]);
|
|
||||||
AReport.Add('');
|
|
||||||
AReport.Add('');
|
|
||||||
|
|
||||||
grandsum := grandsum + sum;
|
|
||||||
sum := 0;
|
|
||||||
row := row + 1;
|
|
||||||
|
|
||||||
2:
|
|
||||||
if ptr1 < 1 then
|
|
||||||
goto printgrid;
|
|
||||||
|
|
||||||
subscript[ptr1-1] := subscript[ptr1-1] + 1;
|
|
||||||
if subscript[ptr1-1] <= levels[ptr1-1] then
|
|
||||||
goto 4;
|
|
||||||
|
|
||||||
3:
|
|
||||||
ptr1 := ptr1 - 1;
|
|
||||||
if ptr1 < 1 then
|
|
||||||
goto printgrid;
|
|
||||||
if subscript[ptr1-1] >= levels[ptr1-1] then
|
|
||||||
goto 3;
|
|
||||||
subscript[ptr1-1] := subscript[ptr1-1] + 1;
|
|
||||||
|
|
||||||
4:
|
|
||||||
for i := ptr1 + 1 to no_in_list do
|
|
||||||
subscript[i-1] := 1;
|
|
||||||
ptr1 := no_in_list - 1;
|
|
||||||
col := 1;
|
|
||||||
|
|
||||||
goto 1;
|
|
||||||
|
|
||||||
printgrid:
|
|
||||||
title := 'Cell Frequencies by Levels';
|
|
||||||
for i := 1 to row - 1 do
|
|
||||||
begin
|
|
||||||
value := format('Block %d',[i]);
|
|
||||||
rowlabels[i-1] := value;
|
|
||||||
end;
|
|
||||||
|
|
||||||
MatPrint(outgrid,row-1,Levels[no_in_list-1],title,rowlabels,collabels,NC, AReport);
|
|
||||||
end; { Procedure BREAKDOWN }
|
|
||||||
*)
|
|
||||||
|
|
||||||
procedure TCrossTabFrm.CloseBtnClick(Sender: TObject);
|
procedure TCrossTabFrm.CloseBtnClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
@ -6,10 +6,12 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||||
StdCtrls, ExtCtrls, Clipbrd,
|
StdCtrls, ExtCtrls, Clipbrd, Grids,
|
||||||
Globals, OptionsUnit, DictionaryUnit;
|
Globals, OptionsUnit, DictionaryUnit;
|
||||||
|
|
||||||
Function GoodRecord(Row, NoVars: integer; const GridPos: IntDyneVec): boolean;
|
Function GoodRecord(Row, NoVars: integer; const GridPos: IntDyneVec): boolean; overload;
|
||||||
|
Function GoodRecord(AGrid: TStringGrid; Row, NoVars: integer; const GridPos: IntDyneVec): boolean; overload;
|
||||||
|
|
||||||
procedure FormatCell(Col, Row : integer);
|
procedure FormatCell(Col, Row : integer);
|
||||||
procedure FormatGrid;
|
procedure FormatGrid;
|
||||||
function IsNumeric(s : string) : boolean;
|
function IsNumeric(s : string) : boolean;
|
||||||
@ -27,8 +29,10 @@ procedure CopyRow;
|
|||||||
procedure PasteRow;
|
procedure PasteRow;
|
||||||
procedure PrintDict(AReport: TStrings);
|
procedure PrintDict(AReport: TStrings);
|
||||||
procedure PrintData(AReport: TStrings);
|
procedure PrintData(AReport: TStrings);
|
||||||
function ValidValue(row, col: integer): boolean;
|
function ValidValue(row, col: integer): boolean; overload;
|
||||||
function IsFiltered(GridRow: integer): boolean;
|
function ValidValue(AGrid: TStringGrid; row, col: integer): boolean; overload;
|
||||||
|
function IsFiltered(GridRow: integer): boolean; overload;
|
||||||
|
function IsFiltered(AGrid: TStringGrid; GridRow: integer): boolean; overload;
|
||||||
|
|
||||||
procedure MatRead(const a: DblDyneMat; out NoRows, NoCols: integer;
|
procedure MatRead(const a: DblDyneMat; out NoRows, NoCols: integer;
|
||||||
const Means, StdDevs: DblDyneVec; out NCases: integer;
|
const Means, StdDevs: DblDyneVec; out NCases: integer;
|
||||||
@ -62,7 +66,13 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Utils, MainUnit;
|
Utils, MainUnit;
|
||||||
|
|
||||||
Function GoodRecord(Row, NoVars: integer; const GridPos: IntDyneVec): boolean;
|
function GoodRecord(Row, NoVars: Integer; const GridPos: IntDyneVec): boolean;
|
||||||
|
begin
|
||||||
|
Result := GoodRecord(OS3MainFrm.DataGrid, Row, NoVars, GridPos);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GoodRecord(AGrid: TStringGrid; Row, NoVars: integer;
|
||||||
|
const GridPos: IntDyneVec): boolean;
|
||||||
var
|
var
|
||||||
i, j: integer;
|
i, j: integer;
|
||||||
begin
|
begin
|
||||||
@ -70,7 +80,7 @@ begin
|
|||||||
for i := 0 to NoVars-1 do
|
for i := 0 to NoVars-1 do
|
||||||
begin
|
begin
|
||||||
j := GridPos[i];
|
j := GridPos[i];
|
||||||
if not ValidValue(Row, j) then
|
if not ValidValue(AGrid, Row, j) then
|
||||||
Result := false;
|
Result := false;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -737,128 +747,6 @@ begin
|
|||||||
OpenSeparatorfile(' ', SSV_FILE_FILTER, 'ssv');
|
OpenSeparatorfile(' ', SSV_FILE_FILTER, 'ssv');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
|
||||||
procedure OpenTabFile;
|
|
||||||
var
|
|
||||||
TabFile : TextFile;
|
|
||||||
namestr : string;
|
|
||||||
s: string;
|
|
||||||
ch: char;
|
|
||||||
labelsinc : boolean;
|
|
||||||
row, col : integer;
|
|
||||||
res: TModalResult;
|
|
||||||
begin
|
|
||||||
Assert(OS3MainFrm <> nil);
|
|
||||||
Assert(OptionsFrm <> nil);
|
|
||||||
|
|
||||||
labelsinc := false;
|
|
||||||
|
|
||||||
// check for a currently open file
|
|
||||||
if NoVariables > 1 then
|
|
||||||
begin
|
|
||||||
MessageDlg('Close (or Save and Close) the current work.', mtWarning, [mbOK], 0);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
OS3MainFrm.OpenDialog1.Filter := 'Tab field files (*.tab)|*.tab;*.TAB|Text files (*.txt)|*.txt;*.TXT|All files (*.*)|*.*';
|
|
||||||
OS3MainFrm.OpenDialog1.FilterIndex := 1;
|
|
||||||
OS3MainFrm.OpenDialog1.DefaultExt := 'tab';
|
|
||||||
if OS3MainFrm.OpenDialog1.Execute then
|
|
||||||
begin
|
|
||||||
res := MessageDlg('Are variable labels included?', mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
|
||||||
if res = mrCancel then
|
|
||||||
exit;
|
|
||||||
labelsInc := (res = mrYes);
|
|
||||||
NoCases := 0;
|
|
||||||
NoVariables := 0;
|
|
||||||
if labelsInc then row := 0 else row := 1;
|
|
||||||
col := 1;
|
|
||||||
|
|
||||||
AssignFile(TabFile, OS3MainFrm.OpenDialog1.FileName); // File selected in dialog box
|
|
||||||
Reset(tabfile);
|
|
||||||
OS3MainFrm.FileNameEdit.Text := OS3MainFrm.OpenDialog1.FileName;
|
|
||||||
s := '';
|
|
||||||
while not EOF(TabFile) do
|
|
||||||
begin
|
|
||||||
Read(TabFile, ch);
|
|
||||||
if (ch < #9) or (ch > #127) then
|
|
||||||
Continue;
|
|
||||||
if (ch = #13) then
|
|
||||||
Continue; // line feed character
|
|
||||||
if (ch <> #9) and (ch <> #10) then // check for tab or new line
|
|
||||||
s := s + ch
|
|
||||||
else if ch = #9 then // tab character found
|
|
||||||
begin
|
|
||||||
if (not labelsinc) and (row = 1) then // create a col. label
|
|
||||||
begin
|
|
||||||
namestr := 'VAR ' + IntToStr(col);
|
|
||||||
OS3MainFrm.DataGrid.Cells[col, 0] := namestr;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.Cells[col, row] := s;
|
|
||||||
if col > NoVariables then
|
|
||||||
begin
|
|
||||||
NoVariables := col;
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
end;
|
|
||||||
col := col + 1;
|
|
||||||
s := '';
|
|
||||||
if col >= OS3MainFrm.DataGrid.ColCount then
|
|
||||||
OS3MainFrm.DataGrid.ColCount := OS3MainFrm.DataGrid.ColCount + 1;
|
|
||||||
end
|
|
||||||
else //must be new line character
|
|
||||||
begin
|
|
||||||
if (not labelsinc) and (row = 1) then // create a col. label
|
|
||||||
begin
|
|
||||||
namestr := 'VAR ' + IntToStr(col);
|
|
||||||
OS3MainFrm.DataGrid.Cells[col,0] := namestr;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.Cells[col,row] := s;
|
|
||||||
s := '';
|
|
||||||
if col > NoVariables then
|
|
||||||
begin
|
|
||||||
NoVariables := col;
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
end;
|
|
||||||
col := 1;
|
|
||||||
if row > NoCases then NoCases := row;
|
|
||||||
OS3MainFrm.DataGrid.Cells[0,row] := 'Case ' + IntToStr(row);
|
|
||||||
row := row + 1;
|
|
||||||
if row >= OS3MainFrm.DataGrid.RowCount then
|
|
||||||
OS3MainFrm.DataGrid.RowCount := OS3MainFrm.DataGrid.RowCount + 1;
|
|
||||||
end;
|
|
||||||
end; // END OF FILE
|
|
||||||
|
|
||||||
OS3MainFrm.NoCasesEdit.Text := IntToStr(NoCases);
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
CloseFile(TabFile);
|
|
||||||
if NoVariables >= OS3MainFrm.DataGrid.ColCount - 1 then
|
|
||||||
OS3MainFrm.DataGrid.ColCount := OS3MainFrm.DataGrid.ColCount + 1;
|
|
||||||
|
|
||||||
// set up the dictionary
|
|
||||||
DictionaryFrm.DictGrid.RowCount := NoVariables + 1;
|
|
||||||
DictionaryFrm.DictGrid.ColCount := 8;
|
|
||||||
for row := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
DictionaryFrm.DictGrid.Cells[0,row] := IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[1,row] := 'VAR.' + IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[2,row] := 'VARIABLE ' + IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[3,row] := '8';
|
|
||||||
DictionaryFrm.DictGrid.Cells[4,row] := 'F';
|
|
||||||
DictionaryFrm.DictGrid.Cells[5,row] := '2';
|
|
||||||
DictionaryFrm.DictGrid.Cells[6,row] := MissingValueCodes[Options.DefaultMiss];
|
|
||||||
DictionaryFrm.DictGrid.Cells[7,row] := 'L';
|
|
||||||
end;
|
|
||||||
for row := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
DictionaryFrm.DictGrid.Cells[1,row] := OS3MainFrm.DataGrid.Cells[row,0];
|
|
||||||
VarDefined[row] := true;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.RowCount := (NoCases + 1);
|
|
||||||
OS3MainFrm.DataGrid.ColCount := (NoVariables + 1);
|
|
||||||
end;
|
|
||||||
GetTypes;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
|
|
||||||
procedure SaveSeparatorFile(ASeparator: Char; AFilter, ADefaultExt: String);
|
procedure SaveSeparatorFile(ASeparator: Char; AFilter, ADefaultExt: String);
|
||||||
var
|
var
|
||||||
@ -913,7 +801,12 @@ begin
|
|||||||
SaveSeparatorFile(' ', SSV_FILE_FILTER, 'ssv');
|
SaveSeparatorFile(' ', SSV_FILE_FILTER, 'ssv');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ValidValue(row, col: integer): boolean;
|
function ValidValue(row, col: Integer): Boolean;
|
||||||
|
begin
|
||||||
|
Result := ValidValue(OS3MainFrm.DataGrid, row, col);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ValidValue(AGrid: TStringGrid; row, col: integer): boolean;
|
||||||
var
|
var
|
||||||
valid: boolean;
|
valid: boolean;
|
||||||
xvalue: string;
|
xvalue: string;
|
||||||
@ -922,13 +815,13 @@ begin
|
|||||||
valid := true;
|
valid := true;
|
||||||
if FilterOn then
|
if FilterOn then
|
||||||
begin
|
begin
|
||||||
cellstring := Trim(OS3MainFrm.DataGrid.Cells[FilterCol, row]);
|
cellstring := Trim(AGrid.Cells[FilterCol, row]);
|
||||||
if cellstring = 'NO' then valid := false;
|
if cellstring = 'NO' then valid := false;
|
||||||
Result := valid;
|
Result := valid;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
xvalue := Trim(OS3MainFrm.DataGrid.Cells[col,row]);
|
xvalue := Trim(AGrid.Cells[col,row]);
|
||||||
if (xvalue = '') and (DictionaryFrm.DictGrid.Cells[4, col] <> 'S') then
|
if (xvalue = '') and (DictionaryFrm.DictGrid.Cells[4, col] <> 'S') then
|
||||||
valid := false;
|
valid := false;
|
||||||
if valid then // check for user-defined missing value
|
if valid then // check for user-defined missing value
|
||||||
@ -939,11 +832,17 @@ begin
|
|||||||
Result := valid;
|
Result := valid;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IsFiltered(GridRow: integer): boolean;
|
function IsFiltered(GridRow: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FilterOn and (Trim(OS3MainFrm.DataGrid.Cells[FilterCol,GridRow]) = 'NO');
|
Result := IsFiltered(OS3MainFrm.DataGrid, GridRow);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function IsFiltered(AGrid: TStringGrid; GridRow: integer): boolean;
|
||||||
|
begin
|
||||||
|
Result := FilterOn and (Trim(AGrid.Cells[FilterCol,GridRow]) = 'NO');
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure MatRead(const a: DblDyneMat; out NoRows, NoCols: integer;
|
procedure MatRead(const a: DblDyneMat; out NoRows, NoCols: integer;
|
||||||
const means, stddevs: DblDyneVec; out NCases: integer;
|
const means, stddevs: DblDyneVec; out NCases: integer;
|
||||||
const RowLabels, ColLabels: StrDyneVec; const AFileName: string);
|
const RowLabels, ColLabels: StrDyneVec; const AFileName: string);
|
||||||
@ -997,6 +896,7 @@ begin
|
|||||||
CloseFile(mat_file);
|
CloseFile(mat_file);
|
||||||
end; { matrix save routine }
|
end; { matrix save routine }
|
||||||
|
|
||||||
|
|
||||||
procedure ReOpen(AFilename: string);
|
procedure ReOpen(AFilename: string);
|
||||||
var
|
var
|
||||||
fileExt: string;
|
fileExt: string;
|
||||||
@ -1018,324 +918,6 @@ begin
|
|||||||
MessageDlg(Format('File "%s" not found.', [AFileName]), mtError, [mbOK], 0);
|
MessageDlg(Format('File "%s" not found.', [AFileName]), mtError, [mbOK], 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
|
||||||
procedure OpenCommaFile;
|
|
||||||
const
|
|
||||||
COMMA = ',';
|
|
||||||
var
|
|
||||||
CommaFile: TextFile;
|
|
||||||
namestr: string;
|
|
||||||
s: string;
|
|
||||||
ch: char;
|
|
||||||
labelsinc: boolean;
|
|
||||||
row, col: integer;
|
|
||||||
res: TModalResult;
|
|
||||||
begin
|
|
||||||
Assert(OS3MainFrm <> nil);
|
|
||||||
Assert(OptionsFrm <> nil);
|
|
||||||
|
|
||||||
labelsInc := false;
|
|
||||||
|
|
||||||
// check for a currently open file
|
|
||||||
if NoVariables > 1 then
|
|
||||||
begin
|
|
||||||
MessageDlg('Close (or Save and Close) the current work.', mtError, [mbOK], 0);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
OS3MainFrm.OpenDialog1.Filter := 'Comma field files (*.csv)|*.csv;*.CSV|Text files (*.txt)|*.txt;*.TXT|All files (*.*)|*.*';
|
|
||||||
OS3MainFrm.OpenDialog1.FilterIndex := 1;
|
|
||||||
OS3MainFrm.OpenDialog1.DefaultExt := 'csv';
|
|
||||||
if OS3MainForm.OpenDialog1.Execute then
|
|
||||||
begin
|
|
||||||
res := MessageDlg('Are variable labels included?', mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
|
||||||
if res = mrCancel then
|
|
||||||
exit;
|
|
||||||
labelsInc := (res = mrYes);
|
|
||||||
|
|
||||||
NoCases := 0;
|
|
||||||
NoVariables := 0;
|
|
||||||
if labelsInc then row := 0 else row := 1;
|
|
||||||
col := 1;
|
|
||||||
|
|
||||||
AssignFile(CommaFile, OS3MainFrm.OpenDialog1.FileName); // File selected in dialog box
|
|
||||||
Reset(CommaFile);
|
|
||||||
OS3MainFrm.FileNameEdit.Text := OS3MainFrm.OpenDialog1.FileName;
|
|
||||||
s := '';
|
|
||||||
while not EOF(CommaFile) do
|
|
||||||
begin
|
|
||||||
Read(CommaFile, ch);
|
|
||||||
if (ch < #9) or (ch > #127) then
|
|
||||||
Continue;
|
|
||||||
if (ch = #13 then // line feed character
|
|
||||||
Continue;
|
|
||||||
if (ch <> COMMA) and (ch <> #10) then // check for tab or new line
|
|
||||||
s := s + ch
|
|
||||||
else if ch = COMMA then // Comma found
|
|
||||||
begin
|
|
||||||
if (not labelsInc) and (row = 1) then // create a col. label
|
|
||||||
begin
|
|
||||||
namestr := 'VAR ' + IntToStr(col);
|
|
||||||
OS3MainFrm.DataGrid.Cells[col, 0] := namestr;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.Cells[col, row] := astr;
|
|
||||||
if col > NoVariables then
|
|
||||||
begin
|
|
||||||
NoVariables := col;
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
end;
|
|
||||||
col := col + 1;
|
|
||||||
s := '';
|
|
||||||
if col >= OS3MainFrm.DataGrid.ColCount then
|
|
||||||
OS3MainFrm.DataGrid.ColCount := OS3MainFrm.DataGrid.ColCount + 1;
|
|
||||||
end
|
|
||||||
else //must be new line character
|
|
||||||
begin
|
|
||||||
if (not labelsInc) and (row = 1) then // create a col. label
|
|
||||||
begin
|
|
||||||
namestr := 'VAR ' + IntToStr(col);
|
|
||||||
OS3MainFrm.DataGrid.Cells[col, 0] := namestr;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.Cells[col, row] := s;
|
|
||||||
s := '';
|
|
||||||
if col > NoVariables then
|
|
||||||
begin
|
|
||||||
NoVariables := col;
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
end;
|
|
||||||
col := 1;
|
|
||||||
if row > NoCases then NoCases := row;
|
|
||||||
OS3MainFrm.DataGrid.Cells[0, row] := 'Case ' + IntToStr(row);
|
|
||||||
row := row + 1;
|
|
||||||
if row >= OS3MainFrm.DataGrid.RowCount then
|
|
||||||
OS3MainFrm.DataGrid.RowCount := OS3MainFrm.DataGrid.RowCount + 1;
|
|
||||||
end;
|
|
||||||
end; // END OF FILE
|
|
||||||
|
|
||||||
OS3MainFrm.NoCasesEdit.Text := IntToStr(NoCases);
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
CloseFile(CommaFile);
|
|
||||||
if NoVariables > OS3MainFrm.DataGrid.ColCount - 1 then
|
|
||||||
OS3MainFrm.DataGrid.ColCount := OS3MainFrm.DataGrid.ColCount + 1;
|
|
||||||
|
|
||||||
// set up the dictionary
|
|
||||||
DictionaryFrm.DictGrid.RowCount := NoVariables + 1;
|
|
||||||
DictionaryFrm.DictGrid.ColCount := 8;
|
|
||||||
for row := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
DictionaryFrm.DictGrid.Cells[0,row] := IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[1,row] := 'VAR.' + IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[2,row] := 'VARIABLE ' + IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[3,row] := '8';
|
|
||||||
DictionaryFrm.DictGrid.Cells[4,row] := 'F';
|
|
||||||
DictionaryFrm.DictGrid.Cells[5,row] := '2';
|
|
||||||
DictionaryFrm.DictGrid.Cells[6,row] := MissingValueCodes[Options.DefaultMiss];
|
|
||||||
DictionaryFrm.DictGrid.Cells[7,row] := 'L';
|
|
||||||
end;
|
|
||||||
for row := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
DictionaryFrm.DictGrid.Cells[1,row] := OS3MainFrm.DataGrid.Cells[row,0];
|
|
||||||
VarDefined[row] := true;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.RowCount := (NoCases + 1);
|
|
||||||
OS3MainFrm.DataGrid.ColCount := (NoVariables + 1);
|
|
||||||
end;
|
|
||||||
GetTypes;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
procedure SaveCommaFile;
|
|
||||||
var
|
|
||||||
namestr : string;
|
|
||||||
cellvalue : string;
|
|
||||||
CommaFile : TextFile;
|
|
||||||
i, j : integer;
|
|
||||||
|
|
||||||
begin
|
|
||||||
OS3MainFrm.SaveDialog1.Filter := 'Comma field files (*.CSV)|*.CSV|Text files (*.txt)|*.TXT|All files (*.*)|*.*';
|
|
||||||
OS3MainFrm.SaveDialog1.FilterIndex := 1;
|
|
||||||
OS3MainFrm.SaveDialog1.DefaultExt := 'CSV';
|
|
||||||
if OS3MainFrm.SaveDialog1.Execute then
|
|
||||||
begin
|
|
||||||
namestr := OS3MainFrm.SaveDialog1.FileName;
|
|
||||||
Assign(CommaFile,namestr);
|
|
||||||
ReWrite(CommaFile);
|
|
||||||
for i := 0 to NoCases do
|
|
||||||
begin
|
|
||||||
for j := 1 to NoVariables do //write all but last with a tab
|
|
||||||
begin
|
|
||||||
cellvalue := OS3MainFrm.DataGrid.Cells[j,i];
|
|
||||||
if cellvalue = '' then cellvalue := '.';
|
|
||||||
cellvalue := Trim(cellvalue);
|
|
||||||
if j < NoVariables then cellvalue := cellvalue + ',';
|
|
||||||
write(CommaFile,cellvalue);
|
|
||||||
end;
|
|
||||||
writeln(CommaFile);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
CloseFile(CommaFile);
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
procedure OpenSpaceFile;
|
|
||||||
label getit;
|
|
||||||
var
|
|
||||||
SpaceFile : TextFile;
|
|
||||||
namestr : string;
|
|
||||||
astr : string;
|
|
||||||
achar : char;
|
|
||||||
respval : string;
|
|
||||||
labelsinc : boolean;
|
|
||||||
row, col : integer;
|
|
||||||
spacechar : integer;
|
|
||||||
spacefound : boolean;
|
|
||||||
begin
|
|
||||||
Assert(OS3MainFrm <> nil);
|
|
||||||
Assert(DictionaryFrm <> nil);
|
|
||||||
|
|
||||||
spacechar := ord(' ');
|
|
||||||
spacefound := false;
|
|
||||||
labelsinc := false;
|
|
||||||
// check for a currently open file
|
|
||||||
if NoVariables > 1 then
|
|
||||||
begin
|
|
||||||
ShowMessage('WARNING! Close (or Save and Close) the current work.');
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
respval := InputBox('LABELS?','Are variable labels included?','Y');
|
|
||||||
if respval = 'Y' then labelsinc := true;
|
|
||||||
OS3MainFrm.OpenDialog1.Filter := 'Comma field files (*.SSV)|*.SSV|Text files (*.txt)|*.TXT|All files (*.*)|*.*';
|
|
||||||
OS3MainFrm.OpenDialog1.FilterIndex := 1;
|
|
||||||
OS3MainFrm.OpenDialog1.DefaultExt := 'SSV';
|
|
||||||
if OS3MainFrm.OpenDialog1.Execute then
|
|
||||||
begin
|
|
||||||
NoCases := 0;
|
|
||||||
NoVariables := 0;
|
|
||||||
if labelsinc = true then row := 0 else row := 1;
|
|
||||||
col := 1;
|
|
||||||
AssignFile(SpaceFile, OS3MainFrm.OpenDialog1.FileName); // File selected in dialog box
|
|
||||||
Reset(SpaceFile);
|
|
||||||
OS3MainFrm.FileNameEdit.Text := OS3MainFrm.OpenDialog1.FileName;
|
|
||||||
astr := '';
|
|
||||||
while not EOF(SpaceFile) do
|
|
||||||
begin
|
|
||||||
getit: read(SpaceFile,achar);
|
|
||||||
if ord(achar) <> spacechar then spacefound := false;
|
|
||||||
if (ord(achar) < 9) or (ord(achar) > 127) then goto getit;
|
|
||||||
if ord(achar) = 13 then goto getit; // line feed character
|
|
||||||
if (ord(achar) <> spacechar) and (ord(achar) <> 10) then // check for space or new line
|
|
||||||
begin
|
|
||||||
astr := astr + achar;
|
|
||||||
end
|
|
||||||
else if ord(achar) = spacechar then // space character found
|
|
||||||
begin
|
|
||||||
if spacefound then goto getit; // extra space
|
|
||||||
if length(astr) = 0 then goto getit; // leading space
|
|
||||||
spacefound := true;
|
|
||||||
if (not labelsinc) and (row = 1) then // create a col. label
|
|
||||||
begin
|
|
||||||
namestr := 'VAR ' + IntToStr(col);
|
|
||||||
OS3MainFrm.DataGrid.Cells[col,0] := namestr;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.Cells[col,row] := astr;
|
|
||||||
if col > NoVariables then
|
|
||||||
begin
|
|
||||||
NoVariables := col;
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
end;
|
|
||||||
col := col + 1;
|
|
||||||
astr := '';
|
|
||||||
if col >= OS3MainFrm.DataGrid.ColCount then
|
|
||||||
OS3MainFrm.DataGrid.ColCount := OS3MainFrm.DataGrid.ColCount + 1;
|
|
||||||
end
|
|
||||||
else //must be new line character
|
|
||||||
begin
|
|
||||||
spacefound := false;
|
|
||||||
if (not labelsinc) and (row = 1) then // create a col. label
|
|
||||||
begin
|
|
||||||
namestr := 'VAR ' + IntToStr(col);
|
|
||||||
OS3MainFrm.DataGrid.Cells[col,0] := namestr;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.Cells[col,row] := astr;
|
|
||||||
astr := '';
|
|
||||||
if col > NoVariables then
|
|
||||||
begin
|
|
||||||
NoVariables := col;
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
end;
|
|
||||||
col := 1;
|
|
||||||
if row > NoCases then NoCases := row;
|
|
||||||
OS3MainFrm.DataGrid.Cells[0,row] := 'Case ' + IntToStr(row);
|
|
||||||
row := row + 1;
|
|
||||||
if row >= OS3MainFrm.DataGrid.RowCount then
|
|
||||||
OS3MainFrm.DataGrid.RowCount := OS3MainFrm.DataGrid.RowCount + 1;
|
|
||||||
end;
|
|
||||||
end; // END OF FILE
|
|
||||||
OS3MainFrm.NoCasesEdit.Text := IntToStr(NoCases);
|
|
||||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
|
||||||
CloseFile(SpaceFile);
|
|
||||||
if NoVariables > OS3MainFrm.DataGrid.ColCount - 1 then
|
|
||||||
OS3MainFrm.DataGrid.ColCount := OS3MainFrm.DataGrid.ColCount + 1;
|
|
||||||
end;
|
|
||||||
OS3MainFrm.DataGrid.RowCount := (NoCases + 1);
|
|
||||||
OS3MainFrm.DataGrid.ColCount := (NoVariables + 1);
|
|
||||||
// set up the dictionary
|
|
||||||
DictionaryFrm.DictGrid.RowCount := NoVariables + 1;
|
|
||||||
DictionaryFrm.DictGrid.ColCount := 8;
|
|
||||||
for row := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
DictionaryFrm.DictGrid.Cells[0,row] := IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[1,row] := 'VAR.' + IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[2,row] := 'VARIABLE ' + IntToStr(row);
|
|
||||||
DictionaryFrm.DictGrid.Cells[3,row] := '8';
|
|
||||||
DictionaryFrm.DictGrid.Cells[4,row] := 'F';
|
|
||||||
DictionaryFrm.DictGrid.Cells[5,row] := '2';
|
|
||||||
Dictionaryfrm.DictGrid.Cells[6,row] := MissingValueCodes[Options.DefaultMiss];
|
|
||||||
DictionaryFrm.DictGrid.Cells[7,row] := 'L';
|
|
||||||
end;
|
|
||||||
for row := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
DictionaryFrm.DictGrid.Cells[1,row] := OS3MainFrm.DataGrid.Cells[row,0];
|
|
||||||
VarDefined[row] := true;
|
|
||||||
end;
|
|
||||||
GetTypes;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
procedure SaveSpaceFile;
|
|
||||||
var
|
|
||||||
namestr : string;
|
|
||||||
cellvalue : string;
|
|
||||||
SpaceFile : TextFile;
|
|
||||||
i, j : integer;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Assert(OS3MainFrm <> nil);
|
|
||||||
|
|
||||||
OS3MainFrm.SaveDialog1.Filter := 'Comma field files (*.SSV)|*.SSV|Text files (*.txt)|*.TXT|All files (*.*)|*.*';
|
|
||||||
OS3MainFrm.SaveDialog1.FilterIndex := 1;
|
|
||||||
OS3MainFrm.SaveDialog1.DefaultExt := 'SSV';
|
|
||||||
if OS3MainFrm.SaveDialog1.Execute then
|
|
||||||
begin
|
|
||||||
namestr := OS3MainFrm.SaveDialog1.FileName;
|
|
||||||
Assign(SpaceFile,namestr);
|
|
||||||
ReWrite(SpaceFile);
|
|
||||||
for i := 0 to NoCases do
|
|
||||||
begin
|
|
||||||
for j := 1 to NoVariables do //write all but last with a tab
|
|
||||||
begin
|
|
||||||
cellvalue := OS3MainFrm.DataGrid.Cells[j,i];
|
|
||||||
if cellvalue = '' then cellvalue := '.';
|
|
||||||
cellvalue := Trim(cellvalue);
|
|
||||||
if j < NoVariables then cellvalue := cellvalue + ' ';
|
|
||||||
write(SpaceFile,cellvalue);
|
|
||||||
end;
|
|
||||||
writeln(SpaceFile);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
CloseFile(SpaceFile);
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
|
|
||||||
procedure InsertRow;
|
procedure InsertRow;
|
||||||
var
|
var
|
||||||
|
Reference in New Issue
Block a user