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

删除回忆录丶 提交于 2019-12-08 14:46:58

问题


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;

回答1:


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.




回答2:


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;


来源:https://stackoverflow.com/questions/14164631/how-to-define-a-breakpoint-whenever-an-object-field-value-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!