unit1.~pas

来自「精彩编程百例75~100 其中有媒体播放器 SQL语言编辑器 ADO方法连接多个」· ~PAS 代码 · 共 92 行

~PAS
92
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBTables, DB, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Session1: TSession;
    Table1: TTable;
    Label1: TLabel;
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i:TStringList; {字符串列表变量}
reply:Integer;
begin
i:=TStringlist.Create;
Session.GetAliasNames(i); {取得别名列表}
if (i.IndexOf('student')=-1) then {判断别名是否存在}
begin
reply:=Application.MessageBox('别名student不存在,现在创建吗?','BDE信息窗口'
,mb_OKCancel);{增加一个名为student的数据库别名}
if reply=IDCANCEL then
begin
i.Free;
Exit;
end;
Session.AddStandardAlias('student','D:\Program Files\Common Files\Borland Shared\Data','Paradox');
Session.SaveConfigFile; {BDE配置文件存盘}
end ;
i.Clear; {取得别名student中的所有表格名称列表}
Session.GetTableNames('student','',False,False,i);
if (i.IndexOf('info')=-1) then {判断表格是否存在}
begin
reply:=Application.MessageBox('别名student中不存在表格info,现在创建吗?','表格信息窗口',mb_OKCancel);
if reply=IDCANCEL then
begin
i.Free;
Exit;
end;
with table1 do
begin
Active:=false;
DatabaseName:='student'; {数据库别名}
TableName:='info';{表格名}
TableType:=ttParadox;{数据库类型}
with FieldDefs do
begin {增加字段}
Clear;
Add('Sno',ftString,30,False); { 学号String(30)}
Add('Sname',ftString,30,False); {姓名 String(30)}
Add('sdepartment',ftString,20,False); {系 String(20)}
Add('sage',ftinteger,0,False); {年龄 Date}
Add('sgrade',ftInteger,0,False); {年级 Integer}
end;
with IndexDefs do
begin {增加索引}
Clear; {按学号建立主索引}
Add('nameindex','sno',[ixPrimary,ixUnique]);
end;
CreateTable; {创建表格}
end;
end ;
i.free;{释放变量i}
end;


procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  close;
end;

end.

⌨️ 快捷键说明

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