-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvert.pas
117 lines (108 loc) · 3.12 KB
/
Convert.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
unit Convert;
interface
uses Windows, Classes, Graphics, Forms, Controls, Buttons,
StdCtrls, ExtCtrls, Dialogs,SysUtils, fileops;
type
TConvDlg1 = class(TForm)
OKBtn: TBitBtn;
CancelBtn: TBitBtn;
HelpBtn: TBitBtn;
Bevel1: TBevel;
RadioGroup1: TRadioGroup;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure OKBtnClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ConvDlg1: TConvDlg1;
implementation
{$R *.DFM}
uses TecMain, Types;
procedure TConvDlg1.OKBtnClick(Sender: TObject);
var f, g : textfile;
ch : Char;
exitflag, saveflag: boolean;
dummy: string;
begin
if OpenDialog1.Execute then
begin
repeat
saveflag:= SaveDialog1.Execute;
if saveflag then
begin
exitflag:=true;
if SaveDialog1.filename=OpenDialog1.filename then
Case MessageDlg('Select a filename different from the input file!', mtWarning,[mbCancel,mbRetry], 0) of
mrCancel:
begin
Saveflag:=false;
exit;
end;
mrRetry: ExitFlag:=False;
end;
end;
until exitflag;
if saveflag then
begin
Screen.Cursor := CrHourGlass;
try
AssignFile(f, OpenDialog1.FileName);
Reset(f);
try
AssignFile(g, SaveDialog1.FileName);
Rewrite(g);
if RadioGroup1.ItemIndex = 0 then
begin
While not eof(f) do
begin
readln(f, dummy);
dummy:=AdjustLineBreaks(Dummy);
writeln(g, dummy);
end;
end
else
begin
While not eof(f) do
begin
read(f, ch);
if ch <> #10 then write(g, ch);
end;
end;
CloseFile(g);
Screen.Cursor := CrDefault;
TecMainWin.WriteToStatusbar(nil ,'Written to file '+SaveDialog1.FileName);
except
on EInOutError do {can not write to file}
begin
CloseFile(f);
Screen.Cursor := CrDefault;
MessageDlg('Conversion of '+OpenDialog1.FileName+' failed!', mtInformation,[mbOk], 0);
end;
end;
CloseFile(f);
except {can not open file}
On EInOutError do
begin
Globalfailed:=true;
Screen.Cursor:=crDefault;
MessageDlg('Can not open '+OpenDialog1.Filename+' !'#10#13+
'Processing stopped. File might be in use by another application.',
mtError,[mbOk], 0);
Close;
Exit;
end;
end;
end;
end;
end;
procedure TConvDlg1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if MDIChildCount <= 1 then TecMainWin.Window1.Enabled := false;
Action := caFree;
end;
end.