2012年(106)
分类: 嵌入式
2012-05-07 18:13:03
数据库1(基本编辑操作)
步骤一:开始---程序--- Borland Delphi 6---BDE---Object---New---OK(默认STANDARD)---PATH---设置为含有数据库文件的目录下。
步骤二:向Form1中添加Table组件(BDE组中),DatabaseName---STANDARD1(上一步创建的),TableName---Pza.DBF。添加DataSource 组件(DataAccess组中),DataSet---Table1。添加DBGrid组件(Data Controls 组中) DataSource---DataSource1。添加DBNavigator1组件(DataControls组中)DataSource---DataSource1。
向Form1中添加6个Button(Button1…Button6) , Caption依次为”添加”,”删除”,”修改”,”确定”,”取消”,”退出”
步骤三:
1.声明一个procedure (public后面一行):
procedure setstate(s:integer); //0:browse;1:editor insert
定义这个procedure(implementation{$R *.dfm}后面一行):
procedure TForm1.setstate(s:integer);
begin
if s=0then
begin
button1.Enabled:=True;
button2.Enabled:=True;
button3.Enabled:=True;
button4.Enabled:=False;
button5.Enabled:=False;
button6.Enabled:=True;
end
else
begin
button1.Enabled:=False;
button2.Enabled:=False;
button3.Enabled:=False;
button4.Enabled:=True;
button5.Enabled:=True;
button6.Enabled:=False;
end;
end;
2.定义变量x(implementation下面一行):
var x:integer;
3.打开Table(Form1---OnActivate) :
Table1.Open;
setstate(0);
4. Button1:
Table1.Append;
DBGrid1.SetFocus;
setstate(1);
Button2:
ifMessageDLG('Delete?',mtwarning,[mbYes,mbNo],0)=mrYes then Table1.Delete;
Button3:
Table1.Edit;
DBGrid1.SetFocus;
setstate(1);
Button4:
Table1.Post;
setstate(0);
Button5:
Table1.Cancel;
setstate(0);
Button6:
Table1.Close;
Application.Terminate;
5.Datasource1---AutoEdit: false;