views:

225

answers:

3

I've given up on the Delphi 7 debugger and am pretty much relying on outputdebugstrings. Is there a standard function I can call to get the contents of an object as a string like the debugger would if I set a breakpoint?

A: 

if delphi 7 is the .NET version, then you could do (some of) that with reflection. (not easy, but not terribly hard). if it's the normal, compiled thing, then it's a hard problem and the debugger is you best bet, apart from specialized printing functions/methods.

Baczek
The only .Net version of Delphi 7 was the command-line-only "preview compiler," which is never what anyone means when talking about "Delphi 7."
Rob Kennedy
+4  A: 

Not exactly what your looking for, but you can use RTTI to get access to the values of various published properties. The magical routines are in the TypInfo unit. The ones you are probably most interested in are GetPropList which will return a list of the objects properties, and GetPropValue which will allow you to get the values of the properties.

procedure TForm1.DumpObject( YourObjectInstance : tObject );
var
  PropList : PPropList;
  PropCnt  : integer;
  iX : integer;
  vValue : Variant;
  sValue : String;
begin
  PropCnt := GetPropList(YourObjectInstance,PropList);
  for iX := 0 to PropCnt-1 do
    begin
      vValue := GetPropValue(YourObjectInstance,PropList[ix].Name,True);
      sValue := VarToStr( vValue );
      Memo1.Lines.Add(PropList[ix].Name+' = '+sValue );
    end;
end;

for example, run this with DumpObject(Self) on the button click of the main form and it will dump all of the properties of the current form into the memo. This is only published properties, and requires that the main class either decends from TPersistant, OR was compiled with {$M+} turned on before the object.

Rumor has it that a "reflector" like ability will be available in a future version of Delphi (possibly 2010).

skamradt
I was at the Delphi Live conference session where the CodeGear people talked about the "rumored" ability. They said explicitly that will be a lot more RTTI, but nowhere near enough information to decompile an app or reverse-engineer the structure of your objects the way .NET Reflector does.
Mason Wheeler
+2  A: 

Consider something like Codesite which is a much more complete tracing solution. It allows you to output much more complex info, and then search, print, and analyse the data. But for your purposes, you can simply send an object to it with Codesite.Send('Before', self); and you get all the RTTI available properties in the log. Do an "After" one too, and then you can compare the two in the Codesite output just by selecting both. It's saved me many times.

mj2008