Is there a function like PHP vardump in Delphi?

I have abandoned the Delphi 7 debugger and rely heavily on outputdebugstrings. Is there a standard function that I can call to get the contents of an object as a string, such as a debugger, if I set a breakpoint?

+3
source share
3 answers

Not quite what you are looking for, but you can use RTTI to access the values โ€‹โ€‹of various published properties. The magic routines are in the TypInfo module. The ones you are probably most interested in are GetPropList, which will return a list of object properties and GetPropValue, which will allow you to get property values.

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;

, DumpObject (Self) . , TPersistent, {$ M +} .

, Delphi (, 2010) "", .

+4

Codesite, . , , . Codesite.Send('Before', self); RTTI . "After", Codesite, . .

+3

delphi 7 .NET, ( ), . (, ). , , , , /.

-2

Source: https://habr.com/ru/post/1709339/


All Articles