Fórum Pesquisa em memo? #171600
26/07/2003
0
e ai pessoal,
alguem poderia me ajudar, preciso fazer uma pesquisa no memo, como faco isso?
falo
ivan
alguem poderia me ajudar, preciso fazer uma pesquisa no memo, como faco isso?
falo
ivan
Ivan Andre
Curtir tópico
+ 0
Responder
Posts
26/07/2003
Cdaraujo
Olha amigo,
Veja um exemplo que implementei para vc.
Atensiosamente,
Daniel Araújo
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, [b:ac321f200f]RichEdit[/b:ac321f200f];
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FindDialog1 :TFindDialog;
function FindText(const SearchStr: string;
StartPos, Length: Integer; Options: TSearchTypes): Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.FindText(const SearchStr: string;
StartPos, Length: Integer; Options: TSearchTypes): Integer;
var
Find: TFindText;
Flags: Integer;
begin
with Find.chrg do
begin
cpMin := StartPos;
cpMax := cpMin + Length;
end;
Flags := 0;
if stWholeWord in Options then Flags := Flags or FT_WHOLEWORD;
if stMatchCase in Options then Flags := Flags or FT_MATCHCASE;
Find.lpstrText := PChar(SearchStr);
Result := SendMessage(Memo1.Handle, EM_FINDTEXT, Flags, LongInt(@Find));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindDialog1.Position := Point(Memo1.Left + Memo1.Width, Memo1.Top);
FindDialog1.Execute;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
begin
with Memo1 do
begin
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
[b:ac321f200f] FindDialog1 := TFindDialog.Create(Self); [/b:ac321f200f]end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
[b:ac321f200f]FindDialog1.Free;[/b:ac321f200f]end;
end.
Veja um exemplo que implementei para vc.
Atensiosamente,
Daniel Araújo
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, [b:ac321f200f]RichEdit[/b:ac321f200f];
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FindDialog1 :TFindDialog;
function FindText(const SearchStr: string;
StartPos, Length: Integer; Options: TSearchTypes): Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.FindText(const SearchStr: string;
StartPos, Length: Integer; Options: TSearchTypes): Integer;
var
Find: TFindText;
Flags: Integer;
begin
with Find.chrg do
begin
cpMin := StartPos;
cpMax := cpMin + Length;
end;
Flags := 0;
if stWholeWord in Options then Flags := Flags or FT_WHOLEWORD;
if stMatchCase in Options then Flags := Flags or FT_MATCHCASE;
Find.lpstrText := PChar(SearchStr);
Result := SendMessage(Memo1.Handle, EM_FINDTEXT, Flags, LongInt(@Find));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindDialog1.Position := Point(Memo1.Left + Memo1.Width, Memo1.Top);
FindDialog1.Execute;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
begin
with Memo1 do
begin
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
[b:ac321f200f] FindDialog1 := TFindDialog.Create(Self); [/b:ac321f200f]end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
[b:ac321f200f]FindDialog1.Free;[/b:ac321f200f]end;
end.
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)