Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 1440

Delphi debugging tip: keep an eye on a object field of an object that will go out of scope eventually

$
0
0

Every once in a while you want to have a Delphi Watch of a field inside an object (say an object of type TContext), except that the field has no value yet, but eventually will point to another object (say an object of type TUser).

However, the original object will go out of scope, so you need to employ a few tricks.

First of all, you get the address of that field:

@(Context().FCurrentUser) = $7EF6F624

Then you watch the content of that field:

TUser(PPointer($7EF6F624)^),r = nil

To get to this trick, you have to remember:

  1. The contents of address $7EF6F624 is pointer (at first nil) to a TUser.
  2. You get to the contents of the address $7EF6F624 by using PPointer($7EF6F624)^.
  3. Then you cast it to the object you want with the TUser(...) cast.

–jeroen


Viewing all articles
Browse latest Browse all 1440

Trending Articles