📄 cardata.pas
字号:
unit cardata;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables,Registry;
type
TData = class(TDataModule)
Database: TDatabase;
usesTable: TTable;
usesDataSource: TDataSource;
cartypeTable: TTable;
cartypeDataSource: TDataSource;
colorTable: TTable;
colorDataSource: TDataSource;
springTable: TTable;
springDataSource: TDataSource;
usetypeTable: TTable;
usetypeDataSource: TDataSource;
repertoryQuery: TQuery;
repertoryDataSource1: TDataSource;
repertoryTable: TTable;
repertoryDataSource: TDataSource;
saleQuery: TQuery;
saleDataSource: TDataSource;
saleTable: TTable;
saleDataSource1: TDataSource;
repsaTable: TTable;
repsaDataSource: TDataSource;
comQuery: TQuery;
comDataSource: TDataSource;
profitTable: TTable;
profitDataSource: TDataSource;
profitQuery: TQuery;
profitDataSource1: TDataSource;
saleQuery1: TQuery;
usesQuery: TQuery;
Session1: TSession;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Data: TData;
implementation
{$R *.DFM}
procedure TData.DataModuleCreate(Sender: TObject);
var
registerTemp : TRegistry;
bData : array[ 0..0 ] of byte;
SysDir : array[0..255] of char;
begin
registerTemp := TRegistry.Create; //建立一个Registry实例
with registerTemp do
begin
RootKey:=HKEY_LOCAL_MACHINE;//设置根键值为HKEY_LOCAL_MACHINE
//找到Software\ODBC\ODBC.INI\ODBC Data Sources
if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',True) then
begin //注册一个DSN名称
WriteString( 'carsale', 'Microsoft Access Driver (*.mdb)' );
end
else
begin//创建键值失败
{ memo1.lines.add('增加ODBC数据源失败'); }
showmessage('增加ODBC数据源失败');
exit;
end;
CloseKey;
//找到或创建Software\ODBC\ODBC.INI\MyAccess,写入DSN配置信息
if OpenKey('Software\ODBC\ODBC.INI\carsale',True) then
begin
GetSystemDirectory(SysDir,sizeof(SysDir)-1);//得到系统路径
WriteString( 'DBQ',GetCurrentdir+'\cardata\carsale.mdb' );//数据库目录
WriteString( 'Description', 'carsale' );//数据源描述
WriteString( 'Driver', SysDir+'\odbcjt32.dll' );//驱动程序DLL文件
WriteInteger( 'DriverId', 25 );//驱动程序标识
WriteString( 'FIL', 'Ms Access;' );//Filter依据
WriteInteger( 'SafeTransaction', 0 );//支持的事务操作数目
WriteString( 'UID', '' );//用户名称
bData[0] := 0;
WriteBinaryData( 'Exclusive', bData, 1 );//非独占方式
WriteBinaryData( 'ReadOnly', bData, 1 );//非只读方式
end
else//创建键值失败
begin
showmessage('创建键值失败');
exit;
end;
CloseKey;
//找到或创建Software\ODBC\ODBC.INI\MyAccess\Engines\Jet
//写入DSN数据库引擎配置信息
if OpenKey('Software\ODBC\ODBC.INI\MyAccess\Engines\Jet',True) then
begin
WriteString( 'ImplicitCommitSync', 'Yes' );
WriteInteger( 'MaxBufferSize', 512 );//缓冲区大小
WriteInteger( 'PageTimeout', 10 );//页超时
WriteInteger( 'Threads', 3 );//支持的线程数目
WriteString( 'UserCommitSync', 'Yes' );
end
else//创建键值失败
begin
showmessage('创建健值失败');
exit;
end;
CloseKey;
Free; try
database.Connected:=true;
Database.keepconnection:=true;
repertorytable.active:=true;
repertoryquery.active:=true;
salequery.active:=true;
comquery.active:=true;
usestable.active:=true;
usesquery.active:=true;
saletable.active:=true;
salequery1.active:=true;
repsatable.active:=true;
profittable.active:=true;
profitquery.active:=true;
cartypetable.active:=true;
colortable.active:=true;
springtable.active:=true;
usetypetable.active:=true;
session1.Active:=true;
finally
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -