How to get the value that caused the TDBGridInplaceEdit error?

I'm trying to write an exception handler that displays user friendly messages. I don't know how to get the "Newly Entered" data value that caused the TDBGridInplaceEdit error.

For example: I have a DBGrid loaded with data. When I intentionally change the PartNo field of row #1 to a non numeric value to cause a TDBGridInplaceEdit error... (From: 1313.3 To: 1313..3) ... I trap the error and display a message but I can't figure out how to get the bad '1313..3' value.

Original PartNo: 1313.3 Changed PartNo: 1313..3 (two decimal points) Displayed Error Message from the Application onException

procedure TMain.ApplicationEvents1Exception(Sender: TObject; E: Exception);
  str : string;
  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;

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


If you are persisting the fields of your dataset, you can define an OnSetText Method on your fields.(Doubleclick on the dataset and choose add fields).

The Method could look like this:

procedure TForm1.ADataSetAFloatFieldSetText(Sender: TField; const Text: string);
  if not TryStrToFloat(Text,f) then
       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

If you want to avoid persisting your fields you can dynamically assign the Method to the field, e.g. after opening the Dataset.

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

Need Your Help

Spring App + Tomcat + XSLT = TransformerFactoryConfigurationError

java spring tomcat xerces

I am trying to deploy a Spring 3.0 Webapplicatoin to a tomcat5.5 server running on CentOS.

How do I create a nested has_many or belongs_to relationship with DBIx::Class?

sql perl dbix-class

In my code I have three classes as follows: Forum, Forum::Thread and Forum::Post

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.