Procedure TXMLNode.Serialize(C: TObject; SortProps: Boolean = False);
Var i, i2, i3, i4: Integer;
F: Extended;
List: PPropList;
Node: TXMLNode;
Begin
i2 := GetPropList(C.ClassInfo, List);
If i2 > 0
Then
Try
If SortProps
Then SortPropList(List, i2);
For i := 0
to i2 - 1
do
Case List[i].PropType^.Kind
of
tkUnknown: ;
tkInteger:
Begin
Node := AddNode(List[i].
Name);
i3 := GetOrdProp(C, List[i].
Name);
If List[i].PropType^.
Name = '
TColor'
Then Begin
i4 := 0;
While i4 <= High(XMLColorStrings)
do
If i3 = XMLColorStrings[i3].Value
Then Begin
Node.Data := XMLColorStrings[i3].
Name;
Break;
End;
If i4 > High(XMLColorStrings)
Then Continue;
End;
Node.Data := IntToStr(i3);
End;
tkInt64: AddNode(List[i].
Name).Data := IntToStr(GetInt64Prop(C, List[i].
Name));
tkEnumeration: AddNode(List[i].
Name).Data := GetEnumProp(C, List[i].
Name);
tkSet: AddNode(List[i].
Name).Data := GetSetProp(C, List[i].
Name, True);
tkFloat:
Begin
Node := AddNode(List[i].
Name);
F := GetFloatProp(C, List[i].
Name);
If List[i].PropType^.
Name = '
TDateTime'
Then Node.Data := DateToStr(F)
Else If List[i].PropType^.
Name = '
TDate'
Then Node.Data := TimeToStr(F)
Else If List[i].PropType^.
Name = '
TTime'
Then Node.Data := DateTimeToStr(F)
Else Node.Data := FloatToStr(F);
End;
tkChar, tkWChar:
Begin
Node := AddNode(List[i].
Name);
i3 := Word(GetOrdProp(C, List[i].
Name));
If (i3 > $32)
and (i3 < $128)
Then Node.Data := WideChar(i3)
Else Node.Data := '
#' + IntToStr(GetOrdProp(C, List[i].
Name));
End;
tkLString
{$IFNDEF UNICODE}, tkString
{$ENDIF}:
AddNode(List[i].
Name).Data := GetAnsiStrProp(C, List[i].
Name);
tkWString: AddNode(List[i].
Name).Data := GetWideStrProp(C, List[i].
Name);
tkUString
{$IFDEF UNICODE}, tkString
{$ENDIF}:
AddNode(List[i].
Name).Data := GetUnicodeStrProp(C, List[i].
Name);
//tkClass: ;
//tkMethod: ;
//tkVariant: ;
//tkRecord: ;
//tkInterface: ;
//tkArray: ;
//tkDynArray: ;
Else Raise EXMLException.Create('
invalid PropType');
End;
Finally
FreeMem(List);
End;
End;