给一个例子给你,就是我做实验的:
PAS:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, DBGrids, StdCtrls, Mask, DBCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBEdit1: TDBEdit;
DBNavigator1: TDBNavigator;
DBGrid1: TDBGrid;
Table1Aa: TIntegerField;
procedure Table1AaValidate(Sender: TField);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Table1AaValidate(Sender: TField);
begin
if table1aa.asinteger >15 then
begin
application.messagebox('Error','',1);
abort;
end;
end;
end.
DFM:
object Form1: TForm1
Left = 200
Top = 104
Width = 696
Height = 480
Caption = 'Form1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object DBEdit1: TDBEdit
Left = 296
Top = 88
Width = 121
Height = 21
DataField = 'Aa'
DataSource = DataSource1
TabOrder = 0
end
object DBNavigator1: TDBNavigator
Left = 128
Top = 192
Width = 240
Height = 25
DataSource = DataSource1
TabOrder = 1
end
object DBGrid1: TDBGrid
Left = 152
Top = 264
Width = 233
Height = 129
DataSource = DataSource1
TabOrder = 2
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Table1: TTable
Active = True
DatabaseName = 'test'
TableName = 'aa.db'
Left = 184
Top = 80
object Table1Aa: TIntegerField
FieldName = 'Aa'
OnChange = Table1AaValidate
end
end
object DataSource1: TDataSource
DataSet = Table1
Left = 208
Top = 88
end
end