 |
|
EnterpriseDBDAC
Example: BeforeInsert, Insert, AsInteger, FieldByName | | Previous Next |
This example uses the BeforeInsert event to do data validation; if the StrToInt
function raises an exception, the edit control's contents are set to a valid value so the assignment to
the INTEGER field in the table will succeed.
procedure TForm1.EDBTable1BeforeInsert(DataSet: TDataSet);
begin
try
// Make sure edit field can be converted to integer --
// this will raise an exception if it can't
StrToInt(Edit1.Text);
except
Edit1.Text := '0';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EDBTable1.Insert;
EDBTable1.FieldByName('QUANTITY').AsInteger := StrToInt(Edit1.Text);
EDBTable1.Post;
end;
|