diff --git a/Examples/DebugSender/UnitOutput.dfm b/Examples/DebugSender/UnitOutput.dfm index 335d1b321..d920a89e7 100644 --- a/Examples/DebugSender/UnitOutput.dfm +++ b/Examples/DebugSender/UnitOutput.dfm @@ -14,6 +14,7 @@ object FormSend: TFormSend KeyPreview = True OldCreateOrder = False Position = poScreenCenter + OnClick = FormClick OnCreate = FormCreate OnKeyDown = FormKeyDown PixelsPerInch = 96 diff --git a/Examples/DebugSender/UnitOutput.pas b/Examples/DebugSender/UnitOutput.pas index 70708b608..4e6c0ebb5 100644 --- a/Examples/DebugSender/UnitOutput.pas +++ b/Examples/DebugSender/UnitOutput.pas @@ -36,6 +36,8 @@ interface +{$I CnPack.inc} + uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, ActnList, UnitThread, Buttons, @@ -164,6 +166,7 @@ TFormSend = class(TForm) procedure btnEvaluateScreenClick(Sender: TObject); procedure btnFindComponentClick(Sender: TObject); procedure btnFindControlClick(Sender: TObject); + procedure FormClick(Sender: TObject); private { Private declarations } FTimeStamp: Boolean; @@ -656,4 +659,14 @@ procedure TFormSend.DebuggerFindControl(Sender: TObject; (Sender as TCnDebugger).LogMsg('On Find Control: ' + AControl.Name); end; +procedure TFormSend.FormClick(Sender: TObject); +begin +{$IFDEF SUPPORT_ENHANCED_RTTI} + if rgMethod.ItemIndex = 1 then + CnDebugger.TraceEnumType + else + CnDebugger.LogEnumType; +{$ENDIF} +end; + end. diff --git a/Source/Common/CnDebug.pas b/Source/Common/CnDebug.pas index c311e1d47..49233ebcd 100644 --- a/Source/Common/CnDebug.pas +++ b/Source/Common/CnDebug.pas @@ -117,10 +117,8 @@ interface uses SysUtils, Classes, Windows, TypInfo, Controls, Graphics, Registry, Messages, Forms - {$IFDEF USE_JCL} - ,JclDebug, JclHookExcept - {$ENDIF USE_JCL} - ; + {$IFDEF SUPPORT_ENHANCED_RTTI}, Rtti {$ENDIF} + {$IFDEF USE_JCL},JclDebug, JclHookExcept {$ENDIF USE_JCL}; const CnMaxTagLength = 8; // ²»¿É¸Ä±ä @@ -300,7 +298,9 @@ TCnDebugger = class(TObject) procedure SetUseAppend(const Value: Boolean); function GetMessageCount: Integer; function GetPostedMessageCount: Integer; - +{$IFDEF SUPPORT_ENHANCED_RTTI} + function GetEnumTypeStr: string; +{$ENDIF} procedure InternalFindComponent(AComponent: TComponent); procedure InternalFindControl(AControl: TControl); protected @@ -404,8 +404,10 @@ TCnDebugger = class(TObject) procedure LogRawString(const Value: string); procedure LogRawAnsiString(const Value: AnsiString); procedure LogRawWideString(const Value: WideString); - procedure LogStrings(Strings: TStrings; const AMsg: string = ''); +{$IFDEF SUPPORT_ENHANCED_RTTI} + procedure LogEnumType(const AMsg: string = ''); +{$ENDIF} procedure LogException(E: Exception; const AMsg: string = ''); procedure LogMemDump(AMem: Pointer; Size: Integer); procedure LogVirtualKey(AKey: Word); @@ -481,6 +483,9 @@ TCnDebugger = class(TObject) procedure TraceRawAnsiString(const Value: AnsiString); procedure TraceRawWideString(const Value: WideString); procedure TraceStrings(Strings: TStrings; const AMsg: string = ''); +{$IFDEF SUPPORT_ENHANCED_RTTI} + procedure TraceEnumType(const AMsg: string = ''); +{$ENDIF} procedure TraceException(E: Exception; const AMsg: string = ''); procedure TraceMemDump(AMem: Pointer; Size: Integer); procedure TraceVirtualKey(AKey: Word); @@ -1619,6 +1624,20 @@ procedure TCnDebugger.LogEnter(const AProcName, ATag: string); {$ENDIF} end; +{$IFDEF SUPPORT_ENHANCED_RTTI} + +procedure TCnDebugger.LogEnumType(const AMsg: string); +begin +{$IFDEF DEBUG} + if AMsg = '' then + LogMsg('EnumType: ' + GetEnumTypeStr) + else + LogFmt('%s %s', [AMsg, GetEnumTypeStr]); +{$ENDIF} +end; + +{$ENDIF} + procedure TCnDebugger.LogException(E: Exception; const AMsg: string); begin {$IFDEF DEBUG} @@ -2339,6 +2358,20 @@ procedure TCnDebugger.TraceEnter(const AProcName, ATag: string); {$ENDIF} end; +{$IFDEF SUPPORT_ENHANCED_RTTI} + +procedure TCnDebugger.TraceEnumType(const AMsg: string); +begin +{$IFDEF DEBUG} + if AMsg = '' then + TraceMsg('EnumType: ' + GetEnumTypeStr) + else + TraceFmt('%s %s', [AMsg, GetEnumTypeStr]); +{$ENDIF} +end; + +{$ENDIF} + procedure TCnDebugger.TraceException(E: Exception; const AMsg: string); begin if not Assigned(E) then @@ -3511,6 +3544,33 @@ function TCnDebugger.FormatConstArray(Args: array of const): string; end; end; +{$IFDEF SUPPORT_ENHANCED_RTTI} + +function TCnDebugger.GetEnumTypeStr: string; +var + Rtx: TRttiContext; + Rt: TRttiType; + Rot: TRttiOrdinalType; + I: Integer; +begin + Result := ''; + Rt := Rtx.GetType(TypeInfo(T)); + if Rt.IsOrdinal then + begin + Rot := Rt.AsOrdinal; + for I := Rot.MinValue to Rot.MaxValue do + begin + if Result = '' then + Result := GetEnumName(TypeInfo(T), I) + else + Result := Result + ', ' + GetEnumName(TypeInfo(T), I); + end; + Result := '(' + Result + ')'; + end; +end; + +{$ENDIF} + procedure TCnDebugger.LogClass(const AClass: TClass; const AMsg: string); begin {$IFDEF DEBUG}