Changeset 6 for trunk/Forms/UFormConsole.pas
- Timestamp:
- May 6, 2015, 11:19:49 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormConsole.pas
r5 r6 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Buttons, ComCtrls, ActnList, Menus, Process;9 ExtCtrls, Process; 10 10 11 11 type … … 14 14 15 15 TFormConsole = class(TForm) 16 AAbort: TAction; 17 ARestart: TAction; 18 ActionList1: TActionList; 16 ButtonAbort: TButton; 19 17 EditCommand: TEdit; 20 MemoOutput: TMemo; 21 MenuItem1: TMenuItem; 22 MenuItem2: TMenuItem; 23 PopupMenu1: TPopupMenu; 24 ToolBar1: TToolBar; 25 ToolButton1: TToolButton; 26 procedure AAbortExecute(Sender: TObject); 18 Memo1: TMemo; 19 Timer1: TTimer; 20 procedure ButtonAbortClick(Sender: TObject); 27 21 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 28 22 procedure FormCreate(Sender: TObject); 29 23 procedure FormDestroy(Sender: TObject); 30 24 procedure FormShow(Sender: TObject); 25 procedure Timer1Timer(Sender: TObject); 31 26 private 32 27 Process: TProcess; … … 36 31 Parameters: TStringList; 37 32 WorkingDir: string; 38 Environment: TStringList;33 Environment: string; 39 34 Aborted: Boolean; 40 Duration: TDateTime;35 Log: TStringList; 41 36 procedure Perform; 42 37 end; … … 47 42 implementation 48 43 49 uses50 UFormMain;51 52 44 {$R *.lfm} 53 45 … … 57 49 begin 58 50 Parameters := TStringList.Create; 59 Parameters.QuoteChar := ' '; 60 Parameters.Delimiter := ' '; 61 Environment := TStringList.Create; 62 Environment.QuoteChar := ' '; 63 Environment.Delimiter := ' '; 51 Log := TStringList.Create; 64 52 end; 65 53 66 54 procedure TFormConsole.FormDestroy(Sender: TObject); 67 55 begin 68 Environment.Free;56 Log.Free; 69 57 Parameters.Free; 70 58 end; … … 72 60 procedure TFormConsole.FormShow(Sender: TObject); 73 61 begin 74 //FormMain.PersistentForm1.Load(Self);75 MemoOutput.Clear;76 AAbort.Enabled := False;62 Memo1.Clear; 63 ButtonAbort.Enabled := False; 64 Timer1.Enabled := True; 77 65 end; 78 66 79 procedure TFormConsole.AAbortExecute(Sender: TObject); 67 procedure TFormConsole.Timer1Timer(Sender: TObject); 68 begin 69 Timer1.Enabled := False; 70 Perform; 71 end; 72 73 procedure TFormConsole.ButtonAbortClick(Sender: TObject); 80 74 begin 81 75 if Assigned(Process) then begin … … 88 82 ); 89 83 begin 90 AAbort.Execute; 91 //FormMain.PersistentForm1.Save(Self); 84 ButtonAbort.Click; 92 85 end; 93 86 … … 99 92 Line: string; 100 93 CommandLine: string; 101 TimeStart: TDateTime;102 94 begin 103 TimeStart := Now;104 if not Visible then Show;105 95 Text := ''; 106 96 try 107 97 Process := TProcess.Create(nil); 108 98 Aborted := False; 109 AAbort.Enabled := True;99 ButtonAbort.Enabled := True; 110 100 if WorkingDir <> '' then 111 101 Process.CurrentDirectory := WorkingDir; 112 102 //WorkingDir := ''; 113 if Environment .Count <> 0then114 Process.Environment. Assign(Environment);115 //Environment := '';103 if Environment <> '' then 104 Process.Environment.Text := Environment; 105 Environment := ''; 116 106 //Process.Executable := Executable; 117 107 //Process.Parameters.Assign(Parameters); 118 Process.CommandLine := Executable + ' ' + Parameters. DelimitedText;119 CommandLine := Executable + ' ' + Parameters.DelimitedText;120 //if CommandLine[Length(CommandLine)] = #$athen121 //SetLength(CommandLine, Length(CommandLine) - 1);108 Process.CommandLine := Executable + ' ' + Parameters.Text; 109 CommandLine := Executable + ' ' + StringReplace(Parameters.Text, LineEnding, ' ', [rfReplaceAll]); 110 if CommandLine[Length(CommandLine)] = LineEnding then 111 SetLength(CommandLine, Length(CommandLine) - 1); 122 112 EditCommand.Text := CommandLine; 123 113 Process.Options := [poUsePipes, poNoConsole]; … … 135 125 Line := Copy(Text, 1, Pos(LineEnding, Text) - 1); 136 126 Delete(Text, 1, Length(Line) + Length(LineEnding)); 137 Memo Output.Lines.Add(Line);127 Memo1.Lines.Add(Line); 138 128 end; 139 129 end; … … 147 137 Line := Copy(Text, 1, Pos(LineEnding, Text) - 1); 148 138 Delete(Text, 1, Length(Line) + Length(LineEnding)); 149 Memo Output.Lines.Add(Line);139 Memo1.Lines.Add(Line); 150 140 end; 151 141 end; … … 154 144 end; 155 145 finally 156 Memo Output.Lines.Add(Text);146 Memo1.Lines.Add(Text); 157 147 FreeAndNil(Process); 158 148 end; 159 Duration := Now - TimeStart; 160 AAbort.Enabled := False; 161 //ToolButton1.ModalResult := mrOK; 149 Log.Assign(Memo1.Lines); 150 ButtonAbort.Enabled := False; 151 //ModalResult := mrOK; 152 //Close; 162 153 end; 163 154
Note:
See TracChangeset
for help on using the changeset viewer.