某对象的属性是一个子对象,现已取到类名和对象名
bClass := GetObjectPropClass((self as aClass),Tempstr);类名
属性名及属性信息如下方式获取
TempStr := Proplist[j]^.Name;
Propinfo := GetPropinfo(classtypeinfo,TempStr);
请问大虾如何获取到该子对象的对象实例附:以下TKclass段处理有问题,请问哪位大虾可以指教??var //保存字段的名字
aclass,bClass: TClass;
TempStr: shortString;
ClassTypeInfo: PTypeInfo;
ClassTypeData: PTypeData;
PropList: PPropList;
J:Integer;
TK: TTypeKind;
PropInfo: PPropInfo;
childObject,myObject: tobject;
tmpRoot : IWWXMLNode;
begin
inherited;
aClass := self.ClassType; //Self.StrucName);
if aClass=nil then exit; //类为空的话退出
ClassTypeInfo := aclass.ClassInfo;
ClassTypeData := GetTypeData(ClassTypeInfo);
Proplist := nil;
try
GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
getpropinfos(aclass.classinfo, proplist);
for J := 0 to ClassTypeData.PropCount - 1 do
begin
Tk := PropList[J]^.PropType^.Kind;
if Tk = tkMethod then //方法不必映射
continue;
TempStr := Proplist[j]^.Name;
Propinfo := GetPropinfo(classtypeinfo,TempStr);
case tk of
tklstring, tkString, tkWString:
begin
SetStrProp((self as aclass), PropInfo, GetFieldValue(XMLNode,TempStr)); {}
end;
tkinteger:
begin
SetOrdProp((self as aClass),PropInfo,Strtoint(GetFieldValue(XMLNode,TempStr)));
end;
tkInt64: // add int64 2005-06-01
begin
SetInt64Prop((self as aClass),PropInfo,Strtoint64(GetFieldValue(XMLNode,TempStr)));
end;
tkFloat:
begin
SetFloatProp((self as aClass),PropInfo,StrtoFloat(GetFieldValue(XMLNode,TempStr)));
end;
tkClass:
begin
childobject := TObject(PInteger(GetOrdProp(self as aclass,PropList[j]^.Name))); bClass := GetObjectPropClass((self as aClass),Tempstr);
tmpRoot := self.GetNode(bClass.ClassName,0); //ChildObject := TWalkwatchXml.Create;
try
SetObjectProp(ChildObject, PropInfo, GetObjectProp((self as aClass), PropInfo));
//ChildObject := GetObjectProp((self as aClass),PropInfo,bClass);
//SetObjectProp((Self as aClass),PropInfo,ChildObject);
if ChildObject is TWalkwatchXml then
begin
TWalkWAtchXml(ChildObject).Parse(tmpRoot);
Showmessage(tmpRoot.xml);
end;
finally
ChildObject.Free;
end;
end;
tkEnumeration:
begin
SetEnumProp((self as aClass),PropInfo,GetFieldValue(XMLNode,TempStr));
end;
tkSet:
begin
SetOrdProp((self as aClass),PropInfo,Strtoint(GetFieldValue(XMLNode,TempStr)));
end;
tkUnknown,tkVariant:
begin
SetVariantProp((self as aClass),PropInfo,GetFieldValue(XMLNode,TempStr));
end;
tkChar,tkWChar:
begin
SetOrdProp((self as aClass),PropInfo,Strtoint(GetFieldValue(XMLNode,TempStr)));
end;
//tkInterface,tkMethod,tkArray, tkRecord,tkDynArray
else
raise EPropertyConvertError.CreateResFmt(@SInvalidPropertyType,[PropInfo.PropType^^.Name]);
end;
end; //end for
finally
FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
end;
end;
bClass := GetObjectPropClass((self as aClass),Tempstr);类名
属性名及属性信息如下方式获取
TempStr := Proplist[j]^.Name;
Propinfo := GetPropinfo(classtypeinfo,TempStr);
请问大虾如何获取到该子对象的对象实例附:以下TKclass段处理有问题,请问哪位大虾可以指教??var //保存字段的名字
aclass,bClass: TClass;
TempStr: shortString;
ClassTypeInfo: PTypeInfo;
ClassTypeData: PTypeData;
PropList: PPropList;
J:Integer;
TK: TTypeKind;
PropInfo: PPropInfo;
childObject,myObject: tobject;
tmpRoot : IWWXMLNode;
begin
inherited;
aClass := self.ClassType; //Self.StrucName);
if aClass=nil then exit; //类为空的话退出
ClassTypeInfo := aclass.ClassInfo;
ClassTypeData := GetTypeData(ClassTypeInfo);
Proplist := nil;
try
GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
getpropinfos(aclass.classinfo, proplist);
for J := 0 to ClassTypeData.PropCount - 1 do
begin
Tk := PropList[J]^.PropType^.Kind;
if Tk = tkMethod then //方法不必映射
continue;
TempStr := Proplist[j]^.Name;
Propinfo := GetPropinfo(classtypeinfo,TempStr);
case tk of
tklstring, tkString, tkWString:
begin
SetStrProp((self as aclass), PropInfo, GetFieldValue(XMLNode,TempStr)); {}
end;
tkinteger:
begin
SetOrdProp((self as aClass),PropInfo,Strtoint(GetFieldValue(XMLNode,TempStr)));
end;
tkInt64: // add int64 2005-06-01
begin
SetInt64Prop((self as aClass),PropInfo,Strtoint64(GetFieldValue(XMLNode,TempStr)));
end;
tkFloat:
begin
SetFloatProp((self as aClass),PropInfo,StrtoFloat(GetFieldValue(XMLNode,TempStr)));
end;
tkClass:
begin
childobject := TObject(PInteger(GetOrdProp(self as aclass,PropList[j]^.Name))); bClass := GetObjectPropClass((self as aClass),Tempstr);
tmpRoot := self.GetNode(bClass.ClassName,0); //ChildObject := TWalkwatchXml.Create;
try
SetObjectProp(ChildObject, PropInfo, GetObjectProp((self as aClass), PropInfo));
//ChildObject := GetObjectProp((self as aClass),PropInfo,bClass);
//SetObjectProp((Self as aClass),PropInfo,ChildObject);
if ChildObject is TWalkwatchXml then
begin
TWalkWAtchXml(ChildObject).Parse(tmpRoot);
Showmessage(tmpRoot.xml);
end;
finally
ChildObject.Free;
end;
end;
tkEnumeration:
begin
SetEnumProp((self as aClass),PropInfo,GetFieldValue(XMLNode,TempStr));
end;
tkSet:
begin
SetOrdProp((self as aClass),PropInfo,Strtoint(GetFieldValue(XMLNode,TempStr)));
end;
tkUnknown,tkVariant:
begin
SetVariantProp((self as aClass),PropInfo,GetFieldValue(XMLNode,TempStr));
end;
tkChar,tkWChar:
begin
SetOrdProp((self as aClass),PropInfo,Strtoint(GetFieldValue(XMLNode,TempStr)));
end;
//tkInterface,tkMethod,tkArray, tkRecord,tkDynArray
else
raise EPropertyConvertError.CreateResFmt(@SInvalidPropertyType,[PropInfo.PropType^^.Name]);
end;
end; //end for
finally
FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货