unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
LabeledEdit1: TLabeledEdit;
Memo1: TMemo;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure addSlovosochetania( var lst:TStringList);
procedure Poisk(var str:string ; var list: TStringList);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
lineFile: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.addSlovosochetania( var lst:TStringList);
var
s: String;
begin
s := Trim(LabeledEdit1.Text);
while pos(',', s) > 0 do
begin
lst.Add(copy(s, 1, pos(',', s) - 1));
delete(s, 1, pos(',', s));
end;
if Trim(s) <> '' then
lst.Add(s);
end;
procedure TForm1.Poisk(var str:string ; var list: TStringList);
var
i: word;
begin
for i := 0 to list.Count - 1 do
begin
if pos(list.Strings[i], str) > 0 then
begin
Memo1.Lines.Add(list.Strings[i] + ' находится в строке = ' + IntToStr(lineFile) + ' позиция = ' + IntToStr(pos(list.Strings[i], str)));
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
openD: TOpenDialog;
list: TStringList;
f: TextFile;
str: string;
begin
openD := TOpenDialog.Create(nil);
openD.Filter := 'тесктовый файл|*.txt';
if openD.Execute then
begin
list := TStringList.Create;
addSlovosochetania(list);
if list.Count > 0 then
begin
lineFile := 1;
AssignFile(f, openD.FileName);
Reset(f);
while not eof(f) do
begin
readln(f, str);
Poisk(str, list);
Inc(lineFile);
end;
end;
end;
end;
end.