OnDestroy,这也不能解决根本问题
解决方案 »
- 真他妈的气死了,在京东买东西后想认真的发个评论,没想到提示说内容中有屏蔽词,大家看看
- 紧急!quickreport报表反打问题
- 求教如何做类似网际快车等多线程下载工具
- 求助:DELPHI中ASM转换为VC的ASM(20行代码)有关RING0的
- 发票打印问题,急,请指教,谢了
- 请教一个问题~
- Drawcell()在什么情况下被调用处理?
- 关于搜索内存的问题
- 请问Application.handle指的是什么句柄???
- 使用ServerSocket与ClientSocket遇到的问题
- 哪位推荐一本专门讲Delphi基本控件使用的书?
- 谁知道如何怎样将DELPHI中的DBGrid数据转换为EXCEL格式保存起来,先谢了!!!我在线等候
function EmptyDirectory(TheDirectory :String ; Recursive : Boolean) :
Boolean;
var
SearchRec : TSearchRec;
Res : Integer;
begin
Result := False;
TheDirectory := NormalDir(TheDirectory);
Res := FindFirst(TheDirectory + '*.*', faAnyFile, SearchRec);
try
while Res = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
if ((SearchRec.Attr and faDirectory) > 0) and Recursive
then begin
EmptyDirectory(TheDirectory + SearchRec.Name, True);
RemoveDirectory(PChar(TheDirectory + SearchRec.Name));
end
else begin
DeleteFile(PChar(TheDirectory + SearchRec.Name))
end;
end;
Res := FindNext(SearchRec);
end;
Result := True;
finally
FindClose(SearchRec.FindHandle);
end;
end;◇[DELPHI]目录完全删除(deltree)
procedure TForm1.DeleteDirectory(strDir:String);
var
sr: TSearchRec;
FileAttrs: Integer;
strfilename:string;
strPth:string;
begin
strpth:=Getcurrentdir();
FileAttrs := faAnyFile;
if FindFirst(strpth+'\'+strdir+'\*.*', FileAttrs, sr) = 0 then
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
strfilename:=sr.Name;
if fileexists(strpth+'\'+strdir+'\'+strfilename) then
deletefile(strpth+'\'+strdir+'\'+strfilename);
end;
while FindNext(sr) = 0 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
strfilename:=sr.name;
if fileexists(strpth+'\'+strdir+'\'+strfilename) then
deletefile(strpth+'\'+strdir+'\'+strfilename);
end;
end;
FindClose(sr);
removedir(strpth+'\'+strdir);
end;
end;
程序最后那一刹将激发该事件
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
beginend;
我要执行的BAT文件是要删除程序本身。在CloseQuery事件中就执行,太提前了,不行的。
我想的一个问题是,为什么在我那个测试程序中启动BAT语句可以删除自己呢?因为启动BAT文件的一瞬,程序并没有结束,是BAT语句启动到执行的那段时间,程序结束了,被删除了吗?是这样吗?不知道。对我现在这个程序的困惑是,我把启动BAT文件语句放到了最后,按理说不管我的程序在生存期间做了什么,都该很顺利的和我的测试程序一样删除掉自己,可事实并不是这样,所以我想,在close事件中,程序还执行了其他操作,可我该怎么抓住删除自己的良好时机呢?
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
===========================在。dpr中加
procedure DeleteSelf;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
BatchFileName := ChangeFileExt(paramstr(0),'.bat');
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);
// build cmd batch file
Writeln(BatchFile, ':try');
Writeln(BatchFile, 'del "' + ParamStr(0) + '"');
Writeln(BatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);
FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_HIDE;
// create hidden process
if CreateProcess(nil, PChar(BatchFileName), nil, nil,False, IDLE_PRIORITY_CLASS,
nil, nil, StartUpInfo,ProcessInfo) then
begin
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
end;
end;
这里是关键:
...
Application.Run;
DeleteSelf;
end.
绝对保证可以自我删除!!!!!!!!!!!!!!!!1
===========================
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除?超级容易的,一定要给我50分的!!!!!
自我删除我已经实现了,但问题是……算了,自己看吧,这50分啊,您还是多加把劲再说吧。