Jump to content
Tostis

Inspect variables during debug

Recommended Posts

I can't understand how I can inspect variable content when debugger is stopped due to breakpoint.

 

Local variable window shows testvar but I cannot see the content of FSampleField and FInnerField.FOtherField.

Am I doing something wrong?

 

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;



type IInner = interface
  procedure setOtherField(b: integer);
end;

type TInner = class(TInterfacedObject, IInner)
  private var FOtherField: integer;
  procedure setOtherField(b: integer);
end;


type ITest = interface
  procedure setSampleField(a: string);
  procedure setInnerField(b: IInner);
end;

type TTest = class(TInterfacedObject, ITest)
  private var FSampleField: string;
  private var FInnerField: IInner;
  procedure setSampleField(a: string);
  procedure setInnerField(b: IInner);
end;


implementation

{$R *.dfm}

procedure TTest.setSampleField(a: string);
begin
  FSampleField:= a;
end;

procedure TTest.setInnerField(b: IInner);
begin
  FInnerField:= b;
end;

procedure TInner.setOtherField(b: Integer);
begin
  FOtherField:= b;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  var testInnerVar: IInner:= TInner.Create();
  testInnerVar.setOtherField(55);
  var testvar: ITest:= TTest.Create();
  testvar.setSampleField('avalue');
  testvar.setInnerField(testInnerVar);
end;

end.

 

 

 

 

385271806_DelphidebugCapture.thumb.PNG.c5c103e8f0c7ccfa1736974c9150f676.PNG

Share this post


Link to post

That's because testvar is of type ITest and not TTest that contains the member fields.

Share this post


Link to post

So if I want to debug propertly I should give up on using interface reference counting and destroy all objects by myself?

Share this post


Link to post
5 minutes ago, Tostis said:

So if I want to debug propertly I should give up on using interface reference counting and destroy all objects by myself?

Welcome to the house of interface pain.

Hint: you can evaluate intf's methods

Share this post


Link to post

Evaluating expression into watch list is not so useful. It isn't feasible to watch collections of intefaces containing interfaces ecc...

Can you give some best pratices for debugging code?

Should I avoid interfaces?

Are there plugin for RAD that can help me?

 

2146508382_DelphidebugCapture2.thumb.PNG.1b322f995fb054cc41b0ceb01f9326d4.PNG

Share this post


Link to post
54 minutes ago, Tostis said:

I should give up on using interface reference counting and destroy all objects by myself?

Are you trying to say, you are using interfaces only to avoid being responsible for destroying your object instances?

Share this post


Link to post
25 minutes ago, Tostis said:

Evaluating expression into watch list is not so useful. It isn't feasible to watch collections of intefaces containing interfaces ecc...

Can you give some best pratices for debugging code?

Should I avoid interfaces?

Are there plugin for RAD that can help me?

You can write your own debugger visualizer

Share this post


Link to post
17 minutes ago, Uwe Raabe said:

Are you trying to say, you are using interfaces only to avoid being responsible for destroying your object instances?

I'm using interfaces because I have various implementations of the same class, too.

Share this post


Link to post
16 minutes ago, Fr0sT.Brutal said:

You can write your own debugger visualizer

I'll evaluate how does it take before starting to develop my own debugger.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×