1
0
mirror of synced 2024-09-28 17:46:08 +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

@ -155,25 +155,36 @@ const
' Result := (inherited GetCurrent as %<DataType>:s);' + CrLf +
'end;' + CrLf;
PropertyIntfMethodGetOptional = ' function GetHas%<PropertyName>:s: Boolean;';
PropertyIntfMethodGetNil = ' function Get%<PropertyName>:sIsNil: Boolean;';
PropertyIntfMethodGetText = ' function Get%<PropertyName>:sText: WideString;';
PropertyIntfMethodGet = ' function Get%<PropertyName>:s: %<DataType>:s;';
PropertyIntfMethodSetNil = ' procedure Set%<PropertyName>:sIsNil(const Value: Boolean);';
PropertyIntfMethodSetText = ' procedure Set%<PropertyName>:sText(const Value: WideString);';
PropertyIntfMethodSet = ' procedure Set%<PropertyName>:s(const Value: %<DataType>:s);';
PropertyIntfMethodLoadFromStream = ' procedure Load%<PropertyName>:sFromStream(AStream: TStream);';
PropertyIntfMethodLoadFromFile = ' procedure Load%<PropertyName>:sFromFile(const AFileName: string);';
PropertyIntfMethodSaveToStream = ' procedure Save%<PropertyName>:sToStream(AStream: TStream);';
PropertyIntfMethodSaveToFile = ' procedure Save%<PropertyName>:sToFile(const AFileName: string);';
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;';
PropertyIntfMethodSetNil = ' procedure Set%<PropertyName>:sIsNil(const Value: Boolean);';
PropertyIntfMethodSetText = ' procedure Set%<PropertyName>:sText(const Value: WideString);';
PropertyIntfMethodSet = ' procedure Set%<PropertyName>:s(const Value: %<DataType>:s);';
PropertyIntfMethodLoadFromStream = ' procedure Load%<PropertyName>:sFromStream(AStream: TStream);';
PropertyIntfMethodLoadFromFile = ' procedure Load%<PropertyName>:sFromFile(const AFileName: string);';
PropertyIntfMethodSaveToStream = ' procedure Save%<PropertyName>:sToStream(AStream: TStream);';
PropertyIntfMethodSaveToFile = ' procedure Save%<PropertyName>:sToFile(const AFileName: string);';
PropertyInterfaceOptional = ' property Has%<PropertyName>:s: Boolean read GetHas%<PropertyName>:s;';
PropertyInterfaceNilReadOnly = ' property %<PropertyName>:sIsNil: Boolean read Get%<PropertyName>:sIsNil;';
PropertyInterfaceNil = ' property %<PropertyName>:sIsNil: Boolean read Get%<PropertyName>:sIsNil write Set%<PropertyName>:sIsNil;';
PropertyInterfaceTextReadOnly = ' property %<PropertyName>:sText: WideString read Get%<PropertyName>:sText;';
PropertyInterfaceReadOnly = ' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s;';
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;';
PropertyInterfaceOptional = ' property Has%<PropertyName>:s: Boolean read GetHas%<PropertyName>:s;';
PropertyInterfaceNilReadOnly = ' property %<PropertyName>:sIsNil: Boolean read Get%<PropertyName>:sIsNil;';
PropertyInterfaceNil = ' property %<PropertyName>:sIsNil: Boolean read Get%<PropertyName>:sIsNil write Set%<PropertyName>:sIsNil;';
PropertyInterfaceTextReadOnly = ' property %<PropertyName>:sText: WideString read Get%<PropertyName>:sText;';
PropertyInterfaceReadOnly = ' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s;';
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 =
(