当前位置: 首页 > 工具软件 > Vardump > 使用案例 >

delphi有php最新版本,Delphi中是否有类似php的vardump的函数?

范云
2023-12-01

不完全是您要查找的内容,但可以使用rtti访问各种已发布属性的值。神奇的程序在typinfo单元中。您可能最感兴趣的是getPropList,它将返回对象属性列表,以及getPropValue,它将允许您获取属性的值。

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)在主窗体的按钮单击上运行它,它将当前窗体的所有属性转储到备忘录中。这只是已发布的属性,要求主类要么从tppersistent继承,要么在对象之前打开$m+进行编译。

有传言说,类似“反射镜”的能力将在未来的德尔福版本(可能2010年)。

 类似资料: