Better collection support
Support for optional attributes
This commit is contained in:
parent
de277ebcfc
commit
56013f783a
Binary file not shown.
@ -289,7 +289,14 @@ var
|
|||||||
begin
|
begin
|
||||||
case AProperty.PropertyType of
|
case AProperty.PropertyType of
|
||||||
ptSimple:
|
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:
|
ptItem:
|
||||||
begin
|
begin
|
||||||
item := TXMLDataBindingItemProperty(AProperty).Item;
|
item := TXMLDataBindingItemProperty(AProperty).Item;
|
||||||
@ -785,30 +792,33 @@ begin
|
|||||||
begin
|
begin
|
||||||
propertyItem := AItem.Properties[propertyIndex];
|
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(''%<ItemSourceName>:s'', %<ItemClass>:s);',
|
||||||
|
['ItemSourceName', propertyItem.Name,
|
||||||
|
'ItemClass', GetDataTypeName(propertyItem, False)]);
|
||||||
|
|
||||||
|
AStream.WriteLnNamedFmt(' %<FieldName>:s := CreateCollection(%<CollectionClass>:s, %<ItemInterface>:s, ''%<ItemSourceName>:s'') as %<CollectionInterface>: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
|
if propertyItem.PropertyType = ptItem then
|
||||||
begin
|
begin
|
||||||
itemProperty := TXMLDataBindingItemProperty(propertyItem);
|
itemProperty := TXMLDataBindingItemProperty(propertyItem);
|
||||||
|
|
||||||
if (not AItem.IsCollection) and Assigned(propertyItem.Collection) then
|
if (not AItem.IsCollection) or
|
||||||
begin
|
(propertyItem <> AItem.CollectionItem) then
|
||||||
WritePrototype;
|
|
||||||
|
|
||||||
{ Inline collection }
|
|
||||||
if ASection = dxsImplementation then
|
|
||||||
begin
|
|
||||||
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s);',
|
|
||||||
['ItemSourceName', propertyItem.Name,
|
|
||||||
'ItemClass', PrefixClass + itemProperty.Item.TranslatedName]);
|
|
||||||
|
|
||||||
AStream.WriteLnNamedFmt(' %<FieldName>:s := CreateCollection(%<CollectionClass>:s, %<ItemInterface>:s, ''%<ItemSourceName>:s'') as %<CollectionInterface>: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
|
|
||||||
begin
|
begin
|
||||||
{ Item property }
|
{ Item property }
|
||||||
if Assigned(itemProperty.Item) and
|
if Assigned(itemProperty.Item) and
|
||||||
@ -945,8 +955,8 @@ begin
|
|||||||
ptSimple:
|
ptSimple:
|
||||||
begin
|
begin
|
||||||
dataTypeName := TranslateDataType(TXMLDataBindingSimpleProperty(AItem.CollectionItem).DataType);
|
dataTypeName := TranslateDataType(TXMLDataBindingSimpleProperty(AItem.CollectionItem).DataType);
|
||||||
dataClassName := 'TXMLNode';
|
dataClassName := ItemClass;
|
||||||
dataIntfName := 'IXMLNode';
|
dataIntfName := ItemInterface;
|
||||||
end;
|
end;
|
||||||
ptItem:
|
ptItem:
|
||||||
begin
|
begin
|
||||||
@ -1215,9 +1225,11 @@ begin
|
|||||||
begin
|
begin
|
||||||
WriteNewLine;
|
WriteNewLine;
|
||||||
|
|
||||||
// #ToDo1 (MvR) 21-4-2008: optional attributes!
|
|
||||||
if writeOptional then
|
if writeOptional then
|
||||||
sourceCode.Add(PropertyImplMethodGetOptional);
|
if AProperty.IsAttribute then
|
||||||
|
sourceCode.Add(PropertyImplMethodGetOptionalAttr)
|
||||||
|
else
|
||||||
|
sourceCode.Add(PropertyImplMethodGetOptional);
|
||||||
|
|
||||||
if writeNil then
|
if writeNil then
|
||||||
sourceCode.Add(PropertyImplMethodGetNil);
|
sourceCode.Add(PropertyImplMethodGetNil);
|
||||||
@ -1229,10 +1241,16 @@ begin
|
|||||||
|
|
||||||
case AProperty.PropertyType of
|
case AProperty.PropertyType of
|
||||||
ptSimple:
|
ptSimple:
|
||||||
sourceCode.Add(XMLToNativeDataType('Result',
|
if Assigned(AProperty.Collection) then
|
||||||
'%<PropertySourceName>:s',
|
begin
|
||||||
TXMLDataBindingSimpleProperty(AProperty).DataType,
|
sourceCode.Add('begin');
|
||||||
GetDelphiNodeType(AProperty)));
|
sourceCode.Add(' Result := %<FieldName>:s;');
|
||||||
|
sourceCode.Add('end;');
|
||||||
|
end else
|
||||||
|
sourceCode.Add(XMLToNativeDataType('Result',
|
||||||
|
'%<PropertySourceName>:s',
|
||||||
|
TXMLDataBindingSimpleProperty(AProperty).DataType,
|
||||||
|
GetDelphiNodeType(AProperty)));
|
||||||
|
|
||||||
ptItem:
|
ptItem:
|
||||||
begin
|
begin
|
||||||
|
@ -92,11 +92,18 @@ const
|
|||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf;
|
||||||
|
|
||||||
|
PropertyImplMethodGetOptionalAttr = 'function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' Result := Assigned(AttributeNodes.FindNode(''%<PropertySourceName>:s''));' + CrLf +
|
||||||
|
'end;' + CrLf +
|
||||||
|
'' + CrLf;
|
||||||
|
|
||||||
PropertyImplMethodGetNil = 'function TXML%<Name>:s.Get%<PropertyName>:sIsNil: Boolean;' + CrLf +
|
PropertyImplMethodGetNil = 'function TXML%<Name>:s.Get%<PropertyName>:sIsNil: Boolean;' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' Result := GetNodeIsNil(ChildNodes[''%<PropertySourceName>:s'']);' + CrLf +
|
' Result := GetNodeIsNil(ChildNodes[''%<PropertySourceName>:s'']);' + CrLf +
|
||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf;
|
||||||
|
|
||||||
PropertyImplMethodSetNil = 'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
|
PropertyImplMethodSetNil = 'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' SetNodeIsNil(ChildNodes[''%<PropertySourceName>:s''], Value);' + CrLf +
|
' SetNodeIsNil(ChildNodes[''%<PropertySourceName>:s''], Value);' + CrLf +
|
||||||
|
@ -1272,7 +1272,7 @@ begin
|
|||||||
ASchema.InsertItem(collectionItem, interfaceItem);
|
ASchema.InsertItem(collectionItem, interfaceItem);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
propertyItem.Collection := collectionItem;
|
propertyItem.Collection := collectionItem;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user