Changeset 368
- Timestamp:
- May 29, 2012, 7:46:31 AM (12 years ago)
- Location:
- Common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/Common.lpk
r364 r368 74 74 <Item13> 75 75 <Filename Value="UJobProgressView.pas"/> 76 <HasRegisterProc Value="True"/> 76 77 <UnitName Value="UJobProgressView"/> 77 78 </Item13> -
Common/Common.pas
r364 r368 17 17 begin 18 18 RegisterUnit('UDebugLog', @UDebugLog.Register); 19 RegisterUnit('UJobProgressView', @UJobProgressView.Register); 19 20 end; 20 21 -
Common/UJobProgressView.lfm
r364 r368 1 object JobProgressView: TJobProgressView1 object FormJobProgressView: TFormJobProgressView 2 2 Left = 466 3 3 Height = 248 -
Common/UJobProgressView.pas
r364 r368 38 38 end; 39 39 40 TFormJobProgressView = class; 40 41 TJobProgressView = class; 41 42 TJobThread = class; 42 43 TJob = class; 43 44 44 TJobProgressViewMethod = procedure of object;45 TJobProgressViewMethod = procedure(Job: TJob) of object; 45 46 46 47 { TJob } … … 76 77 end; 77 78 78 { T JobProgressView }79 80 T JobProgressView = class(TForm)79 { TFormJobProgressView } 80 81 TFormJobProgressView = class(TForm) 81 82 ImageList1: TImageList; 82 83 Label2: TLabel; … … 100 101 procedure FormCreate(Sender: TObject); 101 102 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 103 public 104 JobProgressView: TJobProgressView; 105 end; 106 107 { TJobProgressView } 108 109 TJobProgressView = class(TComponent) 102 110 private 111 FAutoClose: Boolean; 103 112 Finished: Boolean; 104 113 FOnJobFinish: TJobProgressViewMethod; 114 FShowDelay: Integer; 105 115 FTerminate: Boolean; 106 116 FormList: TList; 117 TotalStartTime: TDateTime; 107 118 Log: TStringList; 119 Form: TFormJobProgressView; 108 120 procedure SetTerminate(const AValue: Boolean); 109 121 procedure UpdateProgress; … … 112 124 procedure UpdateHeight; 113 125 public 114 TotalStartTime: TDateTime;115 126 Jobs: TObjectList; // TListObject<TJob> 116 127 CurrentJob: TJob; 117 128 CurrentJobIndex: Integer; 118 ShowDelay: Integer;119 AutoClose: Boolean;120 129 constructor Create(TheOwner: TComponent); override; 121 130 destructor Destroy; override; … … 127 136 procedure TermSleep(Delay: Integer); 128 137 property Terminate: Boolean read FTerminate write SetTerminate; 138 published 139 property ShowDelay: Integer read FShowDelay write FShowDelay; 140 property AutoClose: Boolean read FAutoClose write FAutoClose; 129 141 property OnJobFinish: TJobProgressViewMethod read FOnJobFinish 130 142 write FOnJobFinish; 131 143 end; 132 144 133 var 134 JobProgressView: TJobProgressView; 145 //var 146 // FormJobProgressView: TFormJobProgressView; 147 148 procedure Register; 135 149 136 150 resourcestring … … 159 173 try 160 174 //raise Exception.Create('Exception in job'); 161 JobProgressView.CurrentJob.Method;175 ProgressView.CurrentJob.Method(Job); 162 176 except 163 177 on E: Exception do begin … … 201 215 Terminate := False; 202 216 203 BringToFront;217 Form.BringToFront; 204 218 205 219 Finished := False; 206 Caption := SPleaseWait;220 Form.Caption := SPleaseWait; 207 221 try 208 FormList := Screen.DisableForms( Self);222 FormList := Screen.DisableForms(Form); 209 223 Log.Clear; 210 MemoLog.Clear;211 212 LabelEstimatedTimePart.Visible := False;213 LabelEstimatedTimeTotal.Visible := False;224 Form.MemoLog.Clear; 225 226 Form.LabelEstimatedTimePart.Visible := False; 227 Form.LabelEstimatedTimeTotal.Visible := False; 214 228 215 229 CurrentJob := nil; 216 230 if ShowDelay = 0 then begin 217 TimerUpdate.Interval := UpdateInterval;218 TimerUpdate.Enabled := True;219 TimerUpdateTimer(Self);231 Form.TimerUpdate.Interval := UpdateInterval; 232 Form.TimerUpdate.Enabled := True; 233 Form.TimerUpdateTimer(Self); 220 234 end else begin 221 TimerUpdate.Interval := ShowDelay;222 TimerUpdate.Enabled := True;235 Form.TimerUpdate.Interval := ShowDelay; 236 Form.TimerUpdate.Enabled := True; 223 237 end; 224 238 225 239 TotalStartTime := Now; 226 ProgressBarTotal.Position := 0;227 ProgressBarTotal.Visible := False;240 Form.ProgressBarTotal.Position := 0; 241 Form.ProgressBarTotal.Visible := False; 228 242 //UpdateHeight; 229 243 … … 234 248 CurrentJob := TJob(Jobs[I]); 235 249 StartTime := Now; 236 LabelEstimatedTimePart.Caption := Format(SEstimatedTime, ['']);237 ProgressBarPart.Position := 0;238 ProgressBarPart.Visible := False;250 Form.LabelEstimatedTimePart.Caption := Format(SEstimatedTime, ['']); 251 Form.ProgressBarPart.Position := 0; 252 Form.ProgressBarPart.Visible := False; 239 253 //Show; 240 254 ReloadJobList; … … 242 256 if NoThreaded then begin 243 257 Thread := nil; 244 Method ;258 Method(CurrentJob); 245 259 end else begin 246 260 try … … 262 276 end; 263 277 end; 264 ProgressBarPart.Hide;278 Form.ProgressBarPart.Hide; 265 279 if Terminate then Break; 266 280 EndTime := Now; 267 281 Finished := True; 268 282 if Assigned(FOnJobFinish) then 269 FOnJobFinish ;283 FOnJobFinish(CurrentJob); 270 284 Inc(I); 271 285 end; 272 286 finally 273 287 CurrentJob := nil; 274 TimerUpdate.Enabled := False;288 Form.TimerUpdate.Enabled := False; 275 289 Screen.EnableForms(FormList); 276 290 //if Visible then Hide; 277 MemoLog.Lines.Assign(Log);278 if ( MemoLog.Lines.Count = 0) and AutoClose then begin279 Hide;291 Form.MemoLog.Lines.Assign(Log); 292 if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin 293 Form.Hide; 280 294 end; 281 295 Clear; 282 Caption := SFinished;296 Form.Caption := SFinished; 283 297 //LabelEstimatedTimePart.Visible := False; 284 298 Finished := True; … … 297 311 PanelLogVisible: Boolean; 298 312 begin 313 with Form do begin 299 314 H := PanelOperationsTitle.Height; 300 315 PanelOperationsVisible := Jobs.Count > 0; … … 324 339 H := H + MemoLogHeight; 325 340 if Height <> H then Height := H; 326 end; 327 328 procedure TJobProgressView.TimerUpdateTimer(Sender: TObject); 341 end; 342 end; 343 344 procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject); 329 345 var 330 346 ProgressBarPartVisible: Boolean; 331 347 ProgressBarTotalVisible: Boolean; 332 348 begin 333 UpdateProgress; 334 if Visible and (not ProgressBarPart.Visible) and Assigned(CurrentJob) and 335 (CurrentJob.Progress.Value > 0) then begin 349 JobProgressView.UpdateProgress; 350 if Visible and (not ProgressBarPart.Visible) and 351 Assigned(JobProgressView.CurrentJob) and 352 (JobProgressView.CurrentJob.Progress.Value > 0) then begin 336 353 ProgressBarPartVisible := True; 337 354 if ProgressBarPartVisible <> ProgressBarPart.Visible then … … 347 364 end; 348 365 349 procedure T JobProgressView.FormDestroy(Sender:TObject);350 begin 351 end; 352 353 procedure T JobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem);354 begin 355 if (Item.Index >= 0) and (Item.Index < Job s.Count) then356 with TJob(Job s[Item.Index]) do begin366 procedure TFormJobProgressView.FormDestroy(Sender:TObject); 367 begin 368 end; 369 370 procedure TFormJobProgressView.ListViewJobsData(Sender: TObject; Item: TListItem); 371 begin 372 if (Item.Index >= 0) and (Item.Index < JobProgressView.Jobs.Count) then 373 with TJob(JobProgressView.Jobs[Item.Index]) do begin 357 374 Item.Caption := Title; 358 if Item.Index = CurrentJobIndex then Item.ImageIndex := 1375 if Item.Index = JobProgressView.CurrentJobIndex then Item.ImageIndex := 1 359 376 else if Finished then Item.ImageIndex := 0 360 377 else Item.ImageIndex := 2; 361 Item.Data := Job s[Item.Index];362 end; 363 end; 364 365 procedure T JobProgressView.FormClose(Sender: TObject;378 Item.Data := JobProgressView.Jobs[Item.Index]; 379 end; 380 end; 381 382 procedure TFormJobProgressView.FormClose(Sender: TObject; 366 383 var CloseAction: TCloseAction); 367 384 begin … … 369 386 end; 370 387 371 procedure T JobProgressView.FormCreate(Sender: TObject);388 procedure TFormJobProgressView.FormCreate(Sender: TObject); 372 389 begin 373 390 Caption := SPleaseWait; … … 399 416 end; 400 417 401 procedure T JobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean);402 begin 403 CanClose := Finished;404 Terminate := True;418 procedure TFormJobProgressView.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 419 begin 420 CanClose := JobProgressView.Finished; 421 JobProgressView.Terminate := True; 405 422 Caption := SPleaseWait + STerminate; 406 423 end; … … 427 444 begin 428 445 if Assigned(CurrentJob) then 429 with CurrentJob do begin446 with CurrentJob, Form do begin 430 447 // Part progress 431 448 ProgressBarPart.Max := Progress.Max; … … 468 485 UpdateHeight; 469 486 // Workaround for not showing first line 470 ListViewJobs.Items.Count := Jobs.Count + 1;471 ListViewJobs.Refresh;472 473 if ListViewJobs.Items.Count <> Jobs.Count then474 ListViewJobs.Items.Count := Jobs.Count;475 ListViewJobs.Refresh;487 Form.ListViewJobs.Items.Count := Jobs.Count + 1; 488 Form.ListViewJobs.Refresh; 489 490 if Form.ListViewJobs.Items.Count <> Jobs.Count then 491 Form.ListViewJobs.Items.Count := Jobs.Count; 492 Form.ListViewJobs.Refresh; 476 493 //Application.ProcessMessages; 477 494 end; … … 480 497 begin 481 498 inherited; 499 if not (csDesigning in ComponentState) then begin 500 Form := TFormJobProgressView.Create(Self); 501 Form.JobProgressView := Self; 502 end; 482 503 Jobs := TObjectList.Create; 483 504 Log := TStringList.Create; … … 501 522 procedure TProgress.SetMax(const AValue: Integer); 502 523 begin 503 FMax := AValue; 504 if FValue >= FMax then FValue := FMax; 524 try 525 FLock.Acquire; 526 FMax := AValue; 527 if FValue >= FMax then FValue := FMax; 528 finally 529 FLock.Release; 530 end; 505 531 end; 506 532 … … 509 535 Change: Boolean; 510 536 begin 511 if AValue < Max then begin 512 Change := AValue <> FValue; 513 FValue := AValue; 514 if Change and Assigned(FOnChange) then FOnChange(Self); 537 try 538 FLock.Acquire; 539 if AValue < Max then begin 540 Change := AValue <> FValue; 541 FValue := AValue; 542 if Change and Assigned(FOnChange) then 543 try 544 FLock.Release; 545 FOnChange(Self); 546 finally 547 FLock.Acquire; 548 end; 549 end; 550 finally 551 FLock.Release; 515 552 end; 516 553 end;
Note:
See TracChangeset
for help on using the changeset viewer.