📄 customsearchfrm.pas
字号:
SQL.Add('delete from temp');
ExecSQL;
end;
end;
procedure TfrmCustomSearch.FormCreate(Sender: TObject);
var
i:Integer;
begin
with fraInput do
begin
//选择“选择ID”
rbNew.Checked:=True;
rbSelectClick(nil);
//插入超时列表
cbbTimeLimit.Items.Clear;
for i:=TimeLimitMin to TimeLimitMax do
cbbTimeLimit.Items.Add(inttostr(i));
//设定默认的超时限制
cbbTimeLimit.ItemIndex:=2;
//定义排序字符串,用作查询时放入sql语句
SortString[0]:='head';
SortString[1]:='Datetime';
SortString[2]:='Type';
SortString[3]:='Source';
end;
//设定刷新速度
tmRefresh.Interval:=StrToInt(frmSetting.cbbRefresh.Text)*1000;
//禁用刷新
tmRefresh.Enabled:=False;
end;
//显示搜索结果
procedure TfrmCustomSearch.DisplayResult(ID: string);
var
SQLString:string;
begin
//在数据库中查询搜索信息
SQLString:='select * from temp where ID='+quotedstr(ID);
SQLString:=SQLString+' order by '+SortString[cbSort.itemIndex];
if rbDescend.Checked then
SQLString:=SQLString+' Desc';
// frmMain.MyExecSQL(frmMain.qryDisplay1,SQLString);
frmMain.MyExecSQL(frmMain.AdoqDisplay,SQLString);
//显示结果
frmDisplay.Display;
end;
procedure TfrmCustomSearch.cbSortChange(Sender: TObject);
begin
DisplayResult(ID);
pnlBar.SetFocus;
end;
//启用输入
procedure TfrmCustomSearch.EnableCustom;
begin
with fraInput do
begin
pnlInputID.Enabled:=True;
pnlCustomInput.Enabled:=True;
end;
end;
//禁用输入
procedure TfrmCustomSearch.DisableCustom;
begin
with fraInput do
begin
pnlInputID.Enabled:=False;
pnlCustomInput.Enabled:=False;
end;
end;
procedure TfrmCustomSearch.sbSearchClick(Sender: TObject);
var
num:integer;
begin
with fraInput do
begin
//选择ID
if rbSelect.Checked then
begin
ID:=tvIDList.Selected.Text;
//with frmMain.qryCustom do
with frmMain.AdoqCustom do
begin
// frmMain.MyExecSQL(frmMain.qryCustom,'select * from Custom where ID='+QuotedStr(ID));
frmMain.MyExecSQL(frmMain.AdoqCustom,'select * from Custom where ID='+QuotedStr(ID));
Edit;
FieldByName('Systime').AsDateTime:=Now;
Post;
end;
end
//选择全新输入
else
ID:='';
//检查输入
if (edtKeyWord1.Text='') and (edtKeyWord2.Text='') and (edtKeyWord3.Text='') then
begin
ShowMessage('请输入关键字!');
edtKeyWord1.SetFocus;
Exit;
end;
GetKeyword;
frmMain.GetList(clbWebType,num);
if num=0 then
begin
showmessage('请选择网站类型');
exit;
end;
frmMain.GetList(clbEngine,num);
if num=0 then
begin
showmessage('请选择搜索引擎');
exit;
end;
//对数据库进行编辑
//删除曾经搜索过的无ID的内容
// with frmMain.qrySearch do
with frmMain.AdoqSearch do
begin
SQL.Clear;
SQL.Add('delete from temp where ID=''''');
ExecSQL;
end;
//清空显示
frmDisplay.Clear;
//复位显示
frmDisplay.Rewind;
//禁止编辑
DisableCustom;
//设定值
//刷新几时启动
tmRefresh.Enabled:=True;
//复位完成标志
Finished:=False;
//复位搜索引擎数量
EngineSelected:=0;
//复位状态栏
stbStatusBar.Panels[0].Text:='搜索中...';
stbStatusBar.Panels[1].Text:='已完成的搜索引擎:';
//记录超时
Timelimit:=StrToInt(fraInput.cbbTimeLimit.Text);
ResultCount:=0;
//开始搜索计时,计算搜索所用时间
tmTimeCost.Tag:=0;
tmTimeCost.Enabled:=True;
//隐藏搜索键
sbSearch.Hide;
//显示停止键
sbStop.Show;
//显示暂停键
sbPause.Show;
//隐藏继续键
sbResume.Hide;
//启用暂停键
sbPause.Enabled:=True;
//启用继续键
sbResume.Enabled:=True;
//创建搜索线程
if clbEngine.Checked[0] then
begin
BaiduSearch:=TBaiduSearch.Create;
Inc(EngineSelected);
BaiduStarted:=true;
end;
{if clbEngine.Checked[1] then
begin
GoogleSearch:=TGoogleSearch.Create;
Inc(EngineSelected);
GoogleStarted:=true;
end;}
if clbEngine.Checked[1] then
begin
_21cnSearch:=T_21cnSearch.Create;
Inc(EngineSelected);
_21cnStarted:=true;
end;
if clbEngine.Checked[2] then
begin
SinaSearch:=TSinaSearch.Create;
Inc(EngineSelected);
SinaStarted:=true;
end;
if clbEngine.Checked[3] then
begin
SohuSearch:=TSohuSearch.Create;
Inc(EngineSelected);
SohuStarted:=true;
end;
if clbEngine.Checked[4] then
begin
YahooSearch:=TYahooSearch.Create;
Inc(EngineSelected);
YahooStarted:=true;
end;
end;
end;
procedure TfrmCustomSearch.leIDEnter(Sender: TObject);
begin
fraInput.sbSaveID.Enabled:=true;
end;
procedure TfrmCustomSearch.rbAscendClick(Sender: TObject);
begin
DisplayResult(ID);
end;
procedure TfrmCustomSearch.rbDescendClick(Sender: TObject);
begin
DisplayResult(ID);
end;
procedure TfrmCustomSearch.fraInput1tvIDListExit(Sender: TObject);
begin
fraInput.sbMaintain.Enabled:=False;
end;
procedure TfrmCustomSearch.tmRefreshTimer(Sender: TObject);
begin
with frmMain do
begin
MyExecSQL(AdoqSearch,'select * from temp where ID='+QuotedStr(ID));
//增加了新的记录
if AdoqSearch.RecordCount>ResultCount then
begin
ResultCount:=AdoqSearch.RecordCount;
//未完则显示
if not(Finished) then
DisplayResult(ID);
end;
end;
end;
procedure TfrmCustomSearch.sbStopClick(Sender: TObject);
begin
//停止所有打开的搜索线程
if BaiduStarted then
begin
BaiduSearch.Suspend;
BaiduSearch.Terminate;
end;
if GoogleStarted then
begin
GoogleSearch.Suspend;
GoogleSearch.Terminate;
end;
if _21cnStarted then
begin
_21cnSearch.Suspend;
_21cnSearch.Terminate;
end;
if SinaStarted then
begin
SinaSearch.Suspend;
SinaSearch.Terminate;
end;
if SohuStarted then
begin
SohuSearch.Suspend;
SohuSearch.Terminate;
end;
if YahooStarted then
begin
YahooSearch.Suspend;
YahooSearch.Terminate;
end;
//标志完成
Finished:=True;
//状态栏提示
stbStatusBar.Panels[0].Text:='完成';
//停止刷新
tmRefresh.Enabled:=False;
//停止计时
tmTimeCost.Enabled:=False;
//启用编辑
EnableCustom;
//显示搜索键
sbSearch.Show;
//隐藏停止键
sbStop.Hide;
//禁用暂停键
sbPause.Enabled:=False;
//禁用继续键
sbResume.Enabled:=False;
end;
procedure TfrmCustomSearch.sbPauseClick(Sender: TObject);
begin
//暂停所有打开的搜索线程
if BaiduStarted then
BaiduSearch.Suspend;
if GoogleStarted then
GoogleSearch.Suspend;
if _21cnStarted then
_21cnSearch.Suspend;
if SinaStarted then
SinaSearch.Suspend;
if SohuStarted then
SohuSearch.Suspend;
if YahooStarted then
YahooSearch.Suspend;
//显示继续键
sbResume.Show;
//隐藏暂停键
sbPause.Hide;
//暂停刷新
tmRefresh.Enabled:=False;
//暂停计时
tmTimeCost.Enabled:=False;
end;
procedure TfrmCustomSearch.sbResumeClick(Sender: TObject);
begin
//继续所有打开的搜索线程
if BaiduStarted then
BaiduSearch.Resume;
if GoogleStarted then
GoogleSearch.Resume;
if _21cnStarted then
_21cnSearch.Resume;
if SinaStarted then
SinaSearch.Resume;
if SohuStarted then
SohuSearch.Resume;
if YahooStarted then
YahooSearch.Resume;
//隐藏继续键
sbResume.Hide;
//显示暂停键
sbPause.Show;
//刷新
tmRefresh.Enabled:=True;
//继续计时
tmTimeCost.Enabled:=True;
end;
//保存入库
procedure TfrmCustomSearch.sbSaveToInfoClick(Sender: TObject);
var
Msg:string;
begin
//ID为空则先保存定制
if ID='' then
begin
//提示保存
Msg:='保存搜索信息之前要先保存定制'+#13+'要保存定制吗?';
if MessageDlg(Msg,mtWarning,[mbYes,mbNo],0)=mrNo then
Exit;
//检查输入
if not(CheckInput) then
Exit;
//保存定制
if not(SaveCustom) then
Exit;
//把所有搜索到的记录的ID改为用户保存过的ID
//with frmMain.qrySearch do
with frmMain.AdoqSearch do
begin
//frmMain.MyExecSQL(frmMain.qrySearch,'select * from temp where ID=''''');
frmMain.MyExecSQL(frmMain.AdoqSearch,'select * from temp where ID=''''');
while not(Eof) do
begin
Edit;
FieldByName('ID').AsString:=ID;
Post;
Next;
end;
end;
end;
//把临时数据库中的数据转到Info数据库
frmMain.TransferTable('temp','Info',ID);
//点击选择ID
fraInput.rbSelect.Checked:=True;
end;
procedure TfrmCustomSearch.fraInputleKeywordKeyPress(Sender: TObject;
var Key: Char);
begin
//按下回车则执行搜索
if Key=#13 then
sbSearchClick(nil);
end;
procedure TfrmCustomSearch.tmTimeCostTimer(Sender: TObject);
begin
//记录搜索所用的时间
with stbStatusBar.Panels[2] do
begin
tmTimeCost.Tag:=tmTimeCost.Tag+1;
Text:='用时:';
if tmTimeCost.Tag>=3600 then
Text:=Text+IntToStr(tmTimeCost.Tag div 3600)+'时';
if tmTimeCost.Tag>=60 then
Text:=Text+IntToStr((tmTimeCost.Tag mod 3600) div 60)+'分';
Text:=Text+IntToStr(tmTimeCost.Tag mod 60)+'秒';
end;
end;
procedure TfrmCustomSearch.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//禁用刷新
tmRefresh.Enabled:=False;
//记录页数
Page:=DisplayFrm.Page;
end;
procedure TfrmCustomSearch.fraInputedtKeyword1KeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
sbSearchClick(nil);
end;
procedure TfrmCustomSearch.fraInputedtKeyword2KeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
sbSearchClick(nil);
end;
procedure TfrmCustomSearch.fraInputedtKeyword3KeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
sbSearchClick(nil);
end;
procedure TfrmCustomSearch.sbOpenBrowserClick(Sender: TObject);
begin
frmBrowser.Show;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -