diff --git a/Forms/MainFrm.dfm b/Forms/MainFrm.dfm index a1e1733..d5e4a09 100644 Binary files a/Forms/MainFrm.dfm and b/Forms/MainFrm.dfm differ diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas index 3f3c52c..723d0b3 100644 --- a/Units/DelphiXMLDataBindingGenerator.pas +++ b/Units/DelphiXMLDataBindingGenerator.pas @@ -289,7 +289,14 @@ var begin case AProperty.PropertyType of ptSimple: - Result := TranslateDataType(TXMLDataBindingSimpleProperty(AProperty).DataType); + if Assigned(AProperty.Collection) then + begin + if AInterfaceName then + Result := ItemInterface + else + Result := ItemClass; + end else + Result := TranslateDataType(TXMLDataBindingSimpleProperty(AProperty).DataType); ptItem: begin item := TXMLDataBindingItemProperty(AProperty).Item; @@ -785,30 +792,33 @@ begin begin propertyItem := AItem.Properties[propertyIndex]; + if (not AItem.IsCollection) and Assigned(propertyItem.Collection) then + begin + WritePrototype; + + { Inline collection } + if ASection = dxsImplementation then + begin + if propertyItem.PropertyType = ptItem then + AStream.WriteLnNamedFmt(' RegisterChildNode(''%:s'', %:s);', + ['ItemSourceName', propertyItem.Name, + 'ItemClass', GetDataTypeName(propertyItem, False)]); + + AStream.WriteLnNamedFmt(' %:s := CreateCollection(%:s, %:s, ''%:s'') as %:s;', + ['FieldName', PrefixField + propertyItem.TranslatedName, + 'CollectionClass', PrefixClass + propertyItem.Collection.TranslatedName, + 'CollectionInterface', PrefixInterface + propertyItem.Collection.TranslatedName, + 'ItemInterface', GetDataTypeName(propertyItem, True), + 'ItemSourceName', propertyItem.Name]); + end; + end; + if propertyItem.PropertyType = ptItem then begin itemProperty := TXMLDataBindingItemProperty(propertyItem); - if (not AItem.IsCollection) and Assigned(propertyItem.Collection) then - begin - WritePrototype; - - { Inline collection } - if ASection = dxsImplementation then - begin - AStream.WriteLnNamedFmt(' RegisterChildNode(''%:s'', %:s);', - ['ItemSourceName', propertyItem.Name, - 'ItemClass', PrefixClass + itemProperty.Item.TranslatedName]); - - AStream.WriteLnNamedFmt(' %:s := CreateCollection(%:s, %:s, ''%:s'') as %:s;', - ['FieldName', PrefixField + propertyItem.TranslatedName, - 'CollectionClass', PrefixClass + propertyItem.Collection.TranslatedName, - 'CollectionInterface', PrefixInterface + propertyItem.Collection.TranslatedName, - 'ItemInterface', PrefixInterface + itemProperty.Item.TranslatedName, - 'ItemSourceName', propertyItem.Name]); - end; - end else if ((not AItem.IsCollection) or - (propertyItem <> AItem.CollectionItem)) then + if (not AItem.IsCollection) or + (propertyItem <> AItem.CollectionItem) then begin { Item property } if Assigned(itemProperty.Item) and @@ -945,8 +955,8 @@ begin ptSimple: begin dataTypeName := TranslateDataType(TXMLDataBindingSimpleProperty(AItem.CollectionItem).DataType); - dataClassName := 'TXMLNode'; - dataIntfName := 'IXMLNode'; + dataClassName := ItemClass; + dataIntfName := ItemInterface; end; ptItem: begin @@ -1215,9 +1225,11 @@ begin begin WriteNewLine; - // #ToDo1 (MvR) 21-4-2008: optional attributes! if writeOptional then - sourceCode.Add(PropertyImplMethodGetOptional); + if AProperty.IsAttribute then + sourceCode.Add(PropertyImplMethodGetOptionalAttr) + else + sourceCode.Add(PropertyImplMethodGetOptional); if writeNil then sourceCode.Add(PropertyImplMethodGetNil); @@ -1229,10 +1241,16 @@ begin case AProperty.PropertyType of ptSimple: - sourceCode.Add(XMLToNativeDataType('Result', - '%:s', - TXMLDataBindingSimpleProperty(AProperty).DataType, - GetDelphiNodeType(AProperty))); + if Assigned(AProperty.Collection) then + begin + sourceCode.Add('begin'); + sourceCode.Add(' Result := %:s;'); + sourceCode.Add('end;'); + end else + sourceCode.Add(XMLToNativeDataType('Result', + '%:s', + TXMLDataBindingSimpleProperty(AProperty).DataType, + GetDelphiNodeType(AProperty))); ptItem: begin diff --git a/Units/DelphiXMLDataBindingResources.pas b/Units/DelphiXMLDataBindingResources.pas index 449ba86..8a69e2f 100644 --- a/Units/DelphiXMLDataBindingResources.pas +++ b/Units/DelphiXMLDataBindingResources.pas @@ -92,11 +92,18 @@ const 'end;' + CrLf + '' + CrLf; + PropertyImplMethodGetOptionalAttr = 'function TXML%:s.GetHas%:s: Boolean;' + CrLf + + 'begin' + CrLf + + ' Result := Assigned(AttributeNodes.FindNode(''%:s''));' + CrLf + + 'end;' + CrLf + + '' + CrLf; + PropertyImplMethodGetNil = 'function TXML%:s.Get%:sIsNil: Boolean;' + CrLf + 'begin' + CrLf + ' Result := GetNodeIsNil(ChildNodes[''%:s'']);' + CrLf + 'end;' + CrLf + '' + CrLf; + PropertyImplMethodSetNil = 'procedure TXML%:s.Set%:sIsNil(const Value: Boolean);' + CrLf + 'begin' + CrLf + ' SetNodeIsNil(ChildNodes[''%:s''], Value);' + CrLf + diff --git a/Units/XMLDataBindingGenerator.pas b/Units/XMLDataBindingGenerator.pas index 4ebd319..8f14e2f 100644 --- a/Units/XMLDataBindingGenerator.pas +++ b/Units/XMLDataBindingGenerator.pas @@ -1272,7 +1272,7 @@ begin ASchema.InsertItem(collectionItem, interfaceItem); end; - propertyItem.Collection := collectionItem; + propertyItem.Collection := collectionItem; end; end; end;