Craig Stevensson
Craig Stevensson

Reputation: 1336

How to visualize the value of a pointer while debugging in Delphi?

So, I have a variable buffPtr: TPointer It has a size of 16 and contains a series of numbers, mostly starting with 0, say something like 013854351387365. I'm sure it contains values, because the application does what it does fine.

I want to see this value while I'm debugging.

If I add "PAnsiChar(buffPtr)^" to the watches I only see the first byte.

Upvotes: 7

Views: 3732

Answers (3)

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43033

Just type in the watch expression PAnsiChar(buffPtr)^,16 or PByte(buffPtr)^,16 if you want the ordinal/byte values.

The trick here is to add the number of pattern repeat after a comma, like ,16.

It is IMHO more convenient than changing the Watch Properties, and it works with the F7 evaluation command of the IDE.

Upvotes: 11

Jeroen Wiert Pluimers
Jeroen Wiert Pluimers

Reputation: 24483

Did you set the watch do dump a region of memory? For some structures that helps.

If you can recompile your application, then define this:

type
  T16Values = array[0..15] of Byte;
  P16Values = ^T16Values;

Then cast your pointer into a P16Values, and view that.

If it is another data type than Byte, change the above code accordingly.

Upvotes: 3

Craig Stevensson
Craig Stevensson

Reputation: 1336

I added a watch to PAnsiChar(buffPtr)^

with the Watch Properties as

Repeat Count = 16 Decimal

enter image description here

Upvotes: 9

Related Questions