我要比较2个STRINGLIST,可是好象哪里出错了,大家帮看看(50分)

  • 主题发起人 主题发起人 wp231957
  • 开始时间 开始时间
W

wp231957

Unregistered / Unconfirmed
GUEST, unregistred user!
unit saomiao32;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, FileCtrl;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;ListBox1: TListBox;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;FileListBox1: TFileListBox;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;filelistbox1.Directory :='c:/windows/system32';<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;filenamelist:tstringlist;<br> &nbsp;i,j:integer;<br> &nbsp;str,filename:string;<br> &nbsp;findbz:boolean;<br>begin<br> &nbsp;try<br> &nbsp; &nbsp;filenamelist:=tstringlist.Create ;<br> &nbsp; &nbsp;//标准文件列表<br> &nbsp; &nbsp;filenamelist.LoadFromFile(ExtractFilePath(Application.ExeName)+'system32.txt');<br> &nbsp; &nbsp;//第一重循环是当前硬盘上SYSTEM32文件列表<br> &nbsp; &nbsp;for i:=0 to filelistbox1.Items.Count -1 do begin<br> &nbsp; &nbsp; &nbsp;//第2重循环是标准文件列表<br> &nbsp; &nbsp; &nbsp;for j:=0 to filenamelist.Count -1 do &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;str:=filenamelist[j];<br> &nbsp; &nbsp; &nbsp; &nbsp;//从文本文件中取文件名<br> &nbsp; &nbsp; &nbsp; &nbsp;filename:=copy(str,1,pos('-',str)-2) ;<br> &nbsp; &nbsp; &nbsp; &nbsp;//默认找到标志为假<br> &nbsp; &nbsp; &nbsp; &nbsp;findbz:=false;<br> &nbsp; &nbsp; &nbsp; &nbsp;if filelistbox1.Items=filename then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;findbz:=true; &nbsp; //如果相等,则找到成功并终止本轮循环,进入下一轮<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;application.ProcessMessages ;<br> &nbsp; &nbsp; &nbsp;//如果没有找到,则追加到LISTBOX1<br> &nbsp; &nbsp; &nbsp;if not findbz then listbox1.Items.Add(filelistbox1.Items) ;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;filenamelist.Free ;<br> &nbsp; &nbsp;showmessage('SYSTEM32目录下共有'+inttostr(filelistbox1.Items.Count)+'个文件'+#13#10+'现在共有'+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inttostr(listbox1.Count)+'个文件与标准文件不符');<br> &nbsp;end;<br>end;<br><br>end.
 
没看出错误来,呵呵
 
不知道你那个system32.text的文件名什么样?你也没有说清楚是什么错<br>不过你上面写的也太麻烦了点。<br> &nbsp; for j:=0 to filenamelist.count-1 do<br> &nbsp; &nbsp; filenamelist:=copy(filenamelist,1,pos('-',filenamelist)-2) ;<br> &nbsp; for j:=0 to filelistbox1.Count -1 do <br> &nbsp; &nbsp; &nbsp; if filenamelist.items.indexof(filelistbox1.items)&lt;0 then <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;listbox1.Items.Add(filelistbox1.Items) ;<br> &nbsp;不如结果不对就可能是文件名提取错误了~~
 
后退
顶部