-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathunit6.pas
More file actions
242 lines (216 loc) · 6.63 KB
/
unit6.pas
File metadata and controls
242 lines (216 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
(******************************************************************************)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* This file is part of KLab *)
(* *)
(* See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(******************************************************************************)
Unit Unit6;
{$MODE objfpc}{$H+}
Interface
Uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, lcltype;
Type
{ TForm6 }
TForm6 = Class(TForm)
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Edit1: TEdit;
Label1: TLabel;
RadioGroup1: TRadioGroup;
Procedure Button1Click(Sender: TObject);
Procedure Button2Click(Sender: TObject);
Procedure Edit1KeyPress(Sender: TObject; Var Key: char);
Procedure Edit1KeyUp(Sender: TObject; Var Key: Word; Shift: TShiftState);
Procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
End;
Var
Form6: TForm6;
Implementation
{$R *.lfm}
Uses uklab, math;
(*
Geht davon aus das Offset, im Bereich
1 .. Length(String) liegt
Leifert das 1. Vorkommen von Substr, nach Offset
*)
Function PosEx(Substr, Source: String; Offset: Integer): integer;
Var
tmp: String;
t: Integer;
Begin
result := 0;
tmp := copy(source, offset, length(source));
t := pos(Substr, tmp);
If t <> 0 Then
result := t + Offset - 1;
End;
Function posrev(Substr: String; S: String): Integer;
Var
i, j: Integer;
b: Boolean;
Begin
result := 0;
i := length(s) - length(Substr) + 1;
While i > 0 Do Begin
b := True;
For j := 1 To Length(Substr) Do
If s[i - 1 + j] <> Substr[j] Then Begin
b := False;
break;
End;
If b Then Begin
result := i;
exit;
End;
dec(i);
End;
End;
(*
Gleich wie PosEx nur Rückwärts suchen
*)
Function PosRevEx(Substr, Source: String; Offset: Integer): integer;
Var
tmp: String;
t: Integer;
Begin
// result := 0;
tmp := copy(source, 1, Offset);
t := posRev(Substr, tmp);
// If t <> 0 Then
result := t;
End;
{ TForm6 }
Procedure TForm6.FormCreate(Sender: TObject);
Begin
Tform(self).Constraints.MaxHeight := Tform(self).Height;
Tform(self).Constraints.MinHeight := Tform(self).Height;
Tform(self).Constraints.Maxwidth := Tform(self).width;
Tform(self).Constraints.Minwidth := Tform(self).width;
edit1.text := '';
caption := 'Find..';
End;
Procedure TForm6.Button1Click(Sender: TObject);
Var
t, x, y: Integer;
suchtext, s: String;
weiter: Boolean;
Begin
// Die Aktuelle Zeile und Spalte Auslesen.
x := AktualSynedit.CaretX;
y := AktualSynedit.Carety - 1;
If CheckBox1.checked Then Begin
(*
Das ist So eigentlich nicht ganz richtig, da ja ein Wort auch am Anfang,
oder am Ende einer Zeile Stehen kann.
Aber das Ganze wird nachher "Weggehackt"
*)
suchtext := ' ' + Edit1.text + ' ';
End
Else Begin
suchtext := Edit1.text;
End;
weiter := true;
Case RadioGroup1.ItemIndex Of
// Rückwärts suchen
0: Begin
// Die Aktuelle Zeile Auslesen
If CheckBox1.checked Then
s := ' ' + AktualSynedit.Lines[y] + ' '
Else
s := AktualSynedit.Lines[y];
// Das ist eigentlich falsch, aber nur so können wir mehrfach suchanfragen handeln.
x := max(1, x - length(suchtext));
While weiter Do Begin
// Case sensitives Suchen
If CheckBox2.checked Then
t := PosRevEx(suchtext, s, x)
Else
t := PosRevEx(lowercase(suchtext), lowercase(s), x);
// Wenn was gefunden wird
If t <> 0 Then Begin
If CheckBox1.checked Then
AktualSynedit.CaretX := t - 1
Else
AktualSynedit.CaretX := t;
AktualSynedit.Carety := y + 1;
AktualSynedit.SelectWord;
weiter := false;
End;
dec(y);
If (y < 0) And Weiter Then Begin
If id_NO = Application.MessageBox('Reached begin of text, wrap ?', 'Question', MB_YESNO Or MB_ICONQUESTION) Then
weiter := false;
y := AktualSynedit.lines.count - 1;
End;
// Die Aktuelle Zeile Auslesen
If CheckBox1.checked Then
s := ' ' + AktualSynedit.Lines[y] + ' '
Else
s := AktualSynedit.Lines[y];
x := length(s);
End;
End;
// Vorwärts Suchen
1: Begin
While weiter Do Begin
// Die Aktuelle Zeile Auslesen
If CheckBox1.checked Then
s := ' ' + AktualSynedit.Lines[y] + ' '
Else
s := AktualSynedit.Lines[y];
// Case sensitives Suchen
If CheckBox2.checked Then
t := posEx(suchtext, s, x)
Else
t := posEx(lowercase(suchtext), lowercase(s), x);
// Wenn was gefunden wird
If t <> 0 Then Begin
If CheckBox1.checked Then
AktualSynedit.CaretX := t - 1
Else
AktualSynedit.CaretX := t;
AktualSynedit.Carety := y + 1;
AktualSynedit.SelectWord;
weiter := false;
End;
x := 1;
inc(y);
If (y >= AktualSynedit.lines.count) And Weiter Then Begin
If id_NO = Application.MessageBox('Reached end of text, wrap ?', 'Question', MB_YESNO Or MB_ICONQUESTION) Then
weiter := false;
y := 0;
End;
End;
End;
End;
End;
Procedure TForm6.Button2Click(Sender: TObject);
Begin
close;
End;
Procedure TForm6.Edit1KeyPress(Sender: TObject; Var Key: char);
Begin
If (key = #13) And button1.visible Then Begin
button1.onclick(Nil);
End;
End;
Procedure TForm6.Edit1KeyUp(Sender: TObject; Var Key: Word; Shift: TShiftState);
Begin
button1.enabled := length(Edit1.text) <> 0;
End;
End.