1
0
mirror of synced 2024-11-24 06:13:51 +00:00

Better collection support

Support for optional attributes
This commit is contained in:
Mark van Renswoude 2009-09-18 07:49:04 +00:00
parent de277ebcfc
commit 56013f783a
4 changed files with 55 additions and 30 deletions

Binary file not shown.

View File

@ -289,6 +289,13 @@ var
begin
case AProperty.PropertyType of
ptSimple:
if Assigned(AProperty.Collection) then
begin
if AInterfaceName then
Result := ItemInterface
else
Result := ItemClass;
end else
Result := TranslateDataType(TXMLDataBindingSimpleProperty(AProperty).DataType);
ptItem:
begin
@ -785,10 +792,6 @@ begin
begin
propertyItem := AItem.Properties[propertyIndex];
if propertyItem.PropertyType = ptItem then
begin
itemProperty := TXMLDataBindingItemProperty(propertyItem);
if (not AItem.IsCollection) and Assigned(propertyItem.Collection) then
begin
WritePrototype;
@ -796,19 +799,26 @@ begin
{ Inline collection }
if ASection = dxsImplementation then
begin
if propertyItem.PropertyType = ptItem then
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s);',
['ItemSourceName', propertyItem.Name,
'ItemClass', PrefixClass + itemProperty.Item.TranslatedName]);
'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', PrefixInterface + itemProperty.Item.TranslatedName,
'ItemInterface', GetDataTypeName(propertyItem, True),
'ItemSourceName', propertyItem.Name]);
end;
end else if ((not AItem.IsCollection) or
(propertyItem <> AItem.CollectionItem)) then
end;
if propertyItem.PropertyType = ptItem then
begin
itemProperty := TXMLDataBindingItemProperty(propertyItem);
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,8 +1225,10 @@ begin
begin
WriteNewLine;
// #ToDo1 (MvR) 21-4-2008: optional attributes!
if writeOptional then
if AProperty.IsAttribute then
sourceCode.Add(PropertyImplMethodGetOptionalAttr)
else
sourceCode.Add(PropertyImplMethodGetOptional);
if writeNil then
@ -1229,6 +1241,12 @@ begin
case AProperty.PropertyType of
ptSimple:
if Assigned(AProperty.Collection) then
begin
sourceCode.Add('begin');
sourceCode.Add(' Result := %<FieldName>:s;');
sourceCode.Add('end;');
end else
sourceCode.Add(XMLToNativeDataType('Result',
'%<PropertySourceName>:s',
TXMLDataBindingSimpleProperty(AProperty).DataType,

View File

@ -92,11 +92,18 @@ const
'end;' + 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 +
'begin' + CrLf +
' Result := GetNodeIsNil(ChildNodes[''%<PropertySourceName>:s'']);' + CrLf +
'end;' + CrLf +
'' + CrLf;
PropertyImplMethodSetNil = 'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
'begin' + CrLf +
' SetNodeIsNil(ChildNodes[''%<PropertySourceName>:s''], Value);' + CrLf +