初学者问题,如何查找(20分)

L

Lee

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟是初学,用的是3.0版。请问FindDialog打开后如何查找,两个例子怎
么均没用到FindOption。还有,Invert Selection是如何实现的?多谢。
 
FindDialog实质上只是一个框架而已,他根本没有任何查找功能
查找功能要靠应用程序来实现,它只是提供了给用户输入查找的
一个介面,具体的使用请看例子,例子里面有个FindText函数,是
查找的真正部分!FindOption你把各种组合试一虾,不就明白了:)
 
我忘了你用的是delphi3,例子里面可能没有我
贴过来了,建议你用<font color=red>Delphi4</font>
例子全,功能又不错!
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: integer;
begin
with RichEdit1 do
begin
{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }

if SelLength <> 0 then
StartPos := SelStart + SelLength;
else

StartPos := 0;

{ ToEnd is the length from StartPos to the end of the text in the rich edit control }

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;
 
补充一下吧:

1. FindDialog有一个OnFind的Event,
是当 查找确定按下时调用的,你需要写这个函数

2. Invert Selection
在edit,memo,richedit,都是通过 Selstart,sellength来确定的。

3。Option是用来custom dialog的,
“绝知此事要躬行”
 
多谢两位,小弟很吝啬是因为初学,分得留着点。
 
顶部