Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging problems with ‘WITH’ statement in Delphi 2006 [duplicate]

Tags:

delphi

Possible Duplicate:
What's wrong with Delphi's “with”

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;

EDIT:

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

like image 690
Charles Faiga Avatar asked Nov 23 '08 09:11

Charles Faiga


1 Answers

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.

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.

like image 50
Cruachan Avatar answered Sep 22 '22 20:09

Cruachan