unit Dialog_u;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Menus, StdCtrls;
type
TFormDialog = class(TForm)
Memo1: TMemo;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
MainMenu: TMainMenu;
Menu_Datei: TMenuItem;
MenuLaden: TMenuItem;
MenuSpeichern: TMenuItem;
N1: TMenuItem;
MenuBeenden: TMenuItem;
Suche1: TMenuItem;
WeiterSuchen1: TMenuItem;
Edit1: TEdit;
CheckBox1: TCheckBox;
procedure MenuLadenClick(Sender: TObject);
procedure MenuSpeichernClick(Sender: TObject);
procedure MenuBeendenClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Suche1Click(Sender: TObject);
procedure WeiterSuchen1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
FormDialog: TFormDialog;
x: Integer;
find: Boolean = False;
implementation
{$R *.DFM}
procedure TFormDialog.MenuLadenClick(Sender: TObject);
begin
if OpenDialog.Execute then
TRY
Memo1.Lines.Loadfromfile(OpenDialog.Filename);
EXCEPT
ShowMessage ('Fehler beim Laden der Datei!');
END;
end;
procedure TFormDialog.MenuSpeichernClick(Sender: TObject);
begin
if SaveDialog.Execute then
TRY
Memo1.Lines.SavetoFile(SaveDialog.Filename);
EXCEPT
ShowMessage ('Fehler beim Speichern der Datei!');
END;
end;
procedure TFormDialog.MenuBeendenClick(Sender: TObject);
begin
FormDialog.Close;
end;
procedure TFormDialog.FormResize(Sender: TObject);
begin
Memo1.width := FormDialog.clientwidth;
Memo1.height := FormDialog.clientheight;
end;
procedure TFormDialog.Suche1Click(Sender: TObject);
var
i: Integer;
a: string;
begin
Memo1.Lines.Add('');
Memo1.Lines.Text := ' ' + Memo1.Lines.Text;
for i := 0 to Length(Memo1.Lines.Text) - Length(edit1.Text) do
begin
a := Copy(Memo1.Lines.Text, i, Length(edit1.Text));
if CheckBox1.Checked = True then
begin
if a = edit1.Text then
begin
find := True;
x := 2;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
Memo1.SetFocus;
Memo1.SelStart := i - 2;
Memo1.SelLength := Length(edit1.Text);
break;
end;
end
else
begin
if lowercase(a) = lowercase(edit1.Text) then
begin
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
find := True;
x := 2;
Memo1.SetFocus;
Memo1.SelStart := i - 2;
Memo1.SelLength := Length(edit1.Text);
break;
end;
end;
end;
if find = False then ShowMessage('SuchString nicht gefunden')
else
find := False;
end;
procedure TFormDialog.WeiterSuchen1Click(Sender: TObject);
var
i: Integer;
a: string;
d: Integer;
begin
d := 0;
for i := 0 to Length(Memo1.Lines.Text) - Length(edit1.Text) do
begin
a := Copy(Memo1.Lines.Text, i, Length(edit1.Text));
if CheckBox1.Checked = True then
begin
if a = edit1.Text then
begin
d := d + 1;
if d = x then
begin
find := True;
x := x + 1;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
Memo1.SetFocus;
Memo1.SelStart := i - 1;
Memo1.SelLength := Length(edit1.Text);
break;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
end;
end;
end
else
begin
if lowercase(a) = lowercase(edit1.Text) then
begin
d := d + 1;
if d = x then
begin
find := True;
x := x + 1;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
Memo1.SetFocus;
Memo1.SelStart := i - 1;
Memo1.SelLength := Length(edit1.Text);
break;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
end;
end;
end;
end;
if find = False then ShowMessage('SuchString nicht gefunden')
else
find := False;
end;
end.
------------------------------------