-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit1.pas
306 lines (251 loc) · 6.37 KB
/
Unit1.pas
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
MainMenu1: TMainMenu;
File1: TMenuItem;
New1: TMenuItem;
Open1: TMenuItem;
Save1: TMenuItem;
Saveas1: TMenuItem;
N1: TMenuItem;
PageSetup1: TMenuItem;
Print1: TMenuItem;
N2: TMenuItem;
Exit1: TMenuItem;
Edit1: TMenuItem;
Undo1: TMenuItem;
Cut1: TMenuItem;
Copy1: TMenuItem;
Paste1: TMenuItem;
N3: TMenuItem;
Find1: TMenuItem;
FindNext1: TMenuItem;
Replace1: TMenuItem;
Goto1: TMenuItem;
N4: TMenuItem;
SelactAll1: TMenuItem;
TimeDate1: TMenuItem;
Format1: TMenuItem;
WordWrap1: TMenuItem;
WordWrap2: TMenuItem;
View1: TMenuItem;
StatusBar1: TMenuItem;
Help1: TMenuItem;
HelpTopics1: TMenuItem;
N5: TMenuItem;
AboutNotepad1: TMenuItem;
StatusBar2: TStatusBar;
sd: TSaveDialog;
od: TOpenDialog;
fnt: TFontDialog;
p: TPrintDialog;
fnd: TFindDialog;
r: TReplaceDialog;
procedure StatusBar1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Find1Click(Sender: TObject);
procedure WordWrap1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Replace1Click(Sender: TObject);
procedure SelactAll1Click(Sender: TObject);
procedure Undo1Click(Sender: TObject);
procedure Cut1Click(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Paste1Click(Sender: TObject);
procedure Print1Click(Sender: TObject);
procedure Saveas1Click(Sender: TObject);
procedure WordWrap2Click(Sender: TObject);
procedure Memo1KeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure New1Click(Sender: TObject);
procedure AboutNotepad1Click(Sender: TObject);
procedure SwFileDrop1FileDragDrop(Sender: TObject; fcount, x, y: Integer;
FileList: TStrings);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
memory: TStrings;
{ Public declarations }
end;
var
Form1: TForm1;
modified: Boolean = false;
pos: integer;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.StatusBar1Click(Sender: TObject);
begin
StatusBar1.Checked := not StatusBar1.Checked;
StatusBar2.visible := StatusBar1.Checked;
end;
procedure TForm1.Open1Click(Sender: TObject);
var
r: integer;
begin
if modified = true then
r := MessageBox(Handle, 'The text in the Untitled file has changed.' +
#10#13 + '' + #10#13 + 'Do you want to save the changes?',
'Notepad', 4147)
else
begin
Memo1.lines.Clear;
pos := 1;
exit;
end;
if r = ID_CANCEL then
exit;
if od.execute then
begin
memory.LoadFromFile(od.filename);
Memo1.lines.Clear;
pos := 1;
end;
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
sd.execute;
end;
procedure TForm1.Find1Click(Sender: TObject);
begin
fnd.execute;
end;
procedure TForm1.WordWrap1Click(Sender: TObject);
begin
if fnt.execute then
Memo1.font := fnt.font;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Replace1Click(Sender: TObject);
begin
r.execute;
end;
procedure TForm1.SelactAll1Click(Sender: TObject);
begin
Memo1.SelectAll;
end;
procedure TForm1.Undo1Click(Sender: TObject);
begin
Memo1.Undo;
end;
procedure TForm1.Cut1Click(Sender: TObject);
begin
Memo1.CutToClipboard;
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
Memo1.CopyToClipboard;
end;
procedure TForm1.Paste1Click(Sender: TObject);
begin
Memo1.PasteFromClipboard;
end;
procedure TForm1.Print1Click(Sender: TObject);
begin
p.execute;
end;
procedure TForm1.Saveas1Click(Sender: TObject);
begin
sd.execute;
end;
procedure TForm1.WordWrap2Click(Sender: TObject);
begin
WordWrap2.Checked := not WordWrap2.Checked;
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if pos > length(memory.Text) then
exit;
if not(ord(memory.Text[pos]) = 13) then
Memo1.lines.Text := Memo1.lines.Text + memory.Text[pos];
Memo1.SelStart := pos;
Memo1.Lines.EndUpdate;
inc(pos);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memory := Tstringlist.Create;
pos := 1;
if paramcount > 0 then
begin
memory.LoadFromFile(paramstr(1));
exit;
end;
if od.execute then
begin
memory.LoadFromFile(od.filename);
end;
// bringwindowtotop(form1.handle);
end;
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
modified := true;
end;
procedure TForm1.New1Click(Sender: TObject);
var
r: integer;
begin
if modified = true then
r := MessageBox(Handle, 'The text in the Untitled file has changed.' +
#10#13 + '' + #10#13 + 'Do you want to save the changes?',
'Notepad', 4147)
else
begin
Memo1.lines.Clear;
pos := 1;
exit;
end;
if r = ID_CANCEL then
exit;
Memo1.lines.Clear;
pos := 1;
exit;
end;
procedure TForm1.AboutNotepad1Click(Sender: TObject);
begin
about.showmodal;
end;
procedure TForm1.SwFileDrop1FileDragDrop(Sender: TObject; fcount, x, y: Integer;
FileList: TStrings);
var
r: integer;
begin
if modified = true then
r := MessageBox(Handle, 'The text in the Untitled file has changed.' +
#10#13 + '' + #10#13 + 'Do you want to save the changes?',
'Notepad', 4147)
else
begin
Memo1.lines.Clear;
pos := 1;
exit;
end;
if r = ID_CANCEL then
exit;
Memo1.lines.Clear;
pos := 1;
memory.LoadFromFile(FileList[0]);
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if modified = true then
if MessageBox(Handle, 'The text in the Untitled file has changed.' + #10#13
+ '' + #10#13 + 'Do you want to save the changes?', 'Notepad', 4147) = ID_CANCEL
then
CanClose := false
else
CanClose := true;
end;
end.