Changeset 297 for ExceptionLogger/UExceptionLogger.pas
- Timestamp:
- Nov 16, 2011, 7:28:20 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ExceptionLogger/UExceptionLogger.pas
r265 r297 10 10 11 11 type 12 TThreadSynchronizeEvent = procedure (AObject: TObject; Method: TThreadMethod) of object; 12 13 13 14 { TExceptionLogger } … … 17 18 FMaxCallStackDepth: Integer; 18 19 FLogFileName: string; 20 FOnThreadSynchronize: TThreadSynchronizeEvent; 21 procedure ThreadSynchronize(AObject: TObject; Method: TThreadMethod); 19 22 function GetAppVersion: string; 20 23 procedure SetMaxCallStackDepth(const AValue: Integer); … … 37 40 property LogFileName: string read FLogFileName write FLogFileName; 38 41 property MaxCallStackDepth: Integer read FMaxCallStackDepth write SetMaxCallStackDepth; 42 property OnThreadSynchronize: TThreadSynchronizeEvent read FOnThreadSynchronize 43 write FOnThreadSynchronize; 39 44 end; 40 45 … … 63 68 SProcedureMethod = 'Procedure/method'; 64 69 SUnit = 'Unit'; 70 SExceptionHandlerCannotBeSynchronized = 'Exception handler cannot be synchronized with main thread.'; 65 71 66 72 implementation … … 84 90 Application.OnException := ExceptionHandler; 85 91 Application.Flags := Application.Flags - [AppNoExceptionMessages]; 92 OnThreadSynchronize := ThreadSynchronize; 86 93 end; 87 94 … … 162 169 LastException := E; 163 170 ExceptionSender := Sender; 164 if ExceptionSender is TThread then 165 TThread.Synchronize(TThread(ExceptionSender), ShowForm) 166 else ShowForm; 171 if (MainThreadID <> ThreadID) then begin 172 if Assigned(FOnThreadSynchronize) then 173 FOnThreadSynchronize(Sender, ShowForm) 174 else raise Exception.Create(SExceptionHandlerCannotBeSynchronized); 175 end else ShowForm; 167 176 end; 168 177 … … 209 218 FMaxCallStackDepth := AValue; 210 219 StackTrace.MaxDepth := AValue; 220 end; 221 222 procedure TExceptionLogger.ThreadSynchronize(AObject: TObject; 223 Method: TThreadMethod); 224 begin 225 if AObject is TThread then TThread.Synchronize(TThread(AObject), Method) 226 else raise Exception.Create(SExceptionHandlerCannotBeSynchronized); 211 227 end; 212 228
Note:
See TracChangeset
for help on using the changeset viewer.