unit1.pas

来自「Delphi_7.0数据库开发源代码。有内容十一章节」· PAS 代码 · 共 83 行

PAS
83
字号
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);
begin
with Table1 do
begin
  Active := False;
  DatabaseName := 'DOCTOR';
  TableType := ttParadox;
  TableName := 'DOCTORINF23';
  if not Table1.Exists then begin
     with FieldDefs do begin
        Clear;
        with AddFieldDef do begin
            Name := '姓名';
            DataType := ftString;
            Required := True;
            Size := 10;
        end;
        with AddFieldDef do begin
             Name := '年龄';
             DataType := ftInteger;
        end;//建立字段定,利用AddFieldDef方法添加一个新的TFieldDef对象
        with AddFieldDef do begin
            Name := '职称';
            DataType := ftString;
            Required := True;
            Size := 10;
        end;
     end;
     with IndexDefs do begin
          Clear;
          with AddIndexDef do begin
          Name := 'MYINDEX';
          Fields := '姓名';
          Options := [ixPrimary];
          end;
     end;  //建立索引
  end;
  CreateTable;
end;
    //Table1.Append ;
    Table1.Open;
    Table1.Edit;
    Table1.FieldByName('姓名').AsString:='刘延';
    Table1.FieldByName('年龄').AsInteger:=22 ;
    Table1.FieldByName('职称').AsString:='医师';
    Table1.Append;
    Table1.Edit;
    Table1.FieldByName('姓名').AsString:='杨晓';
    Table1.FieldByName('年龄').AsInteger:=25 ;
    Table1.FieldByName('职称').AsString:='医师';
    DBGrid1.DataSource:=DataSource1;
    Table1.Active :=True; 
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?