1
0
mirror of synced 2024-11-14 11:09:16 +00:00

Make generation of 'Def' getter method configurable.\nSkip generation of 'Def' getter method for Variants

This commit is contained in:
Bert Herngreen 2017-09-06 17:12:15 +02:00
parent 5451a52cd2
commit a30ef97eb3
6 changed files with 64 additions and 25 deletions

View File

@ -4,7 +4,7 @@ object MainForm: TMainForm
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsDialog
Caption = 'X'#178'Software XML Data Binding for Delphi'
ClientHeight = 291
ClientHeight = 312
ClientWidth = 438
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
@ -17,7 +17,7 @@ object MainForm: TMainForm
OnCreate = FormCreate
DesignSize = (
438
291)
312)
PixelsPerInch = 96
TextHeight = 13
object lblSchema: TLabel
@ -44,14 +44,14 @@ object MainForm: TMainForm
Left = 8
Top = 43
Width = 422
Height = 204
Height = 225
Anchors = [akLeft, akTop, akBottom]
Caption = ' Output '
TabOrder = 1
ExplicitHeight = 167
ExplicitHeight = 204
DesignSize = (
422
204)
225)
object rbFile: TRadioButton
Left = 11
Top = 21
@ -83,7 +83,6 @@ object MainForm: TMainForm
TabOrder = 2
object spFile: TTabSheet
TabVisible = False
ExplicitHeight = 85
object lblFile: TLabel
Left = 4
Top = 7
@ -105,8 +104,6 @@ object MainForm: TMainForm
end
object spFolder: TTabSheet
TabVisible = False
ExplicitLeft = 8
ExplicitHeight = 195
DesignSize = (
408
83)
@ -171,10 +168,19 @@ object MainForm: TMainForm
'perties'
TabOrder = 3
end
object cbGenerateGetOptionalOrDefault: TCheckBox
Left = 11
Top = 198
Width = 401
Height = 17
Hint = ' Generate a "Def" method for optional elements'
Caption = ' Generate a "Def" method for optional elements'
TabOrder = 4
end
end
object btnGenerate: TButton
Left = 274
Top = 258
Top = 279
Width = 75
Height = 25
Anchors = [akRight, akBottom]
@ -182,11 +188,11 @@ object MainForm: TMainForm
Default = True
TabOrder = 3
OnClick = btnGenerateClick
ExplicitTop = 221
ExplicitTop = 258
end
object btnClose: TButton
Left = 355
Top = 258
Top = 279
Width = 75
Height = 25
Anchors = [akRight, akBottom]
@ -194,11 +200,11 @@ object MainForm: TMainForm
Caption = '&Close'
TabOrder = 4
OnClick = btnCloseClick
ExplicitTop = 221
ExplicitTop = 258
end
object btnHints: TButton
Left = 7
Top = 258
Top = 279
Width = 142
Height = 25
Anchors = [akRight, akBottom]
@ -206,7 +212,7 @@ object MainForm: TMainForm
Caption = 'Generate blank &Hints file'
TabOrder = 2
OnClick = btnHintsClick
ExplicitTop = 221
ExplicitTop = 258
end
object DefaultEditStyle: TcxDefaultEditStyleController
Style.HotTrack = False

View File

@ -52,6 +52,7 @@ type
spFile: TTabSheet;
spFolder: TTabSheet;
cbHasChecksEmpty: TCheckBox;
cbGenerateGetOptionalOrDefault: TCheckBox;
procedure btnCloseClick(Sender: TObject);
procedure btnGenerateClick(Sender: TObject);
@ -183,6 +184,7 @@ begin
end;
generator.HasChecksEmpty := cbHasChecksEmpty.Checked;
generator.HasGenerateGetOptionalOrDefault := cbGenerateGetOptionalOrDefault.Checked;
generator.OnGetFileName := GetFileName;
generator.Execute(feSchema.Text);
@ -283,6 +285,7 @@ begin
end;
cbHasChecksEmpty.Checked := settings.Output.HasHasChecksEmpty and settings.Output.HasChecksEmpty;
cbGenerateGetOptionalOrDefault.Checked := settings.Output.HasGenerateGetOptionalOrDefault and settings.Output.GenerateGetOptionalOrDefault;
end;
end;
end;
@ -319,6 +322,7 @@ begin
end;
settings.Output.HasChecksEmpty := cbHasChecksEmpty.Checked;
settings.Output.GetOptionalOrDefault := cbGenerateGetOptionalOrDefault.Checked;
settings.OwnerDocument.SaveToFile(fileName);
end;

View File

@ -1,7 +1,7 @@
{
X2Software XML Data Binding
Generated on: 21-7-2017 9:19:46
Generated on: 6-9-2017 16:58:58
Generated from: P:\x2xmldatabinding\XSD\DataBindingSettings.xsd
}
unit DataBindingSettingsXML;
@ -28,7 +28,7 @@ type
Contains the settings and hints for the Delphi XML Data Binding.
}
IXMLDataBindingSettings = interface(IXMLNode)
['{0407CBCB-B49B-4ED3-A2F6-CCDDFE46F334}']
['{90C0CA10-A7AD-4418-98B6-D03469DB8913}']
procedure XSDValidateDocument(AStrict: Boolean = False);
function GetHasOutput: Boolean;
function GetOutput: IXMLDataBindingOutput;
@ -41,7 +41,7 @@ type
Contains the user-defined output settings last used
}
IXMLDataBindingOutput = interface(IXMLNode)
['{21821EFA-C7D8-4299-BF44-8122FBF2BC2E}']
['{166F0975-2D2F-4CDB-B911-005163A0761F}']
procedure XSDValidate;
procedure XSDValidateStrict(AResult: IXSDValidateStrictResult);
@ -53,10 +53,13 @@ type
function GetOutputMultiple: IXMLOutputMultiple;
function GetHasHasChecksEmpty: Boolean;
function GetHasChecksEmpty: Boolean;
function GetHasGenerateGetOptionalOrDefault: Boolean;
function GetGenerateGetOptionalOrDefault: Boolean;
procedure SetOutputTypeText(const Value: WideString);
procedure SetOutputType(const Value: TXMLDataBindingOutputType);
procedure SetHasChecksEmpty(const Value: Boolean);
procedure SetGenerateGetOptionalOrDefault(const Value: Boolean);
property OutputTypeText: WideString read GetOutputTypeText write SetOutputTypeText;
property OutputType: TXMLDataBindingOutputType read GetOutputType write SetOutputType;
@ -66,10 +69,12 @@ type
property OutputMultiple: IXMLOutputMultiple read GetOutputMultiple;
property HasHasChecksEmpty: Boolean read GetHasHasChecksEmpty;
property HasChecksEmpty: Boolean read GetHasChecksEmpty write SetHasChecksEmpty;
property HasGenerateGetOptionalOrDefault: Boolean read GetHasGenerateGetOptionalOrDefault;
property GenerateGetOptionalOrDefault: Boolean read GetGenerateGetOptionalOrDefault write SetGenerateGetOptionalOrDefault;
end;
IXMLOutputSingle = interface(IXMLNode)
['{ABB2D62A-0B4D-4E4B-8835-ED8AFE7564EA}']
['{77AE2C19-333F-4335-872E-659AE17C4701}']
procedure XSDValidate;
procedure XSDValidateStrict(AResult: IXSDValidateStrictResult);
@ -81,7 +86,7 @@ type
end;
IXMLOutputMultiple = interface(IXMLNode)
['{2F4918D6-EE9C-4986-9052-285A8B4D58C5}']
['{8C1E7817-DBF1-4125-B29A-F7279006C7FB}']
procedure XSDValidate;
procedure XSDValidateStrict(AResult: IXSDValidateStrictResult);
@ -124,10 +129,13 @@ type
function GetOutputMultiple: IXMLOutputMultiple;
function GetHasHasChecksEmpty: Boolean;
function GetHasChecksEmpty: Boolean;
function GetHasGenerateGetOptionalOrDefault: Boolean;
function GetGenerateGetOptionalOrDefault: Boolean;
procedure SetOutputTypeText(const Value: WideString);
procedure SetOutputType(const Value: TXMLDataBindingOutputType);
procedure SetHasChecksEmpty(const Value: Boolean);
procedure SetGenerateGetOptionalOrDefault(const Value: Boolean);
end;
TXMLOutputSingle = class(TX2XMLNode, IXSDValidate, IXSDValidateStrict, IXMLOutputSingle)
@ -279,13 +287,13 @@ end;
procedure TXMLDataBindingOutput.XSDValidate;
begin
GetOutputType;
SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty']);
SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty', 'GenerateGetOptionalOrDefault']);
end;
procedure TXMLDataBindingOutput.XSDValidateStrict(AResult: IXSDValidateStrictResult);
begin
GetOutputType;
SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty']);
SortChildNodes(Self, ['OutputType', 'OutputSingle', 'OutputMultiple', 'HasChecksEmpty', 'GenerateGetOptionalOrDefault']);
end;
function TXMLDataBindingOutput.GetOutputTypeText: WideString;
@ -332,6 +340,17 @@ begin
Result := ChildNodes['HasChecksEmpty'].NodeValue;
end;
function TXMLDataBindingOutput.GetHasGenerateGetOptionalOrDefault: Boolean;
begin
Result := Assigned(ChildNodes.FindNode('GenerateGetOptionalOrDefault'));
end;
function TXMLDataBindingOutput.GetGenerateGetOptionalOrDefault: Boolean;
begin
Result := ChildNodes['GenerateGetOptionalOrDefault'].NodeValue;
end;
procedure TXMLDataBindingOutput.SetOutputTypeText(const Value: WideString);
begin
ChildNodes['OutputType'].NodeValue := Value;
@ -348,6 +367,11 @@ begin
ChildNodes['HasChecksEmpty'].NodeValue := BoolToXML(Value);
end;
procedure TXMLDataBindingOutput.SetGenerateGetOptionalOrDefault(const Value: Boolean);
begin
ChildNodes['GenerateGetOptionalOrDefault'].NodeValue := BoolToXML(Value);
end;
procedure TXMLOutputSingle.XSDValidate;
begin
CreateRequiredElements(Self, ['FileName']);

View File

@ -23,6 +23,7 @@ type
FHasChecksEmpty: Boolean;
FOnGetFileName: TGetFileNameEvent;
FHasGenerateGetOptionalOrDefault: Boolean;
protected
procedure GenerateDataBinding; override;
procedure GenerateOutputFile(ASchemaList: TXMLSchemaList; const ASourceFileName, AUnitName: String);
@ -72,6 +73,7 @@ type
property UnitNames: TDictionary<TXMLDataBindingSchema, String> read FUnitNames;
public
property HasChecksEmpty: Boolean read FHasChecksEmpty write FHasChecksEmpty;
property HasGenerateGetOptionalOrDefault: Boolean read FHasGenerateGetOptionalOrDefault write FHasGenerateGetOptionalOrDefault;
property OnGetFileName: TGetFileNameEvent read FOnGetFileName write FOnGetFileName;
end;
@ -86,6 +88,8 @@ uses
X2Log.Global;
const
VariantText = 'Variant';
{ TDelphiXMLDataBindingGenerator }
@ -314,7 +318,7 @@ var
typeMapping: TTypeMapping;
begin
Result := 'Variant';
Result := VariantText;
if GetDataTypeMapping(ADataType, typeMapping) then
Result := typeMapping.DelphiName;
end;
@ -1225,7 +1229,7 @@ begin
if writeOptional then
begin
sourceCode.Add(PropertyIntfMethodGetOptional);
if AProperty.PropertyType = ptSimple then
if HasGenerateGetOptionalOrDefault and (AProperty.PropertyType = ptSimple) and (dataTypeName <> VariantText) then
sourceCode.Add(PropertyIntfMethodGetOptionalOrDefault);
end;
@ -1316,7 +1320,7 @@ begin
sourceCode.Add(PropertyImplMethodGetOptional[GetDelphiElementType(nodeType)]);
end;
if AProperty.PropertyType = ptSimple then
if HasGenerateGetOptionalOrDefault and (AProperty.PropertyType = ptSimple) and (dataTypeName <> VariantText) then
sourceCode.Add(PropertyImplMethodGetOptionalOrDefault);
end;

View File

@ -1,2 +1,2 @@
<?xml version="1.0"?>
<DataBindingSettings xmlns="http://www.x2software.net/xsd/databinding/DataBindingSettings.xsd"><Output><OutputType>Single</OutputType><OutputSingle><FileName>..\Units\DataBindingSettingsXML.pas</FileName></OutputSingle></Output></DataBindingSettings>
<DataBindingSettings xmlns="http://www.x2software.net/xsd/databinding/DataBindingSettings.xsd"><Output><OutputType>Single</OutputType><OutputSingle><FileName>..\Units\DataBindingSettingsXML.pas</FileName></OutputSingle><HasChecksEmpty>false</HasChecksEmpty><GenerateGetOptionalOrDefault>false</GenerateGetOptionalOrDefault></Output></DataBindingSettings>

View File

@ -35,6 +35,7 @@
</xs:element>
</xs:choice>
<xs:element name="HasChecksEmpty" type="xs:boolean" minOccurs="0"/>
<xs:element name="GenerateGetOptionalOrDefault" type="xs:boolean" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="DataBindingOutputType">