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 }
procedure TXvsMultYForm.ResetBtnClick(Sender: TObject);
VAR i : integer;
var
i: integer;
begin
VarList.Clear;
YBox.Clear;
XEdit.Clear;
XInBtn.Enabled := true;
XOutBtn.Enabled := false;
YInBtn.Enabled := true;
YOutBtn.Enabled := false;
PlotTitleEdit.Text := '';
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
VarList.Clear;
YBox.Clear;
XEdit.Clear;
XInBtn.Enabled := true;
XOutBtn.Enabled := false;
YInBtn.Enabled := true;
YOutBtn.Enabled := false;
PlotTitleEdit.Text := '';
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end;
procedure TXvsMultYForm.VarListSelectionChange(Sender: TObject; User: boolean);
@ -173,11 +174,11 @@ begin
try
SetLength(YValues, NoY, NoCases);
SetLength(XValues, NoCases);
SetLength(Means, NoSelected+1);
SetLength(Variances, NoSelected+1);
SetLength(StdDevs, NoSelected+1);
SetLength(Means, NoSelected);
SetLength(Variances, NoSelected);
SetLength(StdDevs, NoSelected);
SetLength(RMatrix, NoSelected+1, NoSelected+1);
SetLength(selected, NoVariables);
SetLength(selected, NoVariables+1);
for i := 0 to NoSelected - 1 do
begin
@ -187,18 +188,21 @@ begin
end;
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
if not GoodRecord(i, NoSelected, selected) then continue;
if not GoodRecord(i+1, NoSelected, selected) then continue;
inc(N);
XValues[i-1] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[XCol,i]));
MaxX := Max(MaxX, XValues[i-1]);
MinX := Min(MinX, XValues[i-1]);
XValues[i] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[XCol, i+1]));
MaxX := Max(MaxX, XValues[i]);
MinX := Min(MinX, XValues[i]);
for j := 0 to NoY - 1 do
begin
YValues[j, i-1] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[selected[j], i]));
MaxY := Max(MaxY, YValues[j, i-1]);
MinY := Min(MinY, YValues[j, i-1]);
// Unlike other usages of 2-D arrays in LazStats the 1st index is the
// curve index while the 2nd index is the point index here.
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;
@ -332,6 +336,8 @@ end;
// 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}
procedure TXvsMultYForm.PlotXY(XValues: DblDyneVec; YValues: DblDyneMat);
var

View File

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