Changeset 297 for ExceptionLogger


Ignore:
Timestamp:
Nov 16, 2011, 7:28:20 AM (13 years ago)
Author:
george
Message:
  • Added: TExceptionLogger can be extended for handling synchronization of different thread classes.
Location:
ExceptionLogger
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ExceptionLogger/Demo

    • Property svn:ignore
      •  

        old new  
        11lib
        22Demo
         3Demo.exe
  • ExceptionLogger/Demo/Demo.lpi

    r281 r297  
    3838      </Item2>
    3939    </RequiredPackages>
    40     <Units Count="7">
     40    <Units Count="8">
    4141      <Unit0>
    4242        <Filename Value="Demo.lpr"/>
    4343        <IsPartOfProject Value="True"/>
    4444        <UnitName Value="Demo"/>
    45         <EditorIndex Value="1"/>
     45        <EditorIndex Value="2"/>
    4646        <WindowIndex Value="0"/>
    4747        <TopLine Value="1"/>
     
    5959        <EditorIndex Value="0"/>
    6060        <WindowIndex Value="0"/>
    61         <TopLine Value="34"/>
    62         <CursorPos X="3" Y="47"/>
     61        <TopLine Value="14"/>
     62        <CursorPos X="1" Y="27"/>
    6363        <UsageCount Value="20"/>
    6464        <Loaded Value="True"/>
     
    6868        <Filename Value="/usr/lib64/lazarus/components/codetools/codetools.pas"/>
    6969        <UnitName Value="CodeTools"/>
    70         <EditorIndex Value="3"/>
    7170        <WindowIndex Value="0"/>
    7271        <TopLine Value="4"/>
    7372        <CursorPos X="32" Y="15"/>
    7473        <UsageCount Value="10"/>
    75         <Loaded Value="True"/>
    7674      </Unit2>
    7775      <Unit3>
     
    8987        <ResourceBaseClass Value="Form"/>
    9088        <UnitName Value="UExceptionForm"/>
    91         <EditorIndex Value="4"/>
     89        <EditorIndex Value="3"/>
    9290        <WindowIndex Value="0"/>
    9391        <TopLine Value="83"/>
     
    10098      <Unit5>
    10199        <Filename Value="../ReadMe.txt"/>
    102         <EditorIndex Value="5"/>
     100        <EditorIndex Value="4"/>
    103101        <WindowIndex Value="0"/>
    104102        <TopLine Value="1"/>
     
    110108      <Unit6>
    111109        <Filename Value="/usr/share/fpcsrc/rtl/inc/objpash.inc"/>
    112         <EditorIndex Value="2"/>
    113110        <WindowIndex Value="0"/>
    114111        <TopLine Value="171"/>
    115112        <CursorPos X="23" Y="185"/>
    116113        <UsageCount Value="10"/>
    117         <Loaded Value="True"/>
    118114      </Unit6>
     115      <Unit7>
     116        <Filename Value="../UExceptionLogger.pas"/>
     117        <UnitName Value="UExceptionLogger"/>
     118        <EditorIndex Value="1"/>
     119        <WindowIndex Value="0"/>
     120        <TopLine Value="228"/>
     121        <CursorPos X="23" Y="233"/>
     122        <UsageCount Value="10"/>
     123        <Loaded Value="True"/>
     124        <DefaultSyntaxHighlighter Value="Delphi"/>
     125      </Unit7>
    119126    </Units>
    120     <JumpHistory Count="17" HistoryIndex="16">
     127    <JumpHistory Count="22" HistoryIndex="21">
    121128      <Position1>
    122129        <Filename Value="UMainForm.pas"/>
     
    128135      </Position2>
    129136      <Position3>
    130         <Filename Value="/usr/lib64/lazarus/components/codetools/codetools.pas"/>
    131         <Caret Line="1" Column="1" TopLine="1"/>
     137        <Filename Value="UMainForm.pas"/>
     138        <Caret Line="18" Column="28" TopLine="9"/>
    132139      </Position3>
    133140      <Position4>
    134         <Filename Value="/usr/lib64/lazarus/components/codetools/codetools.pas"/>
    135         <Caret Line="32" Column="1" TopLine="4"/>
     141        <Filename Value="../UExceptionForm.pas"/>
     142        <Caret Line="13" Column="1" TopLine="1"/>
    136143      </Position4>
    137144      <Position5>
    138145        <Filename Value="UMainForm.pas"/>
    139         <Caret Line="18" Column="28" TopLine="9"/>
     146        <Caret Line="19" Column="65" TopLine="9"/>
    140147      </Position5>
    141148      <Position6>
    142149        <Filename Value="../UExceptionForm.pas"/>
    143         <Caret Line="13" Column="1" TopLine="1"/>
     150        <Caret Line="88" Column="1" TopLine="83"/>
    144151      </Position6>
    145152      <Position7>
    146         <Filename Value="UMainForm.pas"/>
    147         <Caret Line="19" Column="65" TopLine="9"/>
     153        <Filename Value="../UExceptionForm.pas"/>
     154        <Caret Line="89" Column="1" TopLine="83"/>
    148155      </Position7>
    149156      <Position8>
    150         <Filename Value="../UExceptionForm.pas"/>
    151         <Caret Line="88" Column="1" TopLine="83"/>
     157        <Filename Value="UMainForm.pas"/>
     158        <Caret Line="19" Column="65" TopLine="9"/>
    152159      </Position8>
    153160      <Position9>
    154         <Filename Value="../UExceptionForm.pas"/>
    155         <Caret Line="89" Column="1" TopLine="83"/>
     161        <Filename Value="UMainForm.pas"/>
     162        <Caret Line="21" Column="65" TopLine="9"/>
    156163      </Position9>
    157164      <Position10>
    158165        <Filename Value="UMainForm.pas"/>
    159         <Caret Line="19" Column="65" TopLine="9"/>
     166        <Caret Line="16" Column="33" TopLine="1"/>
    160167      </Position10>
    161168      <Position11>
    162169        <Filename Value="UMainForm.pas"/>
    163         <Caret Line="21" Column="65" TopLine="9"/>
     170        <Caret Line="57" Column="10" TopLine="33"/>
    164171      </Position11>
    165172      <Position12>
    166173        <Filename Value="UMainForm.pas"/>
    167         <Caret Line="16" Column="33" TopLine="1"/>
     174        <Caret Line="56" Column="30" TopLine="34"/>
    168175      </Position12>
    169176      <Position13>
    170177        <Filename Value="UMainForm.pas"/>
    171         <Caret Line="57" Column="10" TopLine="33"/>
     178        <Caret Line="54" Column="4" TopLine="34"/>
    172179      </Position13>
    173180      <Position14>
    174         <Filename Value="UMainForm.pas"/>
    175         <Caret Line="56" Column="30" TopLine="34"/>
     181        <Filename Value="Demo.lpr"/>
     182        <Caret Line="6" Column="16" TopLine="1"/>
    176183      </Position14>
    177184      <Position15>
    178         <Filename Value="UMainForm.pas"/>
    179         <Caret Line="54" Column="4" TopLine="34"/>
     185        <Filename Value="Demo.lpr"/>
     186        <Caret Line="8" Column="14" TopLine="1"/>
    180187      </Position15>
    181188      <Position16>
    182         <Filename Value="Demo.lpr"/>
    183         <Caret Line="6" Column="16" TopLine="1"/>
     189        <Filename Value="../UExceptionLogger.pas"/>
     190        <Caret Line="21" Column="43" TopLine="14"/>
    184191      </Position16>
    185192      <Position17>
    186         <Filename Value="Demo.lpr"/>
    187         <Caret Line="8" Column="14" TopLine="1"/>
     193        <Filename Value="UMainForm.pas"/>
     194        <Caret Line="47" Column="44" TopLine="35"/>
    188195      </Position17>
     196      <Position18>
     197        <Filename Value="UMainForm.pas"/>
     198        <Caret Line="48" Column="44" TopLine="36"/>
     199      </Position18>
     200      <Position19>
     201        <Filename Value="UMainForm.pas"/>
     202        <Caret Line="67" Column="1" TopLine="45"/>
     203      </Position19>
     204      <Position20>
     205        <Filename Value="UMainForm.pas"/>
     206        <Caret Line="24" Column="34" TopLine="1"/>
     207      </Position20>
     208      <Position21>
     209        <Filename Value="UMainForm.pas"/>
     210        <Caret Line="39" Column="1" TopLine="32"/>
     211      </Position21>
     212      <Position22>
     213        <Filename Value="UMainForm.pas"/>
     214        <Caret Line="38" Column="1" TopLine="31"/>
     215      </Position22>
    189216    </JumpHistory>
    190217  </ProjectOptions>
    191218  <CompilerOptions>
    192     <Version Value="10"/>
     219    <Version Value="11"/>
    193220    <Target>
    194221      <Filename Value="Demo"/>
     
    208235    <Linking>
    209236      <Debugging>
    210         <GenerateDebugInfo Value="True"/>
    211237        <DebugInfoType Value="dsStabs"/>
    212238      </Debugging>
  • ExceptionLogger/UExceptionLogger.pas

    r265 r297  
    1010
    1111type
     12  TThreadSynchronizeEvent = procedure (AObject: TObject; Method: TThreadMethod) of object;
    1213
    1314  { TExceptionLogger }
     
    1718    FMaxCallStackDepth: Integer;
    1819    FLogFileName: string;
     20    FOnThreadSynchronize: TThreadSynchronizeEvent;
     21    procedure ThreadSynchronize(AObject: TObject; Method: TThreadMethod);
    1922    function GetAppVersion: string;
    2023    procedure SetMaxCallStackDepth(const AValue: Integer);
     
    3740    property LogFileName: string read FLogFileName write FLogFileName;
    3841    property MaxCallStackDepth: Integer read FMaxCallStackDepth write SetMaxCallStackDepth;
     42    property OnThreadSynchronize: TThreadSynchronizeEvent read FOnThreadSynchronize
     43      write FOnThreadSynchronize;
    3944  end;
    4045
     
    6368  SProcedureMethod = 'Procedure/method';
    6469  SUnit = 'Unit';
     70  SExceptionHandlerCannotBeSynchronized = 'Exception handler cannot be synchronized with main thread.';
    6571
    6672implementation
     
    8490  Application.OnException := ExceptionHandler;
    8591  Application.Flags := Application.Flags - [AppNoExceptionMessages];
     92  OnThreadSynchronize := ThreadSynchronize;
    8693end;
    8794
     
    162169  LastException := E;
    163170  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;
    167176end;
    168177
     
    209218  FMaxCallStackDepth := AValue;
    210219  StackTrace.MaxDepth := AValue;
     220end;
     221
     222procedure TExceptionLogger.ThreadSynchronize(AObject: TObject;
     223  Method: TThreadMethod);
     224begin
     225  if AObject is TThread then TThread.Synchronize(TThread(AObject), Method)
     226    else raise Exception.Create(SExceptionHandlerCannotBeSynchronized);
    211227end;
    212228
  • ExceptionLogger/languages/UExceptionLogger.cs.po

    r295 r297  
    4343msgid "Class"
    4444msgstr "Třída"
     45
     46#: uexceptionlogger.sexceptionhandlercannotbesynchronized
     47msgid "Exception handler cannot be synchronized with main thread."
     48msgstr "Obsluha vyjímky nemůže být synchronizována s hlavním vláknem."
    4549
    4650#: uexceptionlogger.sexceptioninfo
  • ExceptionLogger/languages/UExceptionLogger.po

    r295 r297  
    3434msgctxt "uexceptionlogger.sexceptionclass"
    3535msgid "Class"
     36msgstr ""
     37
     38#: uexceptionlogger.sexceptionhandlercannotbesynchronized
     39msgid "Exception handler cannot be synchronized with main thread."
    3640msgstr ""
    3741
Note: See TracChangeset for help on using the changeset viewer.