1.delphi中操作access数据库(建立.mdb文件,压缩数据库)
以下代码在win2k,d6,mdac2.6下测试通过,
编译好的程序在win98第二版无access环境下运行成功.
//=============================================================================
// procedure: gettemppathfilename
// author : ysai
// date : 2003-01-27
// arguments: (none)
// result : string
//=============================================================================
function gettemppathfilename():string;
//取得临时文件名
var
spath,sfile&:array [0..254] of char;
begin
gettemppath(254,spath);
gettempfilename(spath,'~sm',0,sfile);
result:=sfile;
deletefile(pchar(result));
end;
//=============================================================================
// procedure: createaccessfile
// author : ysai
// date : 2003-01-27
// arguments: filename:string;password:string=''
// result : boolean
//=============================================================================
function createaccessfile(filename:string;password:string=''):boolean;
//建立access文件,如果文件存在则失败
var
stempfilename:string;
vcatalog:olevariant;
begin
stempfilename:=gettemppathfilename;
try
vcatalog:=createoleobject('adox.catalog');
vcatalog.create(format(sconnectionstring,[stempfilename,password]));
result:=copyfile(pchar(stempfilename),pchar(filename),true);
deletefile(stempfilename);
except
result:=false;
end;
end;
//=============================================================================
// procedure: compactdatabase
// author : ysai
// date : 2003-01-27
// arguments: afilename,apassword:string
// result : boolean
//=============================================================================
function compactdatabase(afilename,apassword:string):boolean;
//压缩与修复数据库,覆盖源文件
var
stempfilename:string;
vje:olevariant;
begin
stempfilename:=gettemppathfilename;
try
vje:=createoleobject('jro.jetengine');
vje.compactdatabase(format(sconnectionstring,[afilename,apassword]),
format(sconnectionstring,[stempfilename,apassword]));
result:=copyfile(pchar(stempfilename),pchar(afilename),false);
deletefile(stempfilename);
except
result:=false;
end;
end;
//=============================================================================
// procedure: changedatabasepassword
// author : ysai
// date : 2003-01-27
// arguments: afilename,aoldpassword,anewpassword:string
// result : boolean
//=============================================================================
function changedatabasepassword(afilename,aoldpassword,anewpassword:string):boolean;
//修改access数据库密码
var
stempfilename:string;
vje:olevariant;
begin
stempfilename:=gettemppathfilename;
try
vje:=createoleobject('jro.jetengine');
vje.compactdatabase(format(sconnectionstring,[afilename,aoldpassword]),
format(sconnectionstring,[stempfilename,anewpassword]));
result:=copyfile(pchar(stempfilename),pchar(afilename),false);
deletefile(stempfilename);
except
result:=false;
end;
end;
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器