Search code examples
delphidelphi-xe2

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;

Solution

  • 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.