在Delphi 2006中使用“ WITH”语句调试问题 [英] Debugging problems with ‘WITH’ statement in Delphi 2006

查看:33
本文介绍了在Delphi 2006中使用“ WITH”语句调试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Delphi的< with”

怎么了?



在BDS 2006
中使用'WITH'语句的调试代码有问题调试器将不会在类或记录中显示变量的值。
我是在做错什么还是BDS 2006有错误?

I am have a problem debugging code that uses a ‘WITH’ statement in BDS 2006 The debugger will not show the values of the variables with in a class or record. Am I doing something wrong or does BDS 2006 have a bug ?

type
  TNumber = class
      Num: Integer;
  end;

implementation

{$R *.dfm}

var
   MyNumber: TNumber;

procedure TForm2.FormCreate(Sender: TObject);
begin
   MyNumber := TNumber.Create;
   MyNumber.Num := 10;   /// MyNumber.Num Can be seen with debugger
   with  MyNumber do
   begin
     Num := Num +1 ;           /// Num is not seen by the  debugger
     MyNumber.Num := Num +1 ;  /// MyNumber.Num is seen but Num is not seen by the  debugger
   end;
end;

编辑:

肯定可以使用变量
的全名,但是如果您具有一个以上级别的复杂结构,事情就会变得很混乱

Sure one can use the full name of the variable But things become very messy if you have a complex structure with more than one level

推荐答案

使用被许多语言功能所考虑,它们属于只是因为拥有它并不意味着必须使用它类别。在很多情况下,我会给它留个房间-我发现一两种情况下,当使用极其复杂的多层结构而不使用编译器时,必须使用它完全没有您的期望,并且包含起来也更容易,但是在Delphi的10年编码中,我认为这些都可以用一只手指望。

With is considered by many one of those language features that falls into the "just because you have it doesn't mean you have to use it" category. There are very few occasions where I'd give it house-room - I've found one or two cases where it's use is essential when using extremely complex multi-level structures where the compiler doesn't do quite as you'd expect without it and it is easier to include, but in 10 years of coding Delphi I think these could be counted on the fingers of one hand.

它确实确实在示例中被大量使用,因为代码看起来确实更干净,但是实际上在查看代码时弄清楚变量是简单的还是结构的一部分对维护产生了影响。写作或一段时间没有使用会轻易地超过它。在我使用过的每个Delphi版本上,调试器的已知问题都非常棘手。

It does tend to get used rather a lot in examples as the code certainly looks cleaner, but in practice the maintenance impact of figuring out if a variable is simple or part of a structure when reviewing code you didn't write or haven't used for a period easily outweighs that. The known issues with the debugger on every version of Delphi I've ever used is the clincher.

这篇关于在Delphi 2006中使用“ WITH”语句调试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆