同意ZH-SH,不过,我还是要分!好坏也有200啊……
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, ExtCtrls, DBCtrls, Grids, DBGrids, ComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
DBNavigator1: TDBNavigator;
DBNavigator2: TDBNavigator;
Table1: TTable;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
tblList:tstringlist;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
tblList := TStringList.Create;
tblList.Add('Country.db');
tblList.Add('Employee.db');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
tblList.Free;
end;
procedure TForm1.PageControl1Change(Sender: TObject);
var
i:Integer;
begin
ShowMessage(IntToStr(PageControl1.ActivePageIndex));
with Table1do
begin
if Active then
Close;
TableName := tblList[PageControl1.ActivePageIndex];
DataSource1.DataSet := Table1;//不知道你为什么要那么干,
//不过我还是把每个属性都
//给赋值一把,免得你说Readonly
end;
for i:=0 to ComponentCount - 1do
begin
if Components is TDBGrid then
with Components as TDBGriddo
if Tag = PageControl1.ActivePageIndex + 1 then
DataSource := DataSource1;
if Components is TDBNavigator then
with Components as TDBNavigatordo
if Tag = PageControl1.ActivePageIndex + 1 then
DataSource := DataSource1;
end;
Table1.Open;
end;
end.