文本搜索程序的问题~~50分~(50分)

  • 主题发起人 主题发起人 flyso
  • 开始时间 开始时间
F

flyso

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl;

type
TMainForm = class(TForm)
Label1: TLabel;
DcbDrives: TDriveComboBox;
edtSearchString: TEdit;
dlbDirectories: TDirectoryListBox;
FindDialog: TFindDialog;
Label2: TLabel;
btnSearch: TButton;
btnFindNext: TButton;
lbFilesFound: TListBox;
Memo: TMemo;
procedure btnSearchClick(Sender: TObject);
procedure btnFindNextClick(Sender: TObject);
procedure lbFilesFoundClick(Sender: TObject);
procedure FindDialogFind(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.btnSearchClick(Sender: TObject);
var
MemMapFile:TMemMapFile;
SearchRec:TSearchRec;
RetVal:Integer;
FoundStr:PChar;
FName:String;
FindString:String;
WordCount:Integer;
begin
memFileText.Lines.Clear;
btnFindNext.Enabled:=False;
lbFilesFound.Items.Clear;
//返回已搜索到的文本文件
RetVal:=FindFirst(dlbDirectories.Directory+'/*.txt',faAnyFile,SearchRec);
try
WHILE RetVal=0 do
begin
FName:=SearchRec.Name;
//打开只读内存映射文件
MemMapFile:=TMemMapFile.Create(FName,fmOpenRead,0,True);
try
//为搜索字符串提供临时的存储空间
FindString:=edtSearchString.Text;
WordCount:=0;//将WordCount初始化为0
//得到第一次搜索到的字符串
FoundStr:=StrPos(PChar(MemMapFile.Data),PChar(FindString));
if FoundStr<>nil then
begin
//继续搜索,每找到一个要搜索的字符串,使WordCount加1.
repeat
inc(WordCount);
inc(FoundStr,Length(FoundStr));
//获取下一个要查找的字符串
FoundStr:=StrPos(PChar(FoundStr),PChar(FindString));
until FoundStr=nil;
//将文件名加入列表框中
lbFilesFound.Items.Add(SearchRec.Name+'-'+IntToStr(WordCount));
end;
//获取下一个已搜索到的文件
RetVal:=FindNext(SearchRec);
Finally
MemMapFile.Free;//释放内存映射文件实例
end;
end;
finally
FindClose(SearchRec);
end;
end;

procedure TMainForm.lbFilesFoundClick(Sender: TObject);
var
FName:String;
B:Byte;
begin
With lbFilesFound do
if ItemIndex <> -1 then
begin
B:=Pos('',Item[ItemIndex]);
FName:=Copy(Items[ItemIndex],1,B);
memFileText.Clear;
memFileText.Lines.LoadFromFile(FName);
end;
end;

procedure TMainForm.btnFindNextClick(Sender: TObject);
begin
FindDialog.FindText:=edtSearchString.Text;
FindDialog.Execute;
FindDialog.Top:=Top+Height;
FindDialogFind(FindDialog);
end;

procedure TMainForm.FindDialogFind(Sender: TObject);
begin
with Sender as TFindDialog do
if not SearchMemo(memFileText,FindText,Options) then
ShowMessage('找不到"'+FindText+'".');
end;



end.

................................................
错误提示:
[Warning] Unit1.pas(7): Unit 'FileCtrl' is specific to a platform
[Error] Unit1.pas(40): Undeclared identifier: 'TMemMapFile'
[Error] Unit1.pas(48): Undeclared identifier: 'memFileText'
[Error] Unit1.pas(48): Missing operator or semicolon
[Error] Unit1.pas(58): Missing operator or semicolon
[Error] Unit1.pas(58): Incompatible types: 'TComponent' and 'String'
[Error] Unit1.pas(58): Too many actual parameters
[Error] Unit1.pas(64): ')' expected but identifier 'Data' found
[Error] Unit1.pas(65): Missing operator or semicolon
[Error] Unit1.pas(79): 'END' expected but 'FINALLY' found
[Error] Unit1.pas(81): EXCEPT or FINALLY expected
[Error] Unit1.pas(83): Declaration expected but 'FINALLY' found
[Error] Unit1.pas(85): '.' expected but ';' found
[Warning] Unit1.pas(86): Text after final 'END.' - ignored by compiler
[Error] Unit1.pas(22): Unsatisfied forward or external declaration: 'TMainForm.btnFindNextClick'
[Error] Unit1.pas(23): Unsatisfied forward or external declaration: 'TMainForm.lbFilesFoundClick'
[Error] Unit1.pas(24): Unsatisfied forward or external declaration: 'TMainForm.FindDialogFind'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

请大侠帮忙看看怎么修正~
 
给我把程序全部发过来,abcun@263.net
 
已发
我的邮箱flyso@163.com
 
多人接受答案了。
 

Similar threads

后退
顶部