调试时如何检查非泛型TObjectList的内容?

SOU*_*ser 2 delphi generics debugging tobjectlist inspector

摘要:
1.调试时手动进行类型转换,LachlanG和Ken指出.
2.利用自Delphi 2010以来引入的Debugger Visualizers概念
.3.切换到泛型对应物.

=========================================

以下面的代码为例:

如果断点分别设置在结束时TestRegular和结束时TestGenerics,可以通过调试检查器查看通用列表的项目(甚至是项目的内容),但没有任何意义(甚至不是计数)当一个人将鼠标悬停在tmp变量上时,常规的ashjectlist .我想知道是否有一些方法可以实现常规tobjectlist的类似调试时间功能?

    unit Unit2;

    interface

    uses
      Contnrs, Generics.Collections,
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;

    type
      TMyItem = class;
      TMyItemList = class;
      TForm2 = class;

      TMyItem = class
      private
        fname: string;
      public
        property name: string read fname;
        constructor Create(aName: string);
      end;

      TMyItemList = class(TObjectList)
      protected
        procedure SetObject (Index: Integer; Item: TMyItem);
        function GetObject (Index: Integer): TMyItem;
      public
        function Add (Obj: TMyItem): Integer;
        procedure Insert (Index: Integer; Obj: TMyItem);
        property Objects [Index: Integer]: TMyItem
          read GetObject write SetObject; default;
      end;

      TForm2 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure TestRegular;
        procedure TestGenerics;
      public
        { Public declarations }
      end;

    var
      Form2: TForm2;

    implementation

    {$R *.dfm}

    { TMyItem }

    constructor TMyItem.Create(aName: string);
    begin
      fname := aName;
    end;

    { TMyItemList }

    function TMyItemList.Add(Obj: TMyItem): Integer;
    begin
      Result := inherited Add (Obj);
    end;

    procedure TMyItemList.SetObject(Index: Integer; Item: TMyItem);
    begin
      inherited SetItem (Index, Item);
    end;

    function TMyItemList.GetObject(Index: Integer): TMyItem;
    begin
      Result := inherited GetItem (Index) as TMyItem;
    end;

    procedure TMyItemList.Insert(Index: Integer; Obj: TMyItem);
    begin
      inherited Insert(Index, Obj);
    end;

    {TForm2}

    procedure TForm2.FormCreate(Sender: TObject);
    begin
      TestGenerics;
      TestRegular;
    end;

    procedure TForm2.TestRegular;
    var
     tmp: TMyItemList;
    begin
     tmp := TMyItemList.Create;
     tmp.Add(TMyItem.Create('1'));
     tmp.Add(TMyItem.Create('2'));
     tmp.Free;
    end;

    procedure TForm2.TestGenerics;
    var
     tmp: TObjectList<TMyItem>;
    begin
     tmp := TObjectList<TMyItem>.Create;
     tmp.Add(TMyItem.Create('1'));
     tmp.Add(TMyItem.Create('2'));
     tmp.Free;
    end;

    end.
Run Code Online (Sandbox Code Playgroud)

Lac*_*anG 6

我不认为你能够改进鼠标光标悬停提示中出现的内容.

但是,您可以在源代码中使用调试窗口内的类型转换.

例如,您可以从评估窗口(Ctrl F7)中将tmp变量类型转换为TObjectList(tmp),或者在类型转换变量上创建监视(Ctrl F5).