unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 =
class
(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
Button3: TButton;
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
procedure
Button3Click(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
Path:
string
;
bufpoiska:
string
;
positionbukv:
array
[
0..1000
]
of
integer
;
implementation
{$R *.dfm}
procedure
TForm1
.
Button1Click(Sender: TObject);
var
UserName :
string
;
UserNameLen : Dword;
begin
UserNameLen :=
255
;
SetLength(userName, UserNameLen);
if
GetUserName(
PChar
(UserName), UserNameLen)
then
UserName := Copy(UserName,
1
,UserNameLen -
1
);
OpenDialog1
.
InitialDir:=
'C:\Users\'+UserName+'
\Desktop\';
if
OpenDialog1
.
Execute
then
Path:=OpenDialog1
.
FileName;
RichEdit1
.
Lines
.
LoadFromFile(Path);
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
var
n,j,z:
Integer
;
begin
bufpoiska:=Edit1
.
Text;
z:=
0
;
for
j :=
1
to
Length(RichEdit1
.
text)
do
begin
if
RichEdit1
.
text[j]=bufpoiska
then
begin
positionbukv[z]:=j;
inc(z);
end
;
end
;
end
;
procedure
TForm1
.
Button3Click(Sender: TObject);
var
i:
integer
;
begin
i:=
0
;
while
positionbukv[i]<>
0
do
begin
RichEdit1
.
SelStart:=positionbukv[i]-
1
;
Richedit1
.
SelLength:=
1
;
Richedit1
.
SelAttributes
.
Color:=clRed;
inc(i);
end
;
end
;
end
.