From aecaad587fa8be64de900c8f63afb2a6a209c425 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 3 Dec 2020 15:36:09 +0000 Subject: [PATCH] Fix some missing validation in ABClogLinUnit. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7918 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/lazstats/source/LazStats.lpi | 2 +- .../cross-classification/abcloglinunit.lfm | 7 +- .../cross-classification/abcloglinunit.pas | 103 +++++++++++++----- .../analysis/descriptive/boxplotunit.pas | 2 +- 4 files changed, 80 insertions(+), 34 deletions(-) diff --git a/applications/lazstats/source/LazStats.lpi b/applications/lazstats/source/LazStats.lpi index 19e248e71..8dacf60a9 100644 --- a/applications/lazstats/source/LazStats.lpi +++ b/applications/lazstats/source/LazStats.lpi @@ -606,7 +606,7 @@ - + diff --git a/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.lfm b/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.lfm index ef0afbf86..a414bf506 100644 --- a/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.lfm +++ b/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.lfm @@ -80,7 +80,7 @@ inherited ABCLogLinearForm: TABCLogLinearForm Height = 290 Top = 67 Width = 376 - PageIndex = 0 + PageIndex = 1 Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Top = 16 TabOrder = 1 @@ -429,15 +429,16 @@ inherited ABCLogLinearForm: TABCLogLinearForm AnchorSideBottom.Control = Page2 AnchorSideBottom.Side = asrBottom Left = 0 - Height = 253 + Height = 259 Top = 31 Width = 376 Anchors = [akTop, akLeft, akRight, akBottom] + AutoAdvance = aaDown BorderSpacing.Top = 8 ColCount = 4 FixedCols = 3 MouseWheelOption = mwGrid - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goTabs, goThumbTracking, goSmoothScroll] + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goEditing, goTabs, goThumbTracking, goSmoothScroll] RowCount = 2 TabOrder = 3 end diff --git a/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.pas b/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.pas index cd887cbaf..7c5215366 100644 --- a/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.pas +++ b/applications/lazstats/source/forms/analysis/cross-classification/abcloglinunit.pas @@ -103,7 +103,11 @@ implementation uses Math, - GridProcs; + Utils, GridProcs; + + +const + INVALID_INT_ERROR = 'Valid positive integer required.'; { TABCLogLinearForm } @@ -154,42 +158,82 @@ begin end; procedure TABCLogLinearForm.NColsEditKeyPress(Sender: TObject; var Key: char); +var + n: Integer; begin - if ord(Key) = 13 then NslicesEdit.SetFocus; + if ord(Key) = 13 then + begin + if not TryStrToInt(NColsEdit.Text, n) then + begin + ErrorMsg(INVALID_INT_ERROR); + NColsEdit.SetFocus; + exit; + end; + + NslicesEdit.SetFocus; + end; end; procedure TABCLogLinearForm.NRowsEditKeyPress(Sender: TObject; var Key: char); +var + n: Integer; begin - if ord(Key) = 13 then NcolsEdit.SetFocus; + if ord(Key) = 13 then + begin + if not TryStrToInt(NRowsEdit.Text, n) then + begin + ErrorMsg(INVALID_INT_ERROR); + NRowsEdit.SetFocus; + exit; + end; + NcolsEdit.SetFocus; + end; end; + procedure TABCLogLinearForm.NslicesEditKeyPress(Sender: TObject; var Key: char); var - i, j, k, row : integer; - Nslices, Ncols, Nrows : integer; + i, j, k, row: integer; + nSlices, nCols, nRows: integer; begin - if ord(Key) = 13 then - begin - Nrows := StrToInt(NrowsEdit.Text); - Ncols := StrToInt(NcolsEdit.Text); - Nslices := StrToInt(NslicesEdit.Text); - Grid.RowCount := Nrows * Ncols * Nslices + 1; - row := 1; - for k := 1 to Nslices do - begin - for j := 1 to Ncols do - begin - for i := 1 to Nrows do - begin - Grid.Cells[0,row] := IntToStr(i); - Grid.Cells[1,row] := IntToStr(j); - Grid.Cells[2,row] := IntToStr(k); - row := row + 1; - end; - end; - end; - Grid.SetFocus; - end; + if ord(Key) = 13 then + begin + if not TryStrToInt(NRowsEdit.Text, nRows) then + begin + ErrorMsg(INVALID_INT_ERROR); + NRowsEdit.SetFocus; + exit; + end; + if not TryStrToInt(NColsEdit.Text, nCols) then + begin + ErrorMsg(INVALID_INT_ERROR); + NColsEdit.SetFocus; + exit; + end; + if not TryStrToInt(NSlicesEdit.Text, nSlices) then + begin + ErrorMsg(INVALID_INT_ERROR); + NSlicesEdit.SetFocus; + exit; + end; + Grid.RowCount := nRows * nCols * nSlices + 1; + + row := 1; + for k := 1 to nSlices do + begin + for j := 1 to nCols do + begin + for i := 1 to nRows do + begin + Grid.Cells[0,row] := IntToStr(i); + Grid.Cells[1,row] := IntToStr(j); + Grid.Cells[2,row] := IntToStr(k); + row := row + 1; + end; + end; + end; + Grid.SetFocus; + end; end; procedure TABCLogLinearForm.ColInBtnClick(Sender: TObject); @@ -623,7 +667,7 @@ begin PrintTable(Nrows,Ncols,Nslices,LogData,LogRowMarg,LogColMarg,LogSliceMarg,AReport); AReport.Add(''); - AReport.Add('======================================================================'); + AReport.Add(DIVIDER_AUTO); AReport.Add(''); astr := 'Cell Parameters'; @@ -647,7 +691,7 @@ begin AReport.Add(astr); AReport.Add(''); - AReport.Add('======================================================================'); + AReport.Add(DIVIDER_AUTO); AReport.Add(''); CellLambdas := nil; @@ -862,6 +906,7 @@ begin inherited; Grid.ColCount := 4; + Grid.FixedCols := 3; Grid.RowCount := 2; Grid.Cells[0,0] := 'ROW'; Grid.Cells[1,0] := 'COL'; diff --git a/applications/lazstats/source/forms/analysis/descriptive/boxplotunit.pas b/applications/lazstats/source/forms/analysis/descriptive/boxplotunit.pas index 065d1822b..e31feb3f3 100644 --- a/applications/lazstats/source/forms/analysis/descriptive/boxplotunit.pas +++ b/applications/lazstats/source/forms/analysis/descriptive/boxplotunit.pas @@ -10,7 +10,7 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, Printers, ComCtrls, Buttons, - MainUnit, Globals, DataProcs, ReportFrameUnit, ChartFrameUnit, + MainUnit, Globals, ReportFrameUnit, ChartFrameUnit, BasicStatsReportAndChartFormUnit;