unit UntMemoFind;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
FindDialog1: TFindDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Finddialog1.Execute;
end;procedure TForm1.FindDialog1Find(Sender: TObject);
var
I,J,PosReturn,SkipChars:Integer;//定义四个整型变量
begin
for I:=0 to Memo1.Lines.Count do //I用来在MEMO文本中循环查找
begin
PosReturn:=Pos(FindDialog1.FindText,Memo1.Lines[I]); //查找的文本
if PosReturn <>0 then //found!
begin
Skipchars:=0; // initialization Skipchars
for J:=0 to I-1 do //从这儿以下都不清楚
Skipchars:=Skipchars+Length(Memo1.Lines[J]);
SkipChars:=SkipChars+(I*2); //发现不要这行也可执行
SkipChars:=SkipChars+PosReturn-1; //从这儿以上都不清楚
Memo1.SetFocus;//设置光标
Memo1.SelStart:=SkipChars; //选择起始位置
Memo1.SelLength:=Length(FindDialog1.FindText);//选择长度
Break; //干什么用的?
end;
end;
end;
end.
//运行之后发现只能找到文本中第一次出现的要查找的内容,再不能往下找了
解决方案 »
- access数据库问题
- 200分只给一个人,是Delphi流操作比较慢吗?为何通过流然后绘制到Image上闪动比较厉害。求老大帮忙!!!!!!!!!
- 如何做出和Excel中插入批注类似的效果?(888分求!)
- 【求助】关于查询表名问题?
- 一个比较急的问题,小弟在线等待!!!!!
- 请教:导入导出excel表特别慢的问题,以及自动寻找数据库?
- 让人头疼的问题!分不够在加!!
- 在线播放的rm和wmv如何实现,用一个编辑框接受地址输入就可以了吗,属性如何设置呢?
- 卡住了,請幫手!
- 紧急:将Delphi数据输出到Excel表格出错,什么原因?本来给80分,但是系统不同意
- ComboBox控件默认显示数据
- 请问要如何调用这样的函数?
var
I,J,PosReturn,SkipChars:Integer;//定义四个整型变量
begin
for I:=0 to Memo1.Lines.Count do //I用来在MEMO文本中循环查找
begin
PosReturn:=Pos(FindDialog1.FindText,Memo1.Lines[I]); //查找的文本
if PosReturn <>0 then //found!
begin
Skipchars:=0; // initialization Skipchars
for J:=0 to I-1 do //从这儿以下都不清楚
Skipchars:=Skipchars+Length(Memo1.Lines[J]);
SkipChars:=SkipChars+(I*2); //发现不要这行也可执行
SkipChars:=SkipChars+PosReturn-1; //从这儿以上都不清楚
Memo1.SetFocus;//设置光标
Memo1.SelStart:=SkipChars; //选择起始位置
Memo1.SelLength:=Length(FindDialog1.FindText);//选择长度
Break; //干什么用的? 找到内容就退出了,不继续查找,要是去掉可以继续查找
end;
end;
end;
The Break procedure causes the flow of control in Delphi code to exit a for, while, or repeat statement and continue at the next statement following the loop statement.A call to Break must be contained in a for, while, or repeat statement, or the compiler reports an error.
Skipchars:=Skipchars+Length(Memo1.Lines[J]);
SkipChars:=SkipChars+(I*2); //发现不要这行也可执行
SkipChars:=SkipChars+PosReturn-1; //从这儿以上都不清楚
break的定义break过程在delphi代码中起控制作用,如:退出一个for、while或者某些重复语句段,而continue在这些重复语句段中是执行下一个循环。break的使用必须包含在一个for、while或者某些重复语句段,否则编译器报错。以上翻译的对吗??这个常识应该知道,谢谢这位大侠~!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
FindDialog1: TFindDialog;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
f: integer;
I,J,PosReturn,SkipChars:Integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
f:=0;
Finddialog1.Execute;
end;procedure TForm1.FindDialog1Find(Sender: TObject);begin
for I:=0 to Memo1.Lines.Count -1 do
begin
PosReturn:=Pos(FindDialog1.FindText,Memo1.Lines[I]);
if PosReturn <> 0 then
begin
Skipchars:=0;
for J:=0 to I-1 do
Skipchars:=Skipchars+Length(Memo1.Lines[J]);
if skipchars >= f then
begin
SkipChars:=SkipChars+(I*2);
SkipChars:=SkipChars+PosReturn-1;
Memo1.SetFocus;
Memo1.SelStart:=SkipChars;
Memo1.SelLength:=Length(FindDialog1.FindText);
f:= skipchars;
Break;
end;
end;
end;
end;end.
你的是按行来找的,在一行里,有相同的话,只select上第一个,比如找s,在第三行有..ss..这样的话,只select上第一个s