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

📄 tableexam.pas

📁 《delphi数据库设计与实例开发》随书光盘
💻 PAS
字号:
unit TableExam;

interface

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

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    ListBox1: TListBox;
    DBGrid1: TDBGrid;
    Label1: TLabel;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Label3: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Str:String;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 with Combobox1 do
   begin
     Items.Clear;
     session.GetAliasNames(Items); //获取系统数据库别名
     Text:=Items[0];
   end;
 Label2.Caption:='';
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
 try
  With table1 do
   Begin
    If Active then
      Active:=False;
    DatabaseName:=str;
    TableName:=ListBox1.Items[ListBox1.ItemIndex];//更改TableName属性值
    Label2.Caption:=ListBox1.Items[ListBox1.ItemIndex];
    Active:=True;//重新激活连接
   End;
 except
   On E:EdatabaseError do
   ShowMessage(E.Message);
 end;
end;

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
  str:=Combobox1.Items[Combobox1.ItemIndex];
  try
    with Listbox1 do
     begin
      Items.Clear;
      Session.GetTableNames(str,'',true,false,Listbox1.Items);//获得数据表名
     end;
  except
    showmessage('连接数据库错误!');
  end;
end;

end.

⌨️ 快捷键说明

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