gpt4 book ai didi

delphi - 如何禁用泛型类型的调试信息

转载 作者:行者123 更新时间:2023-12-03 18:32:35 25 4
gpt4 key购买 nike

我有以下代码(简化):

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils,
Unit1 in 'Unit1.pas';

var
f: TFoo<Integer>;
begin
f := TFoo<Integer>.Create;
f.Baz;
Readln;
end.


unit Unit1;

{$D-}

interface

type
TFoo = class
public
procedure Bar(const s: string);
end;

TFoo<T> = class(TFoo)
public
procedure Baz;
end;

implementation

uses
TypInfo;

{ TFoo }

procedure TFoo.Bar(const s: string);
begin
Writeln(s);
end;

{ TFoo<T> }

procedure TFoo<T>.Baz;
begin
Bar(PTypeInfo(TypeInfo(T)).Name);
end;

end.

现在进入 f.Baz我总是在 Unit1.TFoo<T>.Baz 结束虽然我明确禁用了该单元的调试信息,但我无法进入 TFoo.Bar这是正确的。我认为这是因为泛型在内部是如何实现的(如模板)以及 TFoo<Integer>在我的 Project1 中定义.当我添加以下单元时,我无法进入 Baz不再:
unit Unit2;

{$D-}

interface

uses
Unit1;

type
TIntegerFoo = TFoo<Integer>;

implementation

end.

现在有什么方法可以完全删除泛型类型的调试信息,以便我可以在任何地方(调试信息打开的地方)专门化该类型,但避免进入泛型类型的方法?我想这一定是可能的,因为我无法跟踪任何信息 Generics.Collections.TList<T>不启用“使用调试 .dcus”选项的方法。

最佳答案

经过一些实验,似乎决定是否启用调试信息是由引用类型的特定实例的第一个单元控制的。

因此,如果编译器第一次遇到类型的实例化,调试信息被启用,那么特定类型将使用调试信息编译。另一方面,如果第一个实例在没有调试信息的单元中,那么将没有调试信息。

在您的示例中,TFoo<Integer> 的第一个(也是唯一一个)实例化位于启用了调试信息的 .dpr 文件中。所以,如果你移动 {$D-}进入 .dpr 文件,并设置 {$D+}Unit1 , 你会发现 TFoo<Integer>.Baz 没有调试信息.

我说第一个实例化的原因是可能有很多不同的单元实例化TFoo<Integer> .编译器遇到的第一个是确定实例化类型是否使用调试信息编译的。

可以安排TFoo<Integer>有调试信息,但对于 TFoo<string>没有调试信息。

I guess it must be possible since I cannot step info any Generics.Collections.TList method without enabling the "use debug .dcus" option.



我无法解释。根据我的假设,如果第一次实例化类时调试信息打开,调试信息应该可用于 TList 实例化。

我怀疑调试器中可能存在错误。例如,我编写了以下程序:
{$APPTYPE CONSOLE}
uses
Generics.Collections;
begin
TList<Integer>.Create.Add(6);
end.

当我在启用调试 DCU 关闭的情况下运行它时,我确实可以进入 Generics.Collections .但我完全走错了地方。它降落在 TList<T>.Pack .

所以,很抱歉,我无法提供更多见解,但是您问题的这一方面让我感到困惑。

关于delphi - 如何禁用泛型类型的调试信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com