source: trunk/Forms/UOperationProgress.pas

Last change on this file was 6, checked in by chronos, 13 years ago
  • Modified: Source selection separated to single form.
  • Added: Starting compiler and IDE with updated paths in configuration files.
File size: 3.4 KB
Line 
1unit UOperationProgress;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ExtCtrls, Process;
10
11type
12
13 { TOperationProgressForm }
14
15 TOperationProgressForm = class(TForm)
16 ButtonAbort: TButton;
17 ButtonClose: TButton;
18 Edit1: TEdit;
19 Memo1: TMemo;
20 Timer1: TTimer;
21 procedure ButtonAbortClick(Sender: TObject);
22 procedure ButtonCloseClick(Sender: TObject);
23 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
24 procedure FormShow(Sender: TObject);
25 procedure Timer1Timer(Sender: TObject);
26 private
27 Process: TProcess;
28 public
29 CommandLine: string;
30 Path: string;
31 Environment: string;
32 procedure Perform;
33 end;
34
35var
36 OperationProgressForm: TOperationProgressForm;
37
38implementation
39
40{$R *.lfm}
41
42{ TOperationProgressForm }
43
44procedure TOperationProgressForm.ButtonAbortClick(Sender: TObject);
45begin
46 if Assigned(Process) then
47 Process.Terminate(0);
48end;
49
50procedure TOperationProgressForm.ButtonCloseClick(Sender: TObject);
51begin
52
53end;
54
55procedure TOperationProgressForm.FormClose(Sender: TObject;
56 var CloseAction: TCloseAction);
57begin
58 Memo1.Clear;
59end;
60
61procedure TOperationProgressForm.FormShow(Sender: TObject);
62begin
63 Memo1.Clear;
64 ButtonAbort.Enabled := False;
65 ButtonClose.Enabled := False;
66 Timer1.Enabled := True;
67end;
68
69procedure TOperationProgressForm.Timer1Timer(Sender: TObject);
70begin
71 Timer1.Enabled := False;
72 ButtonAbort.Enabled := True;
73 Perform;
74end;
75
76procedure TOperationProgressForm.Perform;
77var
78 Buffer: string;
79 Count: Integer;
80 Text: string;
81 Line: string;
82begin
83 Text := '';
84 try
85 Process := TProcess.Create(nil);
86 if Path <> '' then
87 Process.CurrentDirectory := Path;
88 Path := '';
89 if Environment <> '' then
90 Process.Environment.Text := Environment;
91 Environment := '';
92 Process.CommandLine := CommandLine;
93 Edit1.Text := CommandLine;
94 Process.Options := [poUsePipes, poNoConsole];
95 Process.Execute;
96 Application.ProcessMessages;
97 while Process.Running or (Process.Output.NumBytesAvailable > 0) or
98 (Process.Stderr.NumBytesAvailable > 0) do
99 begin
100 if Process.Output.NumBytesAvailable > 0 then begin
101 SetLength(Buffer, 1000);
102 Count := Process.Output.Read(Buffer[1], Length(Buffer));
103 SetLength(Buffer, Count);
104 Text := Text + Buffer;
105 while Pos(LineEnding, Text) > 0 do begin
106 Line := Copy(Text, 1, Pos(LineEnding, Text) - 1);
107 Delete(Text, 1, Length(Line) + Length(LineEnding));
108 Memo1.Lines.Add(Line);
109 end;
110 end;
111
112 if Process.Stderr.NumBytesAvailable > 0 then begin
113 SetLength(Buffer, 1000);
114 Count := Process.Stderr.Read(Buffer[1], Length(Buffer));
115 SetLength(Buffer, Count);
116 Text := Text + Buffer;
117 while Pos(LineEnding, Text) > 0 do begin
118 Line := Copy(Text, 1, Pos(LineEnding, Text) - 1);
119 Delete(Text, 1, Length(Line) + Length(LineEnding));
120 Memo1.Lines.Add(Line);
121 end;
122 end;
123 Sleep(10);
124 Application.ProcessMessages;
125 end;
126 finally
127 Memo1.Lines.Add(Text);
128 FreeAndNil(Process);
129 end;
130 ButtonAbort.Enabled := False;
131 ButtonClose.Enabled := True;
132 ButtonAbort.ModalResult := mrOK;
133end;
134
135end.
136
Note: See TracBrowser for help on using the repository browser.