Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a breakpoint whenever an object field value changes?

As an example, given the code extract below, I would like to define a breakpoint that triggers whenever the object field value changes and optionally, breaks on a condition (False or True in this case).

type
  TForm1 = class(TForm)
    EnableButton: TButton;
    DisableButton: TButton;
    procedure EnableButtonClick(Sender: TObject);
    procedure DisableButtonClick(Sender: TObject);
  private
    FValue: Boolean; // <== Would like to define a breakpoint here whenever FValue changes.
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DisableButtonClick(Sender: TObject);
begin
  FValue := False;
end;

procedure TForm1.EnableButtonClick(Sender: TObject);
begin
  FValue := True;
end;
like image 539
Jack G. Avatar asked Jan 04 '13 20:01

Jack G.


People also ask

How do you do a conditional breakpoint?

To set a conditional breakpointOn the Home tab, in the Breakpoints group, choose Set/Clear Condition. In the Debugger Breakpoint Condition window, enter a condition. On the Home tab, in the Breakpoints group, choose List. In the Debugger Breakpoint List window, enter a condition in the Condition column.

How do you break a variable change in Visual Studio?

In fact, you can now right-click a variable name in the Local window and then select Break When Value Changes (see Figure 58). Visual Studio will automatically track your variable, and it will break the application execution when the variable value changes.

How do I add a conditional breakpoint in Visual Studio?

Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.

How do I apply a conditional breakpoint in eclipse?

First, set a breakpoint at a given location. Then, use the context menu on the breakpoint in the left editor margin or in the Breakpoints view in the Debug perspective, and select the breakpoint&#146;s properties. In the dialog box, check Enable Condition, and enter an arbitrary Java condition, such as list.


2 Answers

Run the application under the debugger,

select 'Run' from the IDE menu then select 'Add Breakpoint' at the very bottom, then 'Data Breakpoint...'.

enter 'Form1.FValue' as input to the 'Adress:' field. You can also set your condition in the same dialog.

like image 114
Sertac Akyuz Avatar answered Oct 09 '22 04:10

Sertac Akyuz


Some additional information thanks to Sertac answer and comment from David.

One can define a breakpoint based on changes in an array item with a condition.

In this case the data breakpoint is defined as follow:

Form1.FBooleans[0] = True

Code extract:

type
  TBooleanArray = array of Boolean;

  TForm1 = class(TForm)
    EnableButton: TButton;
    DisableButton: TButton;
    procedure EnableButtonClick(Sender: TObject);
    procedure DisableButtonClick(Sender: TObject);
  private
    FBooleans: TBooleanArray; // Breakpoint defined here with the condition
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

constructor TForm1.Create(AOwner: TComponent);
var
  AIndex: Integer;
begin
  inherited;
  SetLength(FBooleans, 3);
  for AIndex := 0 to Length(FBooleans) - 1 do
  begin
    FBooleans[AIndex] := (AIndex mod 2) = 1;
  end;
end;

procedure TForm1.DisableButtonClick(Sender: TObject);
begin
  FBooleans[0] := False;
end;

procedure TForm1.EnableButtonClick(Sender: TObject);
begin
  FBooleans[0] := True; // Beakpoint stops here on condition.
end;
like image 42
Jack G. Avatar answered Oct 09 '22 04:10

Jack G.