// Bei jedem
Tastendruck wird (falls vorhanden) die dazu passende Zeichenfolge type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label1: TLabel; Label2: TLabel; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormKeyPress(Sender: TObject; var Key: Char); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.DFM} var such: string; suchmodus: boolean; start: integer; procedure TForm1.FormCreate(Sender: TObject); begin KeyPreview := true; Button2Click(Sender); end; procedure TForm1.Button1Click(Sender: TObject); begin suchmodus := true; label1.caption := 'Suchmodus ist ein'; end; procedure TForm1.Button2Click(Sender: TObject); begin suchmodus := false; label1.caption := 'Suchmodus ist aus'; Label2.caption := ''; Memo1.sellength := 0; such := ''; start := 1; end; procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); var x, lg: integer; begin if suchmodus then begin if (key = #8) and (such <> '') then begin delete(such, length(such), 1); start := 1; end else if key >= #32 then such := such + Key; if such = '' then begin label2.caption := ''; Memo1.sellength := 0; start := 1; key := #0; exit; end; lg := length(such); label2.caption := such; if (key = #13) and (Memo1.sellength > 0) then inc(start, lg); Memo1.sellength := 0; for x := start to length(memo1.text) - lg + 1 do if lstrcmpi(pchar(such), Pchar(copy(Memo1.text, x, lg))) = 0 then begin Memo1.selstart := x - 1; Memo1.sellength := lg; Memo1.setfocus; Memo1.perform(EM_SCROLLCARET, 0, 0); start := x; break; end; if Memo1.sellength = 0 then start := 1; key := #0; end; end; |
Zugriffe seit 6.9.2001 auf Delphi-Ecke