📄 searchhosts.pas
字号:
unit SearchHosts;
interface
uses Windows, Messages, SysUtils, Classes,ComCtrls,Dialogs;
type
TSearchHostsThread=class(TThread)
private
StartNum, HostIndex, ImageIndex: integer;
tnode: TTreeNode;
HostName, MyGroup: string;
TotalHostNum: integer;
FtpUsr, FtpPass: string;
protected
procedure Execute; override;
procedure GetTreeInfo;
//Procedure SetNode;
public
ParentNode: TTreeNode;
//ParentTree: TTreeView;
end;
THostsThread=class(TThread)
private
TotalHostNum: integer;
protected
procedure Execute; override;
Procedure EndSearch;
public
BeginNum: integer;
ParentNode: TTreeNode;
//ParentTree: TTreeView;
MyToolBtn: TToolButton;
end;
implementation
uses main,SearchHostThreadUnit, FtpBrowse, HttpGet, Config;
procedure TSearchHostsThread.GetTreeInfo;
begin
with MainForm do
begin
ImageIndex := ParentNode.Item[HostIndex].ImageIndex;
tnode := ParentNode.Item[HostIndex];
HostName := tnode.Text;
if (ImageIndex = 7)or(ImageIndex = 15) then
MyGroup := (PMyTreeItem(tnode.Data)).Group;
end;
end;
procedure TSearchHostsThread.Execute;
var
i : integer;
searchers : array[1..100]of TThread; //TSearchHostThread;
bDo : array[1..100]of boolean;
FtpSvrName : string;
HttpSvrName : string;
FtpRecursive : boolean;
begin
TotalHostNum := ParentNode.Count;
for i:=1 to 100 do bDo[i]:=false;
for i:=1 to ThreadNum do
begin
//if stop then exit;
if terminated then exit;
if StartNum+i<TotalHostNum then
begin
HostIndex:=StartNum+i;
synchronize(GetTreeInfo);
if (ImageIndex = 7)or(ImageIndex = 15) then
begin
//if terminated then exit;
if terminated then exit;
bDo[i]:=true;
searchers[i] := TSearchHostThread.create(true);
with searchers[i] as TSearchHostThread do
begin
MyTree := TTreeView(ParentNode.TreeView);
MyNode := tnode;
MyNode.ImageIndex := 12;
MyNode.SelectedIndex := 12;
MyHost := HostName;
MyGroup := Self.MyGroup; //'unknown';
FreeOnTerminate := true;
Resume;
end;
end
else if (ImageIndex = 114)or(ImageIndex = 117) then // FTP
begin
if terminated then exit;
bDo[i]:=true;
FtpSvrName := HostName;
delete(FtpSvrName, 1, 6);
tnode.ImageIndex := 116;
tnode.SelectedIndex := 116;
ConfigForm.GiveFtpUserPassWord(FtpSvrName, FtpUsr, FtpPass);
FtpRecursive := ConfigForm.cbFtpRecursive.Checked;
searchers[i] := TFtpBrowseThread.Create(TTreeView(ParentNode.TreeView),
tnode, nil, nil, FtpSvrName, FtpUsr, FtpPass, FtpRecursive);
searchers[i].Resume;
end
else if (ImageIndex = 123)or(ImageIndex = 121) then // Http
begin
HttpSvrName := HostName;
delete(HttpSvrName, 1, 7);
tnode.ImageIndex := 122;
tnode.SelectedIndex := 122;
searchers[i] := THttpGetThread.Create(TTreeView(ParentNode.TreeView),
tnode, HttpSvrName);
searchers[i].Resume;
end;
end else exit;
end; //end of for
//if threadMode=1 then
//begin
for i:=1 to ThreadNum do
if bDo[i] and (searchers[i]<>nil) then
begin
//if not searchers[i].Terminated then
begin
{if OS <> osWinxp then searchers[i].WaitFor else} WaitForSingleObjectEx(searchers[i].Handle,INFINITE,true);
{if ver>4 then
begin
searchers[i].Terminate;
searchers[i].free //win98下free会出错。
end
else //searchers[i].Terminate;
TerminateThread(searchers[i].handle,0);}
end;
end;
//Synchronize(AddGroup); ///
//end;
end;
procedure THostsThread.EndSearch;
begin
with MainForm do
begin
//ToolBtnStop.Enabled := false;
//ToolBtnPause.Enabled := false;
//ToolBtnAuto.Enabled := true;
//Timer1.Enabled := false;
ParentNode.ImageIndex := 131;
ParentNode.SelectedIndex := 131;
if assigned(MyToolBtn) then
begin
MyToolBtn.Enabled := true;
MyToolBtn.Tag := TotalHostNum;
end;
end;
end;
procedure THostsThread.Execute;
var
i : integer;
Multisearcherhost : TSearchHostsThread;
begin
TotalHostNum := ParentNode.Count;
i := BeginNum;
repeat
if stop then exit;
if terminated then exit;
Multisearcherhost:=TSearchHostsThread.create(true);
Multisearcherhost.StartNum := i;
Multisearcherhost.FreeOnTerminate := true;
Multisearcherhost.ParentNode := ParentNode;
Multisearcherhost.Resume;
//Multisearcherhost.WaitFor;
WaitForSingleObjectEx(Multisearcherhost.Handle,{INFINITE}10000,true);
i:=i+ThreadNum;
//SearchProgress:=i; //timer
until i>= TotalHostNum;
synchronize(EndSearch);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -