1
0
mirror of synced 2024-11-23 06:03:50 +00:00

Support of 'Def' getter method for optional elements

This commit is contained in:
Bert Herngreen 2017-09-01 11:48:05 +02:00
parent 3c9f47f80e
commit 5451a52cd2
2 changed files with 36 additions and 18 deletions

View File

@ -1223,7 +1223,11 @@ begin
WriteNewLine;
if writeOptional then
begin
sourceCode.Add(PropertyIntfMethodGetOptional);
if AProperty.PropertyType = ptSimple then
sourceCode.Add(PropertyIntfMethodGetOptionalOrDefault);
end;
if writeNil then
sourceCode.Add(PropertyIntfMethodGetNil);
@ -1311,6 +1315,9 @@ begin
else
sourceCode.Add(PropertyImplMethodGetOptional[GetDelphiElementType(nodeType)]);
end;
if AProperty.PropertyType = ptSimple then
sourceCode.Add(PropertyImplMethodGetOptionalOrDefault);
end;
if writeNil then

View File

@ -156,6 +156,7 @@ const
'end;' + CrLf;
PropertyIntfMethodGetOptional = ' function GetHas%<PropertyName>:s: Boolean;';
PropertyIntfMethodGetOptionalOrDefault = ' function %<PropertyName>:sDef(const ADefaultValue: %<DataType>:s = Default(%<DataType>:s)): %<DataType>:s;';
PropertyIntfMethodGetNil = ' function Get%<PropertyName>:sIsNil: Boolean;';
PropertyIntfMethodGetText = ' function Get%<PropertyName>:sText: WideString;';
PropertyIntfMethodGet = ' function Get%<PropertyName>:s: %<DataType>:s;';
@ -175,6 +176,16 @@ const
PropertyInterfaceText = ' property %<PropertyName>:sText: WideString read Get%<PropertyName>:sText write Set%<PropertyName>:sText;';
PropertyInterface = ' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s write Set%<PropertyName>:s;';
PropertyImplMethodGetOptionalOrDefault = 'function TXML%<Name>:s.%<PropertyName>:sDef(const ADefaultValue: %<DataType>:s): %<DataType>:s;' + CrLf +
'begin' + CrLf +
' if GetHas%<PropertySourceName>:s then' + CrLf +
' Result := Get%<PropertySourceName>:s' + CrLf +
' else' + CrLf +
' Result := ADefaultValue;' + CrLf +
'end;' + CrLf +
'' + CrLf;
PropertyImplMethodGetOptional: array[TDelphiElementType] of string =
(
{ dntElement }