Changeset 5


Ignore:
Timestamp:
Mar 29, 2016, 11:01:28 PM (9 years ago)
Author:
chronos
Message:
  • Modified: TScanThread is now internal part of TDriveScan class.
  • Fixed: Now scan can be stopped and rerun again in runtime.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDriveScan.pas

    r3 r5  
    99
    1010type
     11  TDriveScan = class;
     12
    1113  TRunMode = (rmRead, rmWrite);
     14
     15  { TScanThread }
     16
     17  TScanThread = class(TThread)
     18    Scan: TDriveScan;
     19    procedure Execute; override;
     20  end;
    1221
    1322  { TDriveScan }
     
    1726    FOnChange: TNotifyEvent;
    1827    FOnTerminate: TNotifyEvent;
     28    ScanThread: TScanThread;
    1929    procedure DoChange;
    2030    procedure DoTerminate;
     31    procedure Run;
    2132  public
    2233    Lock: TCriticalSection;
     
    3243    WritePattern: Byte;
    3344    function GetElapsedTime: TDateTime;
    34     procedure Run;
     45    procedure Start;
     46    procedure Stop;
    3547    constructor Create;
    3648    destructor Destroy; override;
     
    3951  end;
    4052
    41   { TScanThread }
    42 
    43   TScanThread = class(TThread)
    44     Form: TForm;
    45     procedure Execute; override;
    46   end;
    47 
    4853
    4954implementation
    5055
    51 uses
    52   UFormMain;
    5356
    5457{ TScanThread }
     
    5659procedure TScanThread.Execute;
    5760begin
    58   TFormMain(Form).DriveScan.Run;
     61  Scan.Run;
    5962end;
    6063
     
    7578  if TimeEnd <> 0 then Result := TimeEnd - TimeStart
    7679    else Result := Now - TimeStart;
     80end;
     81
     82procedure TDriveScan.Start;
     83begin
     84  ScanThread := TScanThread.Create(True);
     85  ScanThread.Scan := Self;
     86  ScanThread.Start;
    7787end;
    7888
     
    132142end;
    133143
     144procedure TDriveScan.Stop;
     145begin
     146  Terminated := True;
     147  ScanThread.Terminate;
     148  ScanThread.WaitFor;
     149  FreeAndNil(ScanThread);
     150end;
     151
    134152constructor TDriveScan.Create;
    135153begin
  • trunk/UFormMain.pas

    r4 r5  
    6363    PrefixMultiplier: TPrefixMultiplier;
    6464    LastBlockPos: Integer;
    65     ScanThread: TScanThread;
    6665    RedrawPending: Boolean;
    6766    procedure DriveScanChange(Sender: TObject);
     
    106105  DriveScan.OnChange := DriveScanChange;
    107106  DriveScan.OnTerminate := DriveScanTerminate;
    108   ScanThread := TScanThread.Create(True);
    109   ScanThread.Form := Self;
    110107  Project := TProject.Create;
    111108  EditDrive.Text := '/dev/sdb';
     
    114111procedure TFormMain.AScanStopExecute(Sender: TObject);
    115112begin
    116   DriveScan.Terminated := True;
    117   ScanThread.Terminate;
    118   ScanThread.WaitFor;
     113  DriveScan.Stop;
    119114  UpdateInterface;
    120115end;
     
    128123  DriveScan.Mode := TRunMode(ComboBoxRunMode.ItemIndex);
    129124  DriveScan.WritePattern := StrToInt(EditPattern.Text);
    130   ScanThread.Start;
     125  DriveScan.Start;
    131126  UpdateInterface;
    132127end;
     
    156151begin
    157152  FreeAndNil(Project);
    158   FreeAndNil(ScanThread);
    159153  FreeAndNil(DriveScan);
    160154  FreeAndNil(PrefixMultiplier);
Note: See TracChangeset for help on using the changeset viewer.