unit Dialog_u;
{ Projekt DIALOG * Herwig Reidlinger }
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;
Edit2: TEdit;
N2: TMenuItem;
selectline1: TMenuItem;
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;
// Globale Variable oder Klassen-Variable deklarieren
MyLastFindLine : integer;
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 SelectLine (Memo: TMemo;
index: integer);
var
i: integer;
start, fin: integer;
begin
start:= 0;
fin:= length(Memo.lines[
index]);
for i:= 0
to index -1
do begin
start:= start + length(Memo.Lines[i]) + 2;
end;
memo.SetFocus;
Memo.SelStart:= start;
Memo.SelLength:= fin;
ShowMessage(memo.SelText);
end;
function SuchenInMemo( Memo : TMemo; FindenStr, NichtFindenStr :
string; LastFindLine : integer = 0 ) : integer;
var
LineIdx : integer;
begin
LineIdx := LastFindLine + 1;
Result := 0;
while
( LineIdx < Memo.Lines.Count )
and
( Result = 0 )
do
begin
if Pos( FindenStr, Memo.Lines[ LineIdx ] ) > 0
then
if Pos( NichtFindenStr, Memo.Lines[ LineIdx ] ) = 0
then
begin
Result := LineIdx;
SelectLine( Memo, LineIdx );
end;
end;
end;
procedure TFormDialog.Suche1Click(Sender: TObject);
begin
MyLastFindLine := SuchenInMemo( Memo1, Edit1.Text, Edit2.Text );
end;
procedure TFormDialog.WeiterSuchen1Click(Sender: TObject);
begin
MyLastFindLine := SuchenInMemo( Memo1, Edit1.Text, Edit2.Text, MyLastFindLine )
end;
end.