OnValidate for a TClientDataSet
-
24-07-2021 - |
题
I'm trying to write an OnValidate event on a field on a TClientDataSet, something along the lines of
procedure TForm8.ClientDataSet1MyFieldValidate(Sender: TField);
begin
if Sender.AsFloat > 30 then
raise Exception.Create('Too Much!!!');
end;
But Sender.AsFloat is always 0 - how do I do field level validation (I realize in this instance I could use constraints or set Min/Max values)
其他提示
this works fine on D2010, where's 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;
You might want to check if Sender.NewValue contains the value you are after. If the update cache on the client dataset is active you can use the OldValue, Value and NewValue of the fields.
不隶属于 StackOverflow