- Timestamp:
- Mar 29, 2016, 11:01:28 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UDriveScan.pas
r3 r5 9 9 10 10 type 11 TDriveScan = class; 12 11 13 TRunMode = (rmRead, rmWrite); 14 15 { TScanThread } 16 17 TScanThread = class(TThread) 18 Scan: TDriveScan; 19 procedure Execute; override; 20 end; 12 21 13 22 { TDriveScan } … … 17 26 FOnChange: TNotifyEvent; 18 27 FOnTerminate: TNotifyEvent; 28 ScanThread: TScanThread; 19 29 procedure DoChange; 20 30 procedure DoTerminate; 31 procedure Run; 21 32 public 22 33 Lock: TCriticalSection; … … 32 43 WritePattern: Byte; 33 44 function GetElapsedTime: TDateTime; 34 procedure Run; 45 procedure Start; 46 procedure Stop; 35 47 constructor Create; 36 48 destructor Destroy; override; … … 39 51 end; 40 52 41 { TScanThread }42 43 TScanThread = class(TThread)44 Form: TForm;45 procedure Execute; override;46 end;47 48 53 49 54 implementation 50 55 51 uses52 UFormMain;53 56 54 57 { TScanThread } … … 56 59 procedure TScanThread.Execute; 57 60 begin 58 TFormMain(Form).DriveScan.Run;61 Scan.Run; 59 62 end; 60 63 … … 75 78 if TimeEnd <> 0 then Result := TimeEnd - TimeStart 76 79 else Result := Now - TimeStart; 80 end; 81 82 procedure TDriveScan.Start; 83 begin 84 ScanThread := TScanThread.Create(True); 85 ScanThread.Scan := Self; 86 ScanThread.Start; 77 87 end; 78 88 … … 132 142 end; 133 143 144 procedure TDriveScan.Stop; 145 begin 146 Terminated := True; 147 ScanThread.Terminate; 148 ScanThread.WaitFor; 149 FreeAndNil(ScanThread); 150 end; 151 134 152 constructor TDriveScan.Create; 135 153 begin -
trunk/UFormMain.pas
r4 r5 63 63 PrefixMultiplier: TPrefixMultiplier; 64 64 LastBlockPos: Integer; 65 ScanThread: TScanThread;66 65 RedrawPending: Boolean; 67 66 procedure DriveScanChange(Sender: TObject); … … 106 105 DriveScan.OnChange := DriveScanChange; 107 106 DriveScan.OnTerminate := DriveScanTerminate; 108 ScanThread := TScanThread.Create(True);109 ScanThread.Form := Self;110 107 Project := TProject.Create; 111 108 EditDrive.Text := '/dev/sdb'; … … 114 111 procedure TFormMain.AScanStopExecute(Sender: TObject); 115 112 begin 116 DriveScan.Terminated := True; 117 ScanThread.Terminate; 118 ScanThread.WaitFor; 113 DriveScan.Stop; 119 114 UpdateInterface; 120 115 end; … … 128 123 DriveScan.Mode := TRunMode(ComboBoxRunMode.ItemIndex); 129 124 DriveScan.WritePattern := StrToInt(EditPattern.Text); 130 ScanThread.Start;125 DriveScan.Start; 131 126 UpdateInterface; 132 127 end; … … 156 151 begin 157 152 FreeAndNil(Project); 158 FreeAndNil(ScanThread);159 153 FreeAndNil(DriveScan); 160 154 FreeAndNil(PrefixMultiplier);
Note:
See TracChangeset
for help on using the changeset viewer.