My application uses a QuantumGrid (v6.56) and a TSimpleDataSet as its data source.
Problem: an exception is thrown if the user enters a non-numeric value in a a numeric field. The code does not reach the OnBeforePost handler.
How can the application catch the error (and display a message to the user), if the exception is thrown before OnBeforePost?
Stack trace:
exception class : EDatabaseError
exception message : '...' is not valid Integer value for Field <somefieldname>
main thread ($504):
00526c7e +082 EditBooking.exe DB DatabaseError
00526d0f +04b EditBooking.exe DB DatabaseErrorFmt
0052c428 +07c EditBooking.exe DB TIntegerField.SetAsString
0052af30 +00c EditBooking.exe DB TField.SetText
0052abf9 +021 EditBooking.exe DB TField.SetEditText
007c3a3f +053 EditBooking.exe cxDBData
007e14a8 +018 EditBooking.exe cxGridDBDataDefinitions TcxGridDBDataController.UpdateData
006f8159 +039 EditBooking.exe cxCustomData TcxCustomDataProvider.DoUpdateData
007c1c18 +008 EditBooking.exe cxDBData TcxDBDataLink.UpdateData
0053325d +021 EditBooking.exe DB TDataLink.UpdateRecord
005333f8 +0d8 EditBooking.exe DB TDataLink.DataEvent
007c1683 +00f EditBooking.exe cxDBData TcxDBDataLink.DataEvent
00533973 +03f EditBooking.exe DB TDataSource.NotifyL开发者_StackOverflow社区inkTypes
005339a2 +01e EditBooking.exe DB TDataSource.NotifyDataLinks
005339cf +023 EditBooking.exe DB TDataSource.DataEvent
005392ad +131 EditBooking.exe DB TDataSet.DataEvent
00553d7c +058 EditBooking.exe DBClient TCustomClientDataSet.DataEvent
00539396 +042 EditBooking.exe DB TDataSet.UpdateRecord
0053a356 +006 EditBooking.exe DB TDataSet.Post
0055677c +054 EditBooking.exe DBClient TCustomClientDataSet.Post
You need to set the "Properties" property of your column in the cxGrid, there you can assign a CurrencyEdit so the user can only enter numbers, also after setting "Properties" you can use the OnValidate event to validate the user entry.
In your example, the event OnBeforePost isn't reached indeed.
You mention the cxGrid, but the fact is, your issue is easy to reproduce.
Take a simple TDBEdit linked on a TFloatField and try to enter the value "7.7.7.7.7.7.7.7". Float fields accept the decimal separator, but won't validate that only 1 is present. So entering this will also result in an error being raised in a similar fashion, either when you exit the field, or while posting, if you have a shortcut that allows you to do so.
If you want to intercept it "on the way in", then TField.OnSetText is probably your best bet.
精彩评论