LazStats: fix array dimensioning in XvsMultYUnit

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7629 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-08-23 09:15:08 +00:00
parent 79a85d3e59
commit f380f1d6f3
2 changed files with 34 additions and 28 deletions

View File

@ -82,18 +82,19 @@ uses
{ TXvsMultYForm } { TXvsMultYForm }
procedure TXvsMultYForm.ResetBtnClick(Sender: TObject); procedure TXvsMultYForm.ResetBtnClick(Sender: TObject);
VAR i : integer; var
i: integer;
begin begin
VarList.Clear; VarList.Clear;
YBox.Clear; YBox.Clear;
XEdit.Clear; XEdit.Clear;
XInBtn.Enabled := true; XInBtn.Enabled := true;
XOutBtn.Enabled := false; XOutBtn.Enabled := false;
YInBtn.Enabled := true; YInBtn.Enabled := true;
YOutBtn.Enabled := false; YOutBtn.Enabled := false;
PlotTitleEdit.Text := ''; PlotTitleEdit.Text := '';
for i := 1 to NoVariables do for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end; end;
procedure TXvsMultYForm.VarListSelectionChange(Sender: TObject; User: boolean); procedure TXvsMultYForm.VarListSelectionChange(Sender: TObject; User: boolean);
@ -173,11 +174,11 @@ begin
try try
SetLength(YValues, NoY, NoCases); SetLength(YValues, NoY, NoCases);
SetLength(XValues, NoCases); SetLength(XValues, NoCases);
SetLength(Means, NoSelected+1); SetLength(Means, NoSelected);
SetLength(Variances, NoSelected+1); SetLength(Variances, NoSelected);
SetLength(StdDevs, NoSelected+1); SetLength(StdDevs, NoSelected);
SetLength(RMatrix, NoSelected+1, NoSelected+1); SetLength(RMatrix, NoSelected+1, NoSelected+1);
SetLength(selected, NoVariables); SetLength(selected, NoVariables+1);
for i := 0 to NoSelected - 1 do for i := 0 to NoSelected - 1 do
begin begin
@ -187,18 +188,21 @@ begin
end; end;
N := 0; N := 0;
for i := 1 to NoCases do // index rule: array index: i, grid-related index: i+1
for i := 0 to NoCases-1 do
begin begin
if not GoodRecord(i, NoSelected, selected) then continue; if not GoodRecord(i+1, NoSelected, selected) then continue;
inc(N); inc(N);
XValues[i-1] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[XCol,i])); XValues[i] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[XCol, i+1]));
MaxX := Max(MaxX, XValues[i-1]); MaxX := Max(MaxX, XValues[i]);
MinX := Min(MinX, XValues[i-1]); MinX := Min(MinX, XValues[i]);
for j := 0 to NoY - 1 do for j := 0 to NoY - 1 do
begin begin
YValues[j, i-1] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[selected[j], i])); // Unlike other usages of 2-D arrays in LazStats the 1st index is the
MaxY := Max(MaxY, YValues[j, i-1]); // curve index while the 2nd index is the point index here.
MinY := Min(MinY, YValues[j, i-1]); YValues[j, i] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[selected[j], i+1]));
MaxY := Max(MaxY, YValues[j, i]);
MinY := Min(MinY, YValues[j, i]);
end; end;
end; end;
@ -332,6 +336,8 @@ end;
// Routine to plot X versus multiple Y values // Routine to plot X versus multiple Y values
// Unlike many other routines in LazStats the curve index in YValues is the
// first one, the point index is the second one.
{$IFDEF USE_TACHART} {$IFDEF USE_TACHART}
procedure TXvsMultYForm.PlotXY(XValues: DblDyneVec; YValues: DblDyneMat); procedure TXvsMultYForm.PlotXY(XValues: DblDyneVec; YValues: DblDyneMat);
var var

View File

@ -67,10 +67,10 @@ var
i, j: integer; i, j: integer;
begin begin
Result := true; Result := true;
for i := 1 to NoVars do for i := 0 to NoVars-1 do
begin begin
j := GridPos[i-1]; j := GridPos[i];
if not ValidValue(Row,j) then if not ValidValue(Row, j) then
Result := false; Result := false;
end; end;
end; end;
@ -959,11 +959,11 @@ begin
end; end;
xvalue := Trim(OS3MainFrm.DataGrid.Cells[col,row]); xvalue := Trim(OS3MainFrm.DataGrid.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
begin begin
if Trim(DictionaryFrm.DictGrid.Cells[6,col]) = xvalue then if Trim(DictionaryFrm.DictGrid.Cells[6, col]) = xvalue then
valid := false; valid := false;
end; end;
Result := valid; Result := valid;