Difference between revisions of "TFindDialog/zh CN"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{TFindDialog}} '''TFindDialog''' Image:tfinddialog.png 是搜索的弹出对话框. 在 Dialogs tabComponent Palette. 对话框本身不会搜索; 仅仅...")
 
 
Line 24: Line 24:
 
       Memo1.SelStart := k - 1;
 
       Memo1.SelStart := k - 1;
 
       Memo1.SelLength := Length(FindText);
 
       Memo1.SelLength := Length(FindText);
 +
      Memo1.SetFocus; //必须激活控件,否则不显示选择效果
 
     end else
 
     end else
 
       Beep();
 
       Beep();
Line 63: Line 64:
 
       Memo1.SelStart := FFoundPos - 1;
 
       Memo1.SelStart := FFoundPos - 1;
 
       Memo1.SelLength := Length(FindText);
 
       Memo1.SelLength := Length(FindText);
 +
      Memo1.SetFocus; //必须激活控件,否则不显示选择效果
 
     end else
 
     end else
 
       Beep();
 
       Beep();

Latest revision as of 08:37, 1 May 2020

English (en) suomi (fi) français (fr) русский (ru) 中文(中国大陆)‎ (zh_CN)

TFindDialog tfinddialog.png 是搜索的弹出对话框. 在 Dialogs tabComponent Palette.

对话框本身不会搜索; 仅仅是为搜索参数提供一个界面而已. 激活搜索框, 使用方法:Execute() function. 创建 OnFind method 然后咋其中搜索.

component-TFindDialog.png

用法

如下示例显示了使用TFindDialog在(TMemo)中搜索特定内容的方法.

procedure TForm1.Button1Click(Sender: TObject);
begin
  FindDialog1.Execute();
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var
  k: integer;
begin
  with Sender as TFindDialog do begin
    k := Pos(FindText, Memo1.Lines.Text);
    if k > 0 then begin
      Memo1.SelStart := k - 1;
      Memo1.SelLength := Length(FindText);
      Memo1.SetFocus; //必须激活控件,否则不显示选择效果
    end else
      Beep();
  end;
end;

如果要继续搜索同样的内容,必须记住最后一次搜索的位置,从此处继续搜索。 unit 中的PosEx() 就是用来标记位置的:

uses
  StrUtils;

type
  TForm1 = class(TForm)
  private
    FFoundPos: Integer;
    ...

procedure TForm1.Button1Click(Sender: TObject);
begin
  with FindDialog1 do 
  begin
    if frEntireScope in Options then    // Search begins at file start
      FFoundPos := 0
    else
      FFoundPos := Memo1.SelStart;      // Serach begins at current cursor position
    Execute;
  end;
end; 

procedure TForm1.FindDialog1Find(Sender: TObject);
begin
  with Sender as TFindDialog do 
  begin
    FFoundPos := PosEx(FindText, Memo1.Lines.Text, FFoundPos+1);
    if FFoundPos > 0 then 
    begin
      Memo1.SelStart := FFoundPos - 1;
      Memo1.SelLength := Length(FindText);
      Memo1.SetFocus; //必须激活控件,否则不显示选择效果
    end else
      Beep();
  end;
end;

参考资料


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu