From cc5f16814e99ab3c04bdb9a53e9c77a2e34941ef Mon Sep 17 00:00:00 2001 From: wp Date: Mon, 25 Feb 2019 09:11:49 +0000 Subject: [PATCH] TAChart: Add input validation to Datapoints editor. git-svn-id: trunk@60494 - --- .../tachart/editors/tadatapointseditor.lfm | 2 + .../tachart/editors/tadatapointseditor.pas | 48 +++++++++++++++++++ .../tachart/languages/tachartstrconsts.de.po | 8 ++++ .../tachart/languages/tachartstrconsts.fi.po | 8 ++++ .../tachart/languages/tachartstrconsts.fr.po | 8 ++++ .../tachart/languages/tachartstrconsts.hu.po | 8 ++++ .../tachart/languages/tachartstrconsts.lt.po | 8 ++++ .../tachart/languages/tachartstrconsts.pl.po | 8 ++++ .../tachart/languages/tachartstrconsts.pot | 8 ++++ .../languages/tachartstrconsts.pt_BR.po | 8 ++++ .../tachart/languages/tachartstrconsts.ru.po | 8 ++++ .../tachart/languages/tachartstrconsts.se.po | 8 ++++ .../tachart/languages/tachartstrconsts.uk.po | 8 ++++ .../languages/tachartstrconsts.zh_CN.po | 8 ++++ components/tachart/tachartstrconsts.pas | 2 + 15 files changed, 148 insertions(+) diff --git a/components/tachart/editors/tadatapointseditor.lfm b/components/tachart/editors/tadatapointseditor.lfm index 47ce4c2167..0664a6aac1 100644 --- a/components/tachart/editors/tadatapointseditor.lfm +++ b/components/tachart/editors/tadatapointseditor.lfm @@ -16,6 +16,7 @@ object DataPointsEditorForm: TDataPointsEditorForm Width = 276 Align = alClient BorderSpacing.Around = 6 + ColCount = 4 Columns = < item Alignment = taRightJustify @@ -58,6 +59,7 @@ object DataPointsEditorForm: TDataPointsEditorForm Width = 276 OKButton.Name = 'OKButton' OKButton.DefaultCaption = True + OKButton.OnClick = OKButtonClick HelpButton.Name = 'HelpButton' HelpButton.DefaultCaption = True CloseButton.Name = 'CloseButton' diff --git a/components/tachart/editors/tadatapointseditor.pas b/components/tachart/editors/tadatapointseditor.pas index 4139f714ac..0ed7a9b41d 100644 --- a/components/tachart/editors/tadatapointseditor.pas +++ b/components/tachart/editors/tadatapointseditor.pas @@ -31,6 +31,7 @@ type procedure FormCreate(Sender: TObject); procedure miDeleteRowClick(Sender: TObject); procedure miInsertRowClick(Sender: TObject); + procedure OKButtonClick(Sender: TObject); procedure pmRowsPopup(Sender: TObject); procedure sgDataButtonClick(ASender: TObject; ACol, ARow: Integer); procedure sgDataDrawCell( @@ -43,6 +44,7 @@ type FDataPoints: TStrings; FXCount: Integer; FYCount: Integer; + function ValidData(out ACol, ARow: Integer; out AMsg: String): Boolean; public procedure InitData(AXCount, AYCount: Integer; ADataPoints: TStrings); procedure ExtractData(out AModified: Boolean); @@ -170,6 +172,20 @@ begin sgData.InsertColRow(false, FCurrentRow); end; +procedure TDataPointsEditorForm.OKButtonClick(Sender: TObject); +var + c, r: Integer; + msg: String; +begin + if not ValidData(c, r, msg) then begin + sgData.Row := r; + sgData.Col := c; + sgData.SetFocus; + MessageDlg(msg, mtError, [mbOK], 0); + ModalResult := mrNone; + end; +end; + procedure TDataPointsEditorForm.pmRowsPopup(Sender: TObject); begin FCurrentRow := sgData.MouseToCell(sgData.ScreenToClient(Mouse.CursorPos)).Y; @@ -216,6 +232,38 @@ begin end; end; +function TDataPointsEditorForm.ValidData(out ACol, ARow: Integer; + out AMsg: String): Boolean; +var + x: Double; + i: Integer; + r, c: Integer; + s: String; +begin + Result := false; + for r := 1 to sgData.RowCount-1 do begin + for c := 1 to sgData.ColCount-3 do begin + s := sgData.Cells[c, r]; + if (s <> '') and not TryStrToFloat(s, x) and not TryStrToFloat(s, x, DefSeparatorSettings) then + begin + ACol := c; + ARow := r; + AMsg := desNoNumber; + exit; + end; + end; + s := sgData.Cells[sgData.ColCount - 2, r]; + if (s <> '') and not TryStrToInt(s, i) then begin + ACol := sgData.ColCount - 2; + ARow := r; + AMsg := desNoInteger; + exit; + end; + end; + Result := true; +end; + + { TDataPointsPropertyEditor } procedure TDataPointsPropertyEditor.Edit; diff --git a/components/tachart/languages/tachartstrconsts.de.po b/components/tachart/languages/tachartstrconsts.de.po index e8aa939051..c4d51518a9 100644 --- a/components/tachart/languages/tachartstrconsts.de.po +++ b/components/tachart/languages/tachartstrconsts.de.po @@ -29,6 +29,14 @@ msgstr "Zeile löschen" msgid "Insert row" msgstr "Zeile einfügen" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "Wert muss eine ganze Zahl sein." + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "Kein numerischer Wert." + #: tachartstrconsts.destext msgid "Text" msgstr "Text" diff --git a/components/tachart/languages/tachartstrconsts.fi.po b/components/tachart/languages/tachartstrconsts.fi.po index 941769a8d9..1b9cbbeab8 100644 --- a/components/tachart/languages/tachartstrconsts.fi.po +++ b/components/tachart/languages/tachartstrconsts.fi.po @@ -17,6 +17,14 @@ msgstr "Poista rivi" msgid "Insert row" msgstr "Lisää rivi" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Teksti" diff --git a/components/tachart/languages/tachartstrconsts.fr.po b/components/tachart/languages/tachartstrconsts.fr.po index e386ba854f..a85acd395d 100644 --- a/components/tachart/languages/tachartstrconsts.fr.po +++ b/components/tachart/languages/tachartstrconsts.fr.po @@ -27,6 +27,14 @@ msgstr "Supprimer la ligne" msgid "Insert row" msgstr "Insérer une ligne" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Texte" diff --git a/components/tachart/languages/tachartstrconsts.hu.po b/components/tachart/languages/tachartstrconsts.hu.po index 7b92b19cf4..afbd97e1b2 100644 --- a/components/tachart/languages/tachartstrconsts.hu.po +++ b/components/tachart/languages/tachartstrconsts.hu.po @@ -27,6 +27,14 @@ msgstr "Sor törlése" msgid "Insert row" msgstr "Sor beszúrása" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Szöveg" diff --git a/components/tachart/languages/tachartstrconsts.lt.po b/components/tachart/languages/tachartstrconsts.lt.po index 1d0b8efcd6..9071eef9a9 100644 --- a/components/tachart/languages/tachartstrconsts.lt.po +++ b/components/tachart/languages/tachartstrconsts.lt.po @@ -28,6 +28,14 @@ msgstr "Šalinti eilutę" msgid "Insert row" msgstr "Įterpti eilutę" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Tekstas" diff --git a/components/tachart/languages/tachartstrconsts.pl.po b/components/tachart/languages/tachartstrconsts.pl.po index 2290c8fbd3..ceeda37cd3 100644 --- a/components/tachart/languages/tachartstrconsts.pl.po +++ b/components/tachart/languages/tachartstrconsts.pl.po @@ -28,6 +28,14 @@ msgstr "Usuń wiersz" msgid "Insert row" msgstr "Wstaw wiersz" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Tekst" diff --git a/components/tachart/languages/tachartstrconsts.pot b/components/tachart/languages/tachartstrconsts.pot index 2539aa6343..a7ce0bad24 100644 --- a/components/tachart/languages/tachartstrconsts.pot +++ b/components/tachart/languages/tachartstrconsts.pot @@ -17,6 +17,14 @@ msgstr "" msgid "Insert row" msgstr "" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "" diff --git a/components/tachart/languages/tachartstrconsts.pt_BR.po b/components/tachart/languages/tachartstrconsts.pt_BR.po index 7a67b7b49a..4f075c467b 100644 --- a/components/tachart/languages/tachartstrconsts.pt_BR.po +++ b/components/tachart/languages/tachartstrconsts.pt_BR.po @@ -27,6 +27,14 @@ msgstr "Excluir linha" msgid "Insert row" msgstr "Inserir linha" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Texto" diff --git a/components/tachart/languages/tachartstrconsts.ru.po b/components/tachart/languages/tachartstrconsts.ru.po index 605960b4ad..979d099955 100644 --- a/components/tachart/languages/tachartstrconsts.ru.po +++ b/components/tachart/languages/tachartstrconsts.ru.po @@ -27,6 +27,14 @@ msgstr "Удалить строку" msgid "Insert row" msgstr "Вставить строку" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Текст" diff --git a/components/tachart/languages/tachartstrconsts.se.po b/components/tachart/languages/tachartstrconsts.se.po index 4a99c49674..aab3dfaa6e 100644 --- a/components/tachart/languages/tachartstrconsts.se.po +++ b/components/tachart/languages/tachartstrconsts.se.po @@ -28,6 +28,14 @@ msgstr "" msgid "Insert row" msgstr "" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Text" diff --git a/components/tachart/languages/tachartstrconsts.uk.po b/components/tachart/languages/tachartstrconsts.uk.po index 4d065c3c20..d6f01b39c8 100644 --- a/components/tachart/languages/tachartstrconsts.uk.po +++ b/components/tachart/languages/tachartstrconsts.uk.po @@ -30,6 +30,14 @@ msgstr "Видалити рядок" msgid "Insert row" msgstr "Вставити рядок" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "Текст" diff --git a/components/tachart/languages/tachartstrconsts.zh_CN.po b/components/tachart/languages/tachartstrconsts.zh_CN.po index fabd190f12..1acded3b04 100644 --- a/components/tachart/languages/tachartstrconsts.zh_CN.po +++ b/components/tachart/languages/tachartstrconsts.zh_CN.po @@ -28,6 +28,14 @@ msgstr "删除行" msgid "Insert row" msgstr "插入行" +#: tachartstrconsts.desnointeger +msgid "Value must be an integer." +msgstr "" + +#: tachartstrconsts.desnonumber +msgid "Non-numeric value." +msgstr "" + #: tachartstrconsts.destext msgid "Text" msgstr "文本" diff --git a/components/tachart/tachartstrconsts.pas b/components/tachart/tachartstrconsts.pas index a618be911c..95bc475d9e 100644 --- a/components/tachart/tachartstrconsts.pas +++ b/components/tachart/tachartstrconsts.pas @@ -36,6 +36,8 @@ resourcestring desText = 'Text'; desInsertRow = 'Insert row'; desDeleteRow = 'Delete row'; + desNoNumber = 'Non-numeric value.'; + desNoInteger = 'Value must be an integer.'; // Axis rsLeft = 'Left';