算了,我把整个源码帖进来吧,希望大家多多指点
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, AdoMakeMdb, Db, ADODB, Grids, DBGrids, StdCtrls, ZIPACCESS,
Halcn6db, MyPath;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
AdoMakeMdb1: TAdoMakeMdb; //用ADO动态生成数据库的控件
Panel1: TPanel;
Panel2: TPanel;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
MyPath1: TMyPath; //包含Windows系统路径.本程序路径的控件
DataSource1: TDataSource;
CreateHalcyonDataSet1: TCreateHalcyonDataSet;
HalcyonDataSet1: THalcyonDataSet;
DataSource2: TDataSource;
ZipAccess1: TZipAccess; //ACCESS数据库压缩控件
ADOQuery1: TADOQuery;
Panel7: TPanel;
Panel8: TPanel;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
ADOConnection1: TADOConnection;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
procedure LookFileSize;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
s: string;
begin
//建立空DBF数据库
HalcyonDataSet1.DatabaseName := MyPath1.SelfPath;
HalcyonDataSet1.TableName := 'CDBF.DBF';
S := MyPath1.AddPath('CDBF.DBF');
if not FileExists(S) then
begin
with CreateHalcyonDataSet1.CreateFields do
begin
Add('编号;N;10;0');
ADD('姓名;C;16;0');
ADD('工资;N;7;2');
ADD('婚否;L;1;0');
end;
CreateHalcyonDataSet1.Execute;
end
else
HalcyonDataSet1.Active := true;
S := MyPath1.AddPath('CMDB.MDB');
//建立空的Access库
ADOConnection1.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Password="";' +
'User ID=Admin;' +
'Data Source=' + S + ';' +
'Mode=Share Deny None;' +
'Extended Properties="";' +
'Locale Identifier=2052;' +
'Jet OLEDB:System database="";' +
'Jet OLEDB:Registry Path="";' +
'Jet OLEDB
atabase Password="";' +
'Jet OLEDB:Engine Type=5;' +
'Jet OLEDB
atabase Locking Mode=1;' +
'Jet OLEDB:Global Partial Bulk Ops=2;' +
'Jet OLEDB:Global Bulk Transactions=1;' +
'Jet OLEDB:New Database Password="";' +
'Jet OLEDB:Create System Database=False;' +
'Jet OLEDB:Encrypt Database=False;' +
'Jet OLEDB
on''t Copy Locale on Compact=False;' +
'Jet OLEDB:Compact Without Replica Repair=False;' +
'Jet OLEDB:SFP=False';
ADOQuery1.ConnectionString := ADOConnection1.ConnectionString;
if not FileExists(S) then
begin
//建库
AdoMakeMdb1.DBName := S;
AdoMakeMdb1.MakeNewDB;
//建表
ADOQuery1.Close;
ADOQuery1.SQL.Text :=
'CREATE TABLE CS (' +
'编号 INTEGER,' +
'姓名 VARCHAR (16) NOT NULL,' +
'工资 CURRENCY ,' +
'婚否 LOGICAL)';
ADOQuery1.ExecSQL;
end;
ADOTable1.TableName := 'CS';
ADOTable1.Active := true;
//显示尺寸
LookFileSize;
end;
procedure TForm1.LookFileSize;
var
FF: TSearchrec;
begin
if FindFirst(MyPath1.SelfPath + 'CMDB.MDB', faAnyFile, FF) = 0 then
panel7.Caption := 'MDB数据库尺寸: ' + inttostr(FF.Size) + ' 字节';
if FindFirst(MyPath1.SelfPath + 'CDBF.DBF', faAnyFile, FF) = 0 then
panel8.Caption := 'DBF数据库尺寸: ' + inttostr(FF.Size) + ' 字节';
findclose(FF);
end;
//删除全部数据
procedure TForm1.Button4Click(Sender: TObject);
var
I: Integer;
begin
//ADOTable1.DeleteRecords(arAll);
i := 0;
ADOTable1.First;
while not ADOTable1.eof do
begin
INC(i);
Application.ProcessMessages;
Label1.Caption := inttostr(i);
ADOTable1.DeleteRecords(arCurrent);
end;
end;
//递增100个数据
procedure TForm1.Button1Click(Sender: TObject);
var
I, k: Integer;
begin
k := ADOTable1.RecordCount;
for I := 1 to 100 do // Iterate
begin
Application.ProcessMessages;
Label1.caption := inttostr(I );
ADOTable1.Append;
ADOTable1.FieldByName('编号').AsInteger := I+k;
ADOTable1.FieldByName('姓名').AsString := '张老' + inttostr(i+k);
ADOTable1.FieldByName('工资').AsFloat := 3000.33;
ADOTable1.FieldByName('婚否').AsBoolean := true;
end;
ADOTable1.Post;
LookFileSize;
end;
//递增1000个数据
procedure TForm1.Button2Click(Sender: TObject);
var
I, k: Integer;
begin
k := ADOTable1.RecordCount;
for I := 1 to 1000 do
begin
Application.ProcessMessages;
Label1.caption := inttostr(I );
ADOTable1.Append;
ADOTable1.FieldByName('编号').AsInteger := I+k;
ADOTable1.FieldByName('姓名').AsString := '张老' + inttostr(i+k);
ADOTable1.FieldByName('工资').AsFloat := 3000.33;
ADOTable1.FieldByName('婚否').AsBoolean := true;
end;
ADOTable1.Post;
LookFileSize;
end;
//递增10000个数据
procedure TForm1.Button3Click(Sender: TObject);
var
I, k: Integer;
begin
k := ADOTable1.RecordCount;
for I := 1 to 10000 do // Iterate
begin
Application.ProcessMessages;
Label1.caption := inttostr(I );
ADOTable1.Append;
ADOTable1.FieldByName('编号').AsInteger := I+K;
ADOTable1.FieldByName('姓名').AsString := '张老' + inttostr(i+k);
ADOTable1.FieldByName('工资').AsFloat := 3000.33;
ADOTable1.FieldByName('婚否').AsBoolean := true;
end;
ADOTable1.Post;
LookFileSize;
end;
//压缩MDB
procedure TForm1.Button5Click(Sender: TObject);
begin
ADOTable1.Active := False;
ADOConnection1.Close;
ADOConnection1.Mode:=cmUnknown;
ZipAccess1.Zip;
ADOConnection1.Open;
ADOTable1.Active := True;
LookFileSize;
end;
//DBF增加100个数据
procedure TForm1.Button7Click(Sender: TObject);
var
I, k: Integer;
begin
k := HalcyonDataSet1.RecordCount;
for I :=1 to 100 do // Iterate
begin
Application.ProcessMessages;
Label2.caption := inttostr(I );
HalcyonDataSet1.Append;
HalcyonDataSet1.FieldByName('编号').AsInteger := I+k;
HalcyonDataSet1.FieldByName('姓名').AsString := '张老' + inttostr(i+k);
HalcyonDataSet1.FieldByName('工资').AsFloat := 3000.33;
HalcyonDataSet1.FieldByName('婚否').AsBoolean := true;
end;
HalcyonDataSet1.Post;
LookFileSize;
end;
procedure TForm1.Button10Click(Sender: TObject);
var
I, k: Integer;
begin
k := HalcyonDataSet1.RecordCount;
for I := 1 to 1000 do // Iterate
begin
Application.ProcessMessages;
Label2.caption := inttostr(I);
HalcyonDataSet1.Append;
HalcyonDataSet1.FieldByName('编号').AsInteger := I+k;
HalcyonDataSet1.FieldByName('姓名').AsString := '张老' + inttostr(i+k);
HalcyonDataSet1.FieldByName('工资').AsFloat := 3000.33;
HalcyonDataSet1.FieldByName('婚否').AsBoolean := true;
end;
HalcyonDataSet1.Post;
LookFileSize;
end;
procedure TForm1.Button11Click(Sender: TObject);
var
I, k: Integer;
begin
k := HalcyonDataSet1.RecordCount;
for I := 1 to 10000 do // Iterate
begin
Application.ProcessMessages;
Label2.caption := inttostr(I );
HalcyonDataSet1.Append;
HalcyonDataSet1.FieldByName('编号').AsInteger := I+k;
HalcyonDataSet1.FieldByName('姓名').AsString := '张老' + inttostr(i+k);
HalcyonDataSet1.FieldByName('工资').AsFloat := 3000.33;
HalcyonDataSet1.FieldByName('婚否').AsBoolean := true;
end;
HalcyonDataSet1.Post;
LookFileSize;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
I: Integer;
begin
i := 0;
HalcyonDataSet1.First;
while not HalcyonDataSet1.eof do
begin
INC(i);
Application.ProcessMessages;
Label2.Caption := inttostr(i);
HalcyonDataSet1.Delete;
end;
LookFileSize;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
HalcyonDataSet1.Active:=false;
HalcyonDataSet1.Exclusive:=True;
HalcyonDataSet1.Active:=True;
HalcyonDataSet1.Pack;
LookFileSize;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
HalcyonDataSet1.Active:=false;
HalcyonDataSet1.Exclusive:=True;
HalcyonDataSet1.Active:=True;
HalcyonDataSet1.ZAP;
LookFileSize;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
I,K:Integer;
begin
k := ADOTable1.RecordCount;
ADOTable1.Active:=False;
for I := 1 to 100 do
begin
Application.ProcessMessages;
Label1.caption := inttostr(I );
ADOQuery1.Close;
ADOQuery1.SQL.Text :=
'INSERT INTO CS (编号,姓名,工资,婚否) VALUES ('+
inttostr(I+k)+',"张老'+inttostr(I+k)+'",'+'3333.33,'+'TRUE)';
ADOQuery1.ExecSQL;
end;
Application.ProcessMessages;
ADOTable1.Active:=true;
DBGrid1.Refresh;
end;
end.