📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Curdir:string;
begin
table1.Close;
Getdir(0,curdir); //得到当前目录
Table1.DatabaseName:=CurDir; //设置数据库名
Table1.TableName :='RYGL.db'; //设置表名
Table1.TableType :=ttParadox; //设置表的类型
if not table1.Exists then //如果表不存在
begin
with table1 do begin
with FieldDefs do begin //以下建立字段
Clear;
With AddFieldDef do begin //建立BH字段,是必填字段
Name:='BH';
DataType:=ftString;
Required:=True;
Size:=8;
end;
with AddFieldDef do begin //建立XM字段,是必填字段
Name:='XM';
DataType:=ftString;
Required:=True;
Size:=10;
end;
with AddFieldDef do begin // 建立NL字段
Name:='NL';
DataType:=ftInteger;
end;
with AddFieldDef do begin // 建立HF字段
Name:='HF';
DataType:=ftBoolean;
end;
end;
with IndexDefs do begin //以下是建立表的索引
clear;
with Addindexdef do begin //建立BH索引,索引字段是BH,是主键索引
Name:='BH';
Fields:='BH';
Options:=[ixPrimary];
end;
with Addindexdef do begin //建立XM索引,索引字段是XM
Name:='XM';
Fields:='XM';
end;
end;
CreateTable; //创建表
end;
end;
Table1.Open ; //打开表
Table1.Append; //添加一条新记录
Table1.FieldByName('BH').AsString :='01001001'; //以下是给新记录的各字段赋值
Table1.FieldByName('XM').AsString :='王和平';
Table1.FieldByName('NL').AsInteger :=23;
Table1.FieldByName('HF').AsBoolean :=True;
Table1.Post ; //保存记录
Table1.Append;
Table1.FieldByName('BH').AsString :='01001002';
Table1.FieldByName('XM').AsString :='李小华';
Table1.FieldByName('NL').AsInteger :=21;
Table1.FieldByName('HF').AsBoolean :=False;
Table1.Post ;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -