Changeset 261


Ignore:
Timestamp:
Aug 9, 2011, 10:44:42 AM (13 years ago)
Author:
george
Message:
  • Modified: TTermThread and function RunInThread now signalize exception.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UThreading.pas

    r258 r261  
    8383  end;
    8484
     85  TTermThreadState = (ttsReady, ttsRunning, ttsFinished, ttsExceptionOccured);
     86
    8587  { TTermThread }
    8688
     
    8890  private
    8991  public
    90     Finished: Boolean;
     92    State: TTermThreadState;
     93    ExceptionMessage: string;
    9194    Method: TMethodCall;
    9295    procedure Execute; override;
     
    123126    Thread.Resume;
    124127    Thread.Method := Method;
    125     while not Thread.Finished do begin
     128    while (Thread.State = ttsRunning) or (Thread.State = ttsReady) do begin
    126129      if MainThreadID = ThreadID then Application.ProcessMessages;
    127130      Sleep(1);
    128131    end;
     132    if Thread.State = ttsExceptionOccured then
     133      raise Exception.Create(Thread.ExceptionMessage);
    129134  finally
    130135    Thread.Free;
     
    316321begin
    317322  try
     323    State := ttsRunning;
    318324    Method;
    319     Finished := True;
     325    State := ttsFinished;
    320326  except
    321327    on E: Exception do
    322       if Assigned(OnException) then
     328      if Assigned(OnException) then begin
    323329        OnException(FThread, E);
     330        ExceptionMessage := E.Message;
     331        State := ttsExceptionOccured;
     332      end;
    324333  end;
    325334end;
Note: See TracChangeset for help on using the changeset viewer.