You've already forked lazarus-ccr
richmemo: search sample
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3776 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
89
components/richmemo/samples/search/mainform.lfm
Normal file
89
components/richmemo/samples/search/mainform.lfm
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
object Form1: TForm1
|
||||||
|
Left = 362
|
||||||
|
Height = 338
|
||||||
|
Top = 203
|
||||||
|
Width = 615
|
||||||
|
Caption = 'Ready to Search!'
|
||||||
|
ClientHeight = 338
|
||||||
|
ClientWidth = 615
|
||||||
|
LCLVersion = '1.2.4.0'
|
||||||
|
object Button1: TButton
|
||||||
|
Left = 532
|
||||||
|
Height = 25
|
||||||
|
Top = 16
|
||||||
|
Width = 75
|
||||||
|
Anchors = [akTop, akRight]
|
||||||
|
Caption = 'Load RTF'
|
||||||
|
OnClick = Button1Click
|
||||||
|
TabOrder = 3
|
||||||
|
end
|
||||||
|
object Button2: TButton
|
||||||
|
Left = 440
|
||||||
|
Height = 25
|
||||||
|
Top = 16
|
||||||
|
Width = 75
|
||||||
|
Anchors = [akTop, akRight]
|
||||||
|
Caption = 'Search'
|
||||||
|
OnClick = Button2Click
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
object Edit1: TEdit
|
||||||
|
Left = 8
|
||||||
|
Height = 23
|
||||||
|
Top = 18
|
||||||
|
Width = 424
|
||||||
|
Anchors = [akTop, akLeft, akRight]
|
||||||
|
TabOrder = 0
|
||||||
|
Text = 'search'
|
||||||
|
end
|
||||||
|
object RichMemo1: TRichMemo
|
||||||
|
Left = 8
|
||||||
|
Height = 240
|
||||||
|
Top = 88
|
||||||
|
Width = 599
|
||||||
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
|
HideSelection = False
|
||||||
|
Lines.Strings = (
|
||||||
|
'Please type in a word in the search field and hit "Search" to perform Search'
|
||||||
|
)
|
||||||
|
ScrollBars = ssAutoBoth
|
||||||
|
TabOrder = 2
|
||||||
|
end
|
||||||
|
object chkCaseSensitive: TCheckBox
|
||||||
|
Left = 9
|
||||||
|
Height = 19
|
||||||
|
Top = 48
|
||||||
|
Width = 94
|
||||||
|
Caption = 'Case Sensitive'
|
||||||
|
TabOrder = 4
|
||||||
|
end
|
||||||
|
object chkWholeWord: TCheckBox
|
||||||
|
Left = 108
|
||||||
|
Height = 19
|
||||||
|
Top = 48
|
||||||
|
Width = 86
|
||||||
|
Caption = 'Whole Word'
|
||||||
|
TabOrder = 5
|
||||||
|
end
|
||||||
|
object chkBackward: TCheckBox
|
||||||
|
Left = 200
|
||||||
|
Height = 19
|
||||||
|
Top = 48
|
||||||
|
Width = 71
|
||||||
|
Caption = 'Backward'
|
||||||
|
TabOrder = 6
|
||||||
|
end
|
||||||
|
object Button3: TButton
|
||||||
|
Left = 440
|
||||||
|
Height = 25
|
||||||
|
Top = 45
|
||||||
|
Width = 75
|
||||||
|
Caption = 'Reset'
|
||||||
|
OnClick = Button3Click
|
||||||
|
TabOrder = 7
|
||||||
|
end
|
||||||
|
object OpenDialog1: TOpenDialog
|
||||||
|
left = 368
|
||||||
|
top = 48
|
||||||
|
end
|
||||||
|
end
|
93
components/richmemo/samples/search/mainform.pas
Normal file
93
components/richmemo/samples/search/mainform.pas
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
unit mainform;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Windows, RichEdit,
|
||||||
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||||
|
RichMemo, RichMemoUtils, LazUTF8;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TForm1 }
|
||||||
|
|
||||||
|
TForm1 = class(TForm)
|
||||||
|
Button1: TButton;
|
||||||
|
Button2: TButton;
|
||||||
|
Button3: TButton;
|
||||||
|
chkCaseSensitive: TCheckBox;
|
||||||
|
chkWholeWord: TCheckBox;
|
||||||
|
chkBackward: TCheckBox;
|
||||||
|
Edit1: TEdit;
|
||||||
|
OpenDialog1: TOpenDialog;
|
||||||
|
RichMemo1: TRichMemo;
|
||||||
|
procedure Button1Click(Sender: TObject);
|
||||||
|
procedure Button2Click(Sender: TObject);
|
||||||
|
procedure Button3Click(Sender: TObject);
|
||||||
|
private
|
||||||
|
{ private declarations }
|
||||||
|
public
|
||||||
|
{ public declarations }
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Form1: TForm1;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$R *.lfm}
|
||||||
|
|
||||||
|
{ TForm1 }
|
||||||
|
|
||||||
|
procedure TForm1.Button1Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if OpenDialog1.Execute then
|
||||||
|
LoadRTFFile( RichMemo1, OpenDialog1.FileName );
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button2Click(Sender: TObject);
|
||||||
|
var
|
||||||
|
s : Integer;
|
||||||
|
fw: TFINDTEXT;
|
||||||
|
w: AnsiString;
|
||||||
|
l : Integer;
|
||||||
|
st: Integer;
|
||||||
|
opt: TSearchOptions;
|
||||||
|
begin
|
||||||
|
st:=RichMemo1.SelStart;
|
||||||
|
l:=RichMemo1.SelLength;
|
||||||
|
|
||||||
|
opt:=[];
|
||||||
|
if chkCaseSensitive.Checked then include(opt, soMatchCase);
|
||||||
|
if chkWholeWord.Checked then include(opt, soWholeWord);
|
||||||
|
if chkBackward.Checked then include(opt, soBackward);
|
||||||
|
|
||||||
|
Caption:='Searching...';
|
||||||
|
s:=RichMemo1.Search(Edit1.Text, RichMemo1.SelStart, length(RichMemo1.Text), opt);
|
||||||
|
if (s>=0) then begin
|
||||||
|
if (st=s) and (l=UTF8Length(Edit1.Text)) then
|
||||||
|
s:=RichMemo1.Search(Edit1.Text, RichMemo1.SelStart+1, length(RichMemo1.Text), opt);
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (s>=0) then begin
|
||||||
|
Caption:='Found!';
|
||||||
|
RichMemo1.SelStart:=s;
|
||||||
|
RichMemo1.SetSelLengthFor(Edit1.text);
|
||||||
|
end else begin
|
||||||
|
Caption:='Not found!';
|
||||||
|
RichMemo1.SelStart:=MaxInt;
|
||||||
|
RichMemo1.SelLength:=0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Button3Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
RichMemo1.SelStart:=0;
|
||||||
|
RichMemo1.SelLength:=0;
|
||||||
|
Caption:='Ready to Search!';
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
85
components/richmemo/samples/search/testsearch.lpi
Normal file
85
components/richmemo/samples/search/testsearch.lpi
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="testsearch"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
<UseXPManifest Value="True"/>
|
||||||
|
<Icon Value="0"/>
|
||||||
|
</General>
|
||||||
|
<i18n>
|
||||||
|
<EnableI18N LFM="False"/>
|
||||||
|
</i18n>
|
||||||
|
<VersionInfo>
|
||||||
|
<StringTable ProductVersion=""/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="2">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="richmemopackage"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item2>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="2">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="testsearch.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="testsearch"/>
|
||||||
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="mainform.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<ComponentName Value="Form1"/>
|
||||||
|
<HasResources Value="True"/>
|
||||||
|
<ResourceBaseClass Value="Form"/>
|
||||||
|
<UnitName Value="mainform"/>
|
||||||
|
</Unit1>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="testsearch"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<MsgFileName Value=""/>
|
||||||
|
</CompilerMessages>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
20
components/richmemo/samples/search/testsearch.lpr
Normal file
20
components/richmemo/samples/search/testsearch.lpr
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
program testsearch;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||||
|
cthreads,
|
||||||
|
{$ENDIF}{$ENDIF}
|
||||||
|
Interfaces, // this includes the LCL widgetset
|
||||||
|
Forms, mainform, richmemopackage;
|
||||||
|
|
||||||
|
{$R *.res}
|
||||||
|
|
||||||
|
begin
|
||||||
|
RequireDerivedFormResource := True;
|
||||||
|
Application.Initialize;
|
||||||
|
Application.CreateForm(TForm1, Form1);
|
||||||
|
Application.Run;
|
||||||
|
end.
|
||||||
|
|
Reference in New Issue
Block a user