⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 《Delphi百例》源码?禗elphi百例》源码
💻 PAS
字号:
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
ap:TStringList; {字符串列表变量}
answer:Integer;
begin
ap:=TStringlist.Create;
Session.GetAliasNames(ap); {取得别名列表}
if (ap.IndexOf('Cntssamp')=-1) then {判断别名是否存在}
begin
answer:=Application.MessageBox('别名Cntssamp不存在,现在创建吗?','BDE信息窗口'
mb_OKCancel);{增加一个名为Cngzsamp的数据库别名}
if answer=IDCANCEL then
begin
ap.Free;
Exit;
end;
Session.AddStandardAlias('Cntssamp','c:\database','Paradox');
Session.SaveConfigFile; {BDE配置文件存盘}
end ;
ap.Clear; {取得别名Cngzsamp中的所有表格名称列表}
Session.GetTableNames('Cntssamp','',False,False,ap);
if (ap.IndexOf('TSK')=-1) then {判断表格是否存在}
begin
answer:=Application.MessageBox('别名Cntssamp中不存在表格TSK,现在创建吗?','表格信息窗口'

mb_OKCancel);
if answer=IDCANCEL then
begin
ap.Free;
Exit;
end;
with table1 do
begin
Active:=false;
DatabaseName:='Cntssamp'; {数据库别名}
TableName:='TSK';{表格名}
TableType:=ttParadox;{数据库类型}
with FieldDefs do
begin {增加字段}
Clear;
Add('SH',ftString,30,False); {书号 String(30)}
Add('SM',ftString,30,False); {书名 String(30)}
Add('CBS',ftString,20,False); {出版社 String(20)}
Add('CBRQ',ftDate,0,False); {出版日期 Date}
Add('YS',ftInteger,0,False); {页数 Integer}
end;
with IndexDefs do
begin {增加索引}
Clear; {按书号字段建立主索引}
Add('SHSY','SH',[ixPrimary,ixUnique]);
end;
CreateTable; {创建表格}
end;
end ;
ap.free;{释放变量ap}
end;


end.

⌨️ 快捷键说明

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