OnValidate for TClientDataSet

I am trying to write an OnValidate event in a field in a TClientDataSet, something like strings

procedure TForm8.ClientDataSet1MyFieldValidate(Sender: TField); begin if Sender.AsFloat > 30 then raise Exception.Create('Too Much!!!'); end; 

But Sender.AsFloat is always 0 - how can I perform field-level checking (I understand that in this case I could use restrictions or set Min / Max values)

+4
source share
3 answers

This is a bug that appeared in Delphi XE3, here is a QC report and a quick movie I made to clearly illustrate the problem. We hope that this will be fixed in the next update. One of the comments on the quality control page has a hot fix if you need to fix it immediately.

+2
source

this works fine on D2010, where is the difference ...

 procedure TForm3.FloatValidate(Sender: TField); begin if sender.AsFloat > 30 then Showmessage('No'); end; procedure TForm3.Button1Click(Sender: TObject); begin With Clientdataset1 do begin FieldDefs.add('ID',ftInteger,0); FieldDefs.add('Floatfield',ftFloat,0); Createdataset; Fields[1].OnValidate := FloatValidate; end; end; 
+1
source

You might want to check if Sender.NewValue contains the value you are using. If the update cache in the client dataset is active, you can use the values ​​OldValue, Value, and NewValue.

0
source

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


All Articles