delphi帮我看下这是什么意思

来源:百度知道 编辑:UC知道 时间:2024/07/02 05:09:54
如题,帮我解答下foundpos的用法,还有下面的算法都能给个祥细的注释。不多说了,代码如下:

procedure TForm1.FindDialog1Find(Sender: TObject);
var
foundpos,initpos:integer;
begin
initpos:=richedit1.SelStart+richedit1.SelLength;
foundpos:=pos(finddialog1.FindText,copy(richedit1.Text,initpos+1,length(richedit1.Text)-initpos));
if foundpos>0 then
begin
richedit1.SetFocus;
richedit1.SelStart:=initpos+foundpos-1;
richedit1.SelLength:=length(finddialog1.FindText);
end
else
messagedlg('没有找到要查找的文本',mtinformation,[mbok],0);
end;
foundpos:=pos(finddialog1.FindText,copy(richedit1.Text,initpos+1,length(richedit1.Text)-initpos));

特别是这名,如果能帮我解答出来,会再加分的。谢谢了。

procedure TForm1.FindDialog1Find(Sender: TObject);
var
foundpos{找到的字符串的起始位置},initpos{从文章的这个位置开始查找}:integer;
begin
initpos:=richedit1.SelStart{选择内容开始的位置}+richedit1.SelLength{选择内容的长度}; //计算选择内容结束的位置(开始查找的位置)
foundpos:=pos(finddialog1.FindText{欲查找的字符串},copy(richedit1.Text{文章的所有字符串},initpos+1{选择位置之后的一个位置},length(richedit1.Text){整个文章的长度}-initpos{开始查找的位置})); //查找欲查找字符串的开始位置
if foundpos>0 then //如果查找到的位置大于0(找到要找的字符串了)则执行一下代码
begin
richedit1.SetFocus; //设置焦点到richedit1上
richedit1.SelStart:=initpos+foundpos-1; //设置选择开始位置为开始查找位置和找到位置的和(欲查找字符串起始字符在整个文章中的位置)
richedit1.SelLength:=length(finddialog1.FindText); //在文章中选择整个欲查找的字符串
end
else //否则(即没有找到欲查找的字符串)执行以下语句
messagedlg('没有找到要查找的文本',mtinformation,[mbok],0); //弹出对话框
end;