Z
zoulin
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:
本人有一段程序是用来删除ini文件的,可是不知为什么文件总是不能被正确删除。程序如下:
setdate1:=tsetdate1.Create(Application);
setdate1.Caption:=setdate1.Caption+_filtratechart((sender as TMenuItem).caption);
setdate1.ShowModal;
setdate1.Free;
if _dialogok then
begin
sthint1.Show;
sthint1.Update;
toassure1:=ttoassure1.Create(Application);
toassure1.Caption:=_filtratechart((sender as TMenuItem).caption);
sthint1.close;
toassure1.ShowModal;
toassure1.Free;
end;
_delfile(_inilistview)
unit setdate;
interface
uses
wpublic,SysUtils, Windows, Forms, StdCtrls,Dialogs, Mask, ToolEdit,
Controls, Buttons, Classes, RXCtrls;
type
Tsetdate1 = class(TForm)
RxLabel1: TRxLabel;
RxLabel2: TRxLabel;
btnok: TBitBtn;
btnexit: TBitBtn;
bgndate: TDateEdit;
enddate: TDateEdit;
procedure FormCreate(Sender: TObject);
procedure btnokClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject;
var Key: Char);
end;
var
setdate1: Tsetdate1;
implementation
{$R *.DFM}
procedure Tsetdate1.FormCreate(Sender: TObject);
begin
_inilistview:=_clidir[5]+_Randomstring+'.ini';
_dialogok:=false;
bgndate.date:=date;
enddate.date:=date;
end;
procedure Tsetdate1.btnokClick(Sender: TObject);
begin
if bgndate.date>enddate.date then
begin
messagebeep(MB_ICONQUESTION);
messagedlg('您输入的结束日期必须大于等于开始日期...',mterror,[mbcancel],0);
enddate.SetFocus;
abort;
end;
_writeinidata(_inilistview,'date','bgndate',datetostr(bgndate.date));
_writeinidata(_inilistview,'date','enddate',datetostr(enddate.date));
_dialogok:=true;
close;
end;
procedure Tsetdate1.FormKeyPress(Sender: TObject;
var Key: Char);
begin
case key of
#13:
begin
Key:=Chr(0);
SelectNext(ActiveControl,True,True);
end;
#27: close;
end;
end;
end.
unit toassure;
interface
uses
wpublic,SysUtils,Forms,graphics,IniFiles, Db, DBTables, Grids, DBGrids,
RXDBCtrl, StdCtrls, Buttons, DBCtrls, Controls, ExtCtrls, Classes;
type
Ttoassure1 = class(TForm)
Panel2: TPanel;
DBNavigator1: TDBNavigator;
btnfind: TBitBtn;
BitBtn6: TBitBtn;
btnprint: TBitBtn;
RxDBGrid1: TRxDBGrid;
btnfilter: TSpeedButton;
btnunfilter: TSpeedButton;
Qbonded: TQuery;
Qdraw: TQuery;
Table1: TTable;
procedure FormCreate(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure btnfilterClick(Sender: TObject);
procedure btnunfilterClick(Sender: TObject);
procedure btnprintClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
toassure1: Ttoassure1;
implementation
uses setdate,setfilter, dmdata, printfield, re_toassure;
{$R *.DFM}
procedure Ttoassure1.FormCreate(Sender: TObject);
var
p_tempdb:string;
p_inifile:TIniFile;
//表结构存放ini文件
p_bgnd,p_endd:tdate;
p_acnum:string;
p_bondedmoney:real;
p_drawmoney:real;
begin
p_tempdb:=_clidir[5]+'assuretotal.db';
p_bgnd:=strtodate(_readinidata(_inilistview,'date','bgndate'));
p_endd:=strtodate(_readinidata(_inilistview,'date','enddate'));
_createtable(p_tempdb);
dmdata1.Tassuretotal.DatabaseName:=_alias;
dmdata1.Tassuretotal.TableName:=p_tempdb;
dmdata1.Tassuretotal.Open;
table1.DatabaseName:=_alias;
table1.TableName:=_serdir[5]+'account.db';
table1.IndexFieldNames:='acnum';
table1.Filtered:=true;
table1.Filter:='ynstop=false';
table1.Open;
Qbonded.UnPrepare;
Qbonded.ParamByName('_bgndate').asdatetime:=p_bgnd;
Qbonded.ParamByName('_enddate').asdatetime:=p_endd;
Qbonded.Prepare;
Qbonded.Open;
Qdraw.UnPrepare;
Qdraw.ParamByName('_bgndate').asdatetime:=p_bgnd;
Qdraw.ParamByName('_enddate').asdatetime:=p_endd;
Qdraw.Prepare;
Qdraw.Open;
table1.First;
while not table1.Eofdo
begin
p_acnum:=table1.fieldbyname('acnum').asstring;
p_bondedmoney:=0;
p_drawmoney:=0;
if _findquery(Qbonded,'acnum',p_acnum,false) then
p_bondedmoney:=Qbonded.FieldByName('trademoney').asfloat;
if _findquery(Qdraw,'acnum',p_acnum,false) then
p_drawmoney:=Qdraw.FieldByName('trademoney').asfloat;
if (p_drawmoney<>0) or (p_bondedmoney<>0) then
begin
dmdata1.Tassuretotal.append;
dmdata1.Tassuretotal.fieldbyname('num_ywy').asstring:=table1.fieldbyname('num_ywy').asstring;
dmdata1.Tassuretotal.fieldbyname('acnum').asstring:=p_acnum;
dmdata1.Tassuretotal.fieldbyname('bondedmoney').asfloat:=p_bondedmoney;
dmdata1.Tassuretotal.fieldbyname('drawmoney').asfloat:=p_drawmoney;
dmdata1.Tassuretotal.fieldbyname('balancemoney').asfloat:=p_bondedmoney+p_drawmoney;
dmdata1.Tassuretotal.post;
end;
table1.Next;
end;
table1.Close;
Qbonded.Close;
Qdraw.Close;
dmdata1.Tassuretotal.First;
btnfind.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
btnprint.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
btnfilter.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
btnunfilter.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
_setdbgridcolumnproper(rxdbgrid1);
dmdata1.query1.Close;
dmdata1.query1.UnPrepare;
dmdata1.query1.SQL.clear;
dmdata1.query1.SQL.add('select acnum from "'+p_tempdb+'" group by acnum order by acnum');
dmdata1.query1.Prepare;
dmdata1.query1.Open;
dmdata1.query1.First;
p_inifile:=TIniFile.Create(_inilistview);
p_inifile.writeString('name','name',caption);
p_inifile.writeString('list','remark','acnum');
while not dmdata1.query1.Eofdo
begin
p_inifile.writeString('list','lv'+inttostr(dmdata1.query1.RecNo),
dmdata1.query1.FieldByName('acnum').asstring);
p_inifile.writeString('data',dmdata1.query1.FieldByName('acnum').asstring,'1');
dmdata1.query1.Next;
end;
dmdata1.query1.Close;
dmdata1.query1.UnPrepare;
dmdata1.query1.SQL.clear;
dmdata1.query1.SQL.add('select num_ywy from "'+p_tempdb+'" group by num_ywy order by num_ywy');
dmdata1.query1.Prepare;
dmdata1.query1.Open;
p_inifile.writeString('listb','remark','num_ywy');
dmdata1.query1.First;
while not dmdata1.query1.Eofdo
begin
p_inifile.writeString('listb','lv'+inttostr(dmdata1.query1.RecNo),
dmdata1.query1.FieldByName('num_ywy').asstring);
p_inifile.writeString('datab',dmdata1.query1.FieldByName('num_ywy').asstring,'1');
dmdata1.query1.Next;
end;
p_inifile.free;
end;
procedure Ttoassure1.BitBtn6Click(Sender: TObject);
begin
close;
end;
procedure Ttoassure1.btnfilterClick(Sender: TObject);
var
p_inifile:TIniFile;
p_acnum,p_num_ywy:string;
begin
setfilter1:=tsetfilter1.Create(Application);
setfilter1.ShowModal;
setfilter1.Free;
if _dialogok then
begin
p_inifile:=TIniFile.Create(_inilistview);
dmdata1.Tassuretotal.DisableControls;
dmdata1.Tassuretotal.Filtered:=false;
dmdata1.Tassuretotal.First;
while not dmdata1.Tassuretotal.Eofdo
begin
p_num_ywy:=dmdata1.Tassuretotal.FieldByName('num_ywy').asstring;
p_acnum:=dmdata1.Tassuretotal.FieldByName('acnum').asstring;
p_acnum:=p_inifile.readstring('data',p_acnum,'');
p_num_ywy:=p_inifile.readstring('datab',p_num_ywy,'');
dmdata1.Tassuretotal.Edit;
if (p_acnum='1') and (p_num_ywy='1')
then
dmdata1.Tassuretotal.FieldByName('myfilter').asstring:='*'
else
dmdata1.Tassuretotal.FieldByName('myfilter').asstring:='';
dmdata1.Tassuretotal.post;
dmdata1.Tassuretotal.Next;
end;
dmdata1.Tassuretotal.Filtered:=true;
dmdata1.Tassuretotal.First;
dmdata1.Tassuretotal.EnableControls;
dmdata1.Tassuretotal.Refresh;
p_inifile.free;
end;
end;
procedure Ttoassure1.btnunfilterClick(Sender: TObject);
begin
dmdata1.Tassuretotal.Filtered:=false;
dmdata1.Tassuretotal.Refresh;
end;
procedure Ttoassure1.btnprintClick(Sender: TObject);
begin
re_toassure1.preview;
end;
procedure Ttoassure1.FormDestroy(Sender: TObject);
begin
dmdata1.Tassuretotal.Close;
dmdata1.Tassuretotal.DeleteTable;
end;
end.
unit wpublic;
interface
uses
SysUtils,Forms,windows,IniFiles,menus,Dialogs,db,dbtables,dbgrids,bde,
Controls;
var
_inilistview:string;
//保存用于ini文件名称
_dialogok:boolean;
//按下自定义对话框的确认键
_alias: String;
//系统数据引擎
procedure _writeinidata(_filename,_key,_data,_value:string);
function _readinidata(_filename,_key,_data:string;_ynvalue:boolean=true):string;
function _delfile(_fn:string):boolean;
//删除文件
implementation
procedure _writeinidata(_filename,_key,_data,_value:string);
var
_inifile:TIniFile;
begin
_inifile:=TIniFile.Create(_filename);
_inifile.writeString(_key,_data,_value);
_inifile.free;
end;
function _delfile(_fn:string):boolean;
//删除文件
var
p_charchar;
begin
if FileExists(_fn) then
begin
getmem(p_char,length(trim(_fn))+1);
StrPCopy(p_char,_fn);
result:=DeleteFile(p_char);
end else
result:=false;
end;
end.
本人有一段程序是用来删除ini文件的,可是不知为什么文件总是不能被正确删除。程序如下:
setdate1:=tsetdate1.Create(Application);
setdate1.Caption:=setdate1.Caption+_filtratechart((sender as TMenuItem).caption);
setdate1.ShowModal;
setdate1.Free;
if _dialogok then
begin
sthint1.Show;
sthint1.Update;
toassure1:=ttoassure1.Create(Application);
toassure1.Caption:=_filtratechart((sender as TMenuItem).caption);
sthint1.close;
toassure1.ShowModal;
toassure1.Free;
end;
_delfile(_inilistview)
unit setdate;
interface
uses
wpublic,SysUtils, Windows, Forms, StdCtrls,Dialogs, Mask, ToolEdit,
Controls, Buttons, Classes, RXCtrls;
type
Tsetdate1 = class(TForm)
RxLabel1: TRxLabel;
RxLabel2: TRxLabel;
btnok: TBitBtn;
btnexit: TBitBtn;
bgndate: TDateEdit;
enddate: TDateEdit;
procedure FormCreate(Sender: TObject);
procedure btnokClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject;
var Key: Char);
end;
var
setdate1: Tsetdate1;
implementation
{$R *.DFM}
procedure Tsetdate1.FormCreate(Sender: TObject);
begin
_inilistview:=_clidir[5]+_Randomstring+'.ini';
_dialogok:=false;
bgndate.date:=date;
enddate.date:=date;
end;
procedure Tsetdate1.btnokClick(Sender: TObject);
begin
if bgndate.date>enddate.date then
begin
messagebeep(MB_ICONQUESTION);
messagedlg('您输入的结束日期必须大于等于开始日期...',mterror,[mbcancel],0);
enddate.SetFocus;
abort;
end;
_writeinidata(_inilistview,'date','bgndate',datetostr(bgndate.date));
_writeinidata(_inilistview,'date','enddate',datetostr(enddate.date));
_dialogok:=true;
close;
end;
procedure Tsetdate1.FormKeyPress(Sender: TObject;
var Key: Char);
begin
case key of
#13:
begin
Key:=Chr(0);
SelectNext(ActiveControl,True,True);
end;
#27: close;
end;
end;
end.
unit toassure;
interface
uses
wpublic,SysUtils,Forms,graphics,IniFiles, Db, DBTables, Grids, DBGrids,
RXDBCtrl, StdCtrls, Buttons, DBCtrls, Controls, ExtCtrls, Classes;
type
Ttoassure1 = class(TForm)
Panel2: TPanel;
DBNavigator1: TDBNavigator;
btnfind: TBitBtn;
BitBtn6: TBitBtn;
btnprint: TBitBtn;
RxDBGrid1: TRxDBGrid;
btnfilter: TSpeedButton;
btnunfilter: TSpeedButton;
Qbonded: TQuery;
Qdraw: TQuery;
Table1: TTable;
procedure FormCreate(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure btnfilterClick(Sender: TObject);
procedure btnunfilterClick(Sender: TObject);
procedure btnprintClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
toassure1: Ttoassure1;
implementation
uses setdate,setfilter, dmdata, printfield, re_toassure;
{$R *.DFM}
procedure Ttoassure1.FormCreate(Sender: TObject);
var
p_tempdb:string;
p_inifile:TIniFile;
//表结构存放ini文件
p_bgnd,p_endd:tdate;
p_acnum:string;
p_bondedmoney:real;
p_drawmoney:real;
begin
p_tempdb:=_clidir[5]+'assuretotal.db';
p_bgnd:=strtodate(_readinidata(_inilistview,'date','bgndate'));
p_endd:=strtodate(_readinidata(_inilistview,'date','enddate'));
_createtable(p_tempdb);
dmdata1.Tassuretotal.DatabaseName:=_alias;
dmdata1.Tassuretotal.TableName:=p_tempdb;
dmdata1.Tassuretotal.Open;
table1.DatabaseName:=_alias;
table1.TableName:=_serdir[5]+'account.db';
table1.IndexFieldNames:='acnum';
table1.Filtered:=true;
table1.Filter:='ynstop=false';
table1.Open;
Qbonded.UnPrepare;
Qbonded.ParamByName('_bgndate').asdatetime:=p_bgnd;
Qbonded.ParamByName('_enddate').asdatetime:=p_endd;
Qbonded.Prepare;
Qbonded.Open;
Qdraw.UnPrepare;
Qdraw.ParamByName('_bgndate').asdatetime:=p_bgnd;
Qdraw.ParamByName('_enddate').asdatetime:=p_endd;
Qdraw.Prepare;
Qdraw.Open;
table1.First;
while not table1.Eofdo
begin
p_acnum:=table1.fieldbyname('acnum').asstring;
p_bondedmoney:=0;
p_drawmoney:=0;
if _findquery(Qbonded,'acnum',p_acnum,false) then
p_bondedmoney:=Qbonded.FieldByName('trademoney').asfloat;
if _findquery(Qdraw,'acnum',p_acnum,false) then
p_drawmoney:=Qdraw.FieldByName('trademoney').asfloat;
if (p_drawmoney<>0) or (p_bondedmoney<>0) then
begin
dmdata1.Tassuretotal.append;
dmdata1.Tassuretotal.fieldbyname('num_ywy').asstring:=table1.fieldbyname('num_ywy').asstring;
dmdata1.Tassuretotal.fieldbyname('acnum').asstring:=p_acnum;
dmdata1.Tassuretotal.fieldbyname('bondedmoney').asfloat:=p_bondedmoney;
dmdata1.Tassuretotal.fieldbyname('drawmoney').asfloat:=p_drawmoney;
dmdata1.Tassuretotal.fieldbyname('balancemoney').asfloat:=p_bondedmoney+p_drawmoney;
dmdata1.Tassuretotal.post;
end;
table1.Next;
end;
table1.Close;
Qbonded.Close;
Qdraw.Close;
dmdata1.Tassuretotal.First;
btnfind.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
btnprint.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
btnfilter.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
btnunfilter.Enabled:=dmdata1.Tassuretotal.RecordCount>0;
_setdbgridcolumnproper(rxdbgrid1);
dmdata1.query1.Close;
dmdata1.query1.UnPrepare;
dmdata1.query1.SQL.clear;
dmdata1.query1.SQL.add('select acnum from "'+p_tempdb+'" group by acnum order by acnum');
dmdata1.query1.Prepare;
dmdata1.query1.Open;
dmdata1.query1.First;
p_inifile:=TIniFile.Create(_inilistview);
p_inifile.writeString('name','name',caption);
p_inifile.writeString('list','remark','acnum');
while not dmdata1.query1.Eofdo
begin
p_inifile.writeString('list','lv'+inttostr(dmdata1.query1.RecNo),
dmdata1.query1.FieldByName('acnum').asstring);
p_inifile.writeString('data',dmdata1.query1.FieldByName('acnum').asstring,'1');
dmdata1.query1.Next;
end;
dmdata1.query1.Close;
dmdata1.query1.UnPrepare;
dmdata1.query1.SQL.clear;
dmdata1.query1.SQL.add('select num_ywy from "'+p_tempdb+'" group by num_ywy order by num_ywy');
dmdata1.query1.Prepare;
dmdata1.query1.Open;
p_inifile.writeString('listb','remark','num_ywy');
dmdata1.query1.First;
while not dmdata1.query1.Eofdo
begin
p_inifile.writeString('listb','lv'+inttostr(dmdata1.query1.RecNo),
dmdata1.query1.FieldByName('num_ywy').asstring);
p_inifile.writeString('datab',dmdata1.query1.FieldByName('num_ywy').asstring,'1');
dmdata1.query1.Next;
end;
p_inifile.free;
end;
procedure Ttoassure1.BitBtn6Click(Sender: TObject);
begin
close;
end;
procedure Ttoassure1.btnfilterClick(Sender: TObject);
var
p_inifile:TIniFile;
p_acnum,p_num_ywy:string;
begin
setfilter1:=tsetfilter1.Create(Application);
setfilter1.ShowModal;
setfilter1.Free;
if _dialogok then
begin
p_inifile:=TIniFile.Create(_inilistview);
dmdata1.Tassuretotal.DisableControls;
dmdata1.Tassuretotal.Filtered:=false;
dmdata1.Tassuretotal.First;
while not dmdata1.Tassuretotal.Eofdo
begin
p_num_ywy:=dmdata1.Tassuretotal.FieldByName('num_ywy').asstring;
p_acnum:=dmdata1.Tassuretotal.FieldByName('acnum').asstring;
p_acnum:=p_inifile.readstring('data',p_acnum,'');
p_num_ywy:=p_inifile.readstring('datab',p_num_ywy,'');
dmdata1.Tassuretotal.Edit;
if (p_acnum='1') and (p_num_ywy='1')
then
dmdata1.Tassuretotal.FieldByName('myfilter').asstring:='*'
else
dmdata1.Tassuretotal.FieldByName('myfilter').asstring:='';
dmdata1.Tassuretotal.post;
dmdata1.Tassuretotal.Next;
end;
dmdata1.Tassuretotal.Filtered:=true;
dmdata1.Tassuretotal.First;
dmdata1.Tassuretotal.EnableControls;
dmdata1.Tassuretotal.Refresh;
p_inifile.free;
end;
end;
procedure Ttoassure1.btnunfilterClick(Sender: TObject);
begin
dmdata1.Tassuretotal.Filtered:=false;
dmdata1.Tassuretotal.Refresh;
end;
procedure Ttoassure1.btnprintClick(Sender: TObject);
begin
re_toassure1.preview;
end;
procedure Ttoassure1.FormDestroy(Sender: TObject);
begin
dmdata1.Tassuretotal.Close;
dmdata1.Tassuretotal.DeleteTable;
end;
end.
unit wpublic;
interface
uses
SysUtils,Forms,windows,IniFiles,menus,Dialogs,db,dbtables,dbgrids,bde,
Controls;
var
_inilistview:string;
//保存用于ini文件名称
_dialogok:boolean;
//按下自定义对话框的确认键
_alias: String;
//系统数据引擎
procedure _writeinidata(_filename,_key,_data,_value:string);
function _readinidata(_filename,_key,_data:string;_ynvalue:boolean=true):string;
function _delfile(_fn:string):boolean;
//删除文件
implementation
procedure _writeinidata(_filename,_key,_data,_value:string);
var
_inifile:TIniFile;
begin
_inifile:=TIniFile.Create(_filename);
_inifile.writeString(_key,_data,_value);
_inifile.free;
end;
function _delfile(_fn:string):boolean;
//删除文件
var
p_charchar;
begin
if FileExists(_fn) then
begin
getmem(p_char,length(trim(_fn))+1);
StrPCopy(p_char,_fn);
result:=DeleteFile(p_char);
end else
result:=false;
end;
end.