How to get the value causing the TDBGridInplaceEdit error?

I am trying to write an exception handler that displays user-friendly messages. I do not know how to get the value " Newly entered " that caused the TDBGridInplaceEdit error.

For instance:
I have a DBGrid loaded with data. When I intentionally change the PartNo field of line # 1 to a non-numeric value to cause a TDBGridInplaceEdit error ... (From: 1313.3 To: 1313..3) ... I delay the error and display the message, but I cannot figure out how to get bad value "1313..3".

enter image description here
Original PartNo: 1313.3

enter image description here
PartNo modified: 1313..3 (two decimal points)

enter image description here
Error message displayed from onException application

procedure TMain.ApplicationEvents1Exception(Sender: TObject; E: Exception); var str : string; begin str := sender.ToString; str := str + #10; str := str + RzDBGrid2.SelectedField.FieldName; str := str + #10; str := str + VarToStr(RzDBGrid2.SelectedField.Value); str := str + #10; str := str + e.Message; showmessage(str); //Application.ShowException(E); end; 

I would like to format my own message using the value "1313..3" that was entered. How do you get this value?

+4
source share
1 answer

If you save the fields of your dataset, you can define the OnSetText method in your fields. (Double-click on the dataset and select add fields).

enter image description here

The method might look like this:

 procedure TForm1.ADataSetAFloatFieldSetText(Sender: TField; const Text: string); var f:Double; begin if not TryStrToFloat(Text,f) then begin raise Exception.Create( 'Error on: ' + #13#10'Dataset: ' + Sender.DataSet.Name + #13#10'Field: ' + Sender.FieldName + #13#10'Old Value: ' + Sender.AsString + #13#10'New Value: ' + Text ); end; end; 

If you want to avoid saving your fields, you can dynamically assign a method to a field, for example. after opening the data set.

 procedure TForm1.ADataSetAfterOpen(DataSet: TDataSet); Var i:Integer; begin for I := 0 to Dataset.FieldCount - 1 do begin if Dataset.Fields[i].DataType in [ftFloat, ftCurrency, ftBCD] then Dataset.Fields[i].OnSetText := ADataSetAFloatFieldSetText; end; end; 
+5
source

Source: https://habr.com/ru/post/1498508/


All Articles